This chapter is about the birds and the bees, but it’s probably not what you’re thinking! Let’s start with the backstory.
Imagine that you’re a salesperson who needs to travel to a set of cities to show your products to potential customers. The good news is that there’s a direct flight between every pair of cities and, for each pair, you’re given the cost of flying between those two cities. Your objective is to start in your home city, visit each city exactly once, and return back home at lowest total cost. This is called the Traveling Salesperson Problem and it’s one of the most famous problems in computer science.
For example, consider the set of cities and flights shown in Figure 14.1 and imagine that your start city is Aville.
A tempting approach to solving the Traveling Salesperson Problem is to use an approach like this. Starting at our home city, Aville, fly on the cheapest flight. That’s the flight of cost 1 to Beesburg. (This is not yet the part about the bees.) From Beesburg, we could fly on the least expensive flight to a city that we have not yet visited, in this case Ceefield. From Ceefield, we would then fly on the cheapest flight to a city that we have not yet visited. (Remember, the problem stipulates that you only fly to a city once, presumably because you’re busy and you don’t want to fly to any city more than once - even if it might be cheaper to do so.) So now, we fly from Ceefield to Deesdale and from there to Eetown.