RSS

Difference Between Algorithm and Heuristic

15 Feb

I read this interesting  comparison between algorithm and heuristic in the “Code Complete” by Steve McConnell. All the analogies might not be completely correct but I find it as a very simple way to explain the differences between algorithm and heuristic Here I am refereeing algorithm as polynomial time algorithm. Bellow ideas have been generalized by the author  to make a understanding of those two things in a comparative scenario. There may have exceptions.

An algorithm is a set of well-defined instructions for carrying out a particular task. It must be sound and complete. That mean it must gives you the correct answer and it must works for all cases.Usually, an algorithm is predictable, deterministic, and not subject to chance. An algorithm tells you how to go from point A to point B with no detours, no side trips to points D, E, and F, and no stopping to smell the roses or have a cup of joe.

A heuristic is a technique that helps you look for an answer. Its results are subject to chance because a heuristic tells you only how to look, not what to find. It doesn’t tell you how to get directly from point A to point B; it might not even know where point A and point B are. In effect, a heuristic is an algorithm in a clown suit. It’s less predictable, it’s more fun, and it comes without a 30-day, money-back guarantee.

Here is an algorithm for driving to someone’s house: Take Highway 167 south to Puyallup. Take the South Hill Mall exit and drive 4.5 miles up the hill. Turn right at the light by the grocery store, and then take the first left. Turn into the driveway of the large tan house on the left, at 714 North Cedar.

Here’s a heuristic for getting to someone’s house: Find the last letter we mailed you. Drive to the town in the return address. When you get to town, ask someone where our house is. Everyone knows us—someone will be glad to help you. If you can’t find anyone, call us from a public phone, and we’ll come get you.

The difference between an algorithm and a heuristic is subtle, and the two terms overlap somewhat. The main difference between the two is the level of indirection from the solution. An algorithm gives you the instructions directly. A heuristic tells you how to discover the instructions for yourself, or at least where to look for them.” — Code Complete 2, by Steve McConnell page 10-12

Thanks
(Faisal Sikder)

 
18 Comments

Posted by on February 15, 2010 in Uncategorized

 

Tags: , ,

18 responses to “Difference Between Algorithm and Heuristic

  1. Dhruv Sangvikar (@meetsangvikar)

    August 8, 2011 at 11:52 pm

    Thank you..but could u please elaborate the differences a little more? thanks again.

     
  2. Franck Dernoncourt

    September 7, 2011 at 1:37 am

    “An algorithm is predictable, deterministic, and not subject to chance.”

    -> This statement is false. Algorithms can be non-deterministic, e.g. randomized algorithms such as Monte Carlo algorithms.

     
    • Faisal Sikder

      October 26, 2011 at 11:30 am

      Thanks Franck for pointing out my this issue.

      Actually I am referring algorithm as polynomial time algorithm. Generally, there are lots of algorithms which are non-deterministic. I have done some editing to make it more clear.

       
  3. Ejikeme Ugo

    September 7, 2011 at 8:13 pm

    Hello Faisal Sikder, Great article. I referenced it in a tutorial i posted in codeproject. I thought i should let you know.
    Regards,
    Ugochukwu Ejikeme.

    NB: Here’s the article by the way. http://www.codeproject.com/KB/recipes/GeneticAlgorithm.aspx

     
    • Faisal Sikder

      October 26, 2011 at 11:42 am

      Thanks, I appreciate your comments 🙂

       
  4. Đăng Trần

    September 27, 2011 at 8:39 am

    Ez to understand, thanks.

     
  5. eswarann

    February 12, 2012 at 12:33 pm

    I am happy to see this post. I have tried differentiating algorithms, heuristics and meta-heuristics. see http://eswarann.wordpress.com/2012/02/12/introduction-to-algorithms-heuristics-and-meta-heuristics/ . Hope to add more..

     
    • eswarann

      April 30, 2012 at 7:54 am

      Added post on GA/CS/ACO

       
  6. Noufal.P

    December 7, 2012 at 10:44 am

    Thank You

     
  7. http://tinyurl.com/37thikin51373

    January 30, 2013 at 1:10 am

    “Difference Between Algorithm and Heuristic | Simplicity Through
    Breadth” ended up being a wonderful blog, can not wait to look over a lot more of ur postings.

    Time to squander some time online hehe. Many thanks ,Susanne

     
  8. suresh manian

    June 12, 2014 at 5:35 am

    Thank you very much for clearing the confusion i’ve been living with. appears to me what i’ve developed is a heuristic rather than an algorithm. cool:)

     
  9. hamid khan

    June 6, 2015 at 5:11 pm

    Thanks a million for explaining with such a simple example. hope to see more from you…

     
  10. Return 0

    June 25, 2016 at 10:13 am

    ‘Heuristic is an algorithm in a clown suit’

    Thanks, now I have a way describe both of them in the most simplest of terms.

     
  11. lulla.a.f@hotmail.com

    November 29, 2016 at 11:44 pm

    That was really helpful, Thanks

     
  12. Hazim Nasir

    April 25, 2018 at 5:19 pm

    thank you I will try to refer this statements in my Ph.D. survey

     
  13. Kimberley

    May 30, 2019 at 6:53 am

    I love how Steve McConnell explained heuristic and algorithm functionalities.

     

Leave a reply to eswarann Cancel reply