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