|
|
|
|
|
|
|
A library catalog system can give insight into how to organize a parts inventory. |
|
|
|
|
|
|
|
|
Often a problem reminds you of a similar problem you have seen before. You may find solving the problem at hand easier if you remember how you solved the other problem. In other words, draw an analogy between the two problems. For example, a solution to a perspective projection problem from an art class might help you figure out how to compute the distance to a landmark when you are on a cross-country hike. As you work your way through the new problem, you come across things that are different than they were in the old problem, but usually these are just details that you can deal with one at a time. |
|
|
|
|
|
|
|
|
Analogy is really just a broader application of the strategy of looking for things that are familiar. When you are trying to find an algorithm for solving a problem, don't limit yourself to computer-oriented solutions. Step back and try to get a larger view of the problem. Don't worry if your analogy doesn't match perfectlythe only reason for starting with an analogy is that it gives you a place to start (see Figure 1-13). The best programmers are people who have broad experience solving all kinds of problems. |
|
|
|
|
|
|
|
|
Often the beginning state and the ending state are given; the problem is to define a set of actions that can be used to get from one to the other. Suppose you want to go from Boston, Massachusetts, to Austin, Texas. You know the beginning state (you are in the city of Boston) and the ending state (you want to be in the city of Austin). The problem is how to get from one to the other. |
|
|
|
|
|
|
|
|
In this example, you have lots of choices. You can fly, walk, hitchhike, ride a bike, or whatever. The method you choose depends on your circumstances. If you're in a hurry, you'll probably decide to fly. |
|
|
|
|
|
|
|
|
Once you've narrowed down the set of actions, you have to work out the details. It may help to establish intermediate goals that are easier to meet than the overall goal. Let's say there is a really cheap, direct flight to Austin out of Newark, New Jersey. You might decide to divide the trip into legs: Boston to Newark and then Newark to Austin. Your intermediate goal is to |
|
|
|
|
|