1.6 Problems versus Algorithms

There is a distinction between problems and algorithms: a problem is a task to be carried out, and an algorithm is a specific set of steps for how to carry out a task. A problem may have more than one algorithm for solving it. A given algorithm, however, solves only one problem. At this point, it might seem like an easy distinction, but during an introductory course like this one, it can be easy to forget. It’s therefore important to remember that for most real-world problems, this is rarely the case.

As an example, let’s consider the problem of picking up a pile of dealt playing cards, and putting them in order of rank. Some people pick up their cards one at a time and place each card into their hand at the correct position as they do so. Other people pick up all of the cards at once, find the smallest one and move that card to the left-most position, then find the next smallest and put it next to the smallest card, and so on. These are two different algorithms for solving the problem of putting a hand of cards in order. Both achieve the same result, but the algorithms themselves are fundamentally different processes.