Figure 5-5. A tree, drawn as a maze and as a more conventional graph diagram, superimposed on the maze
The left-hand rule is designed to be executed by an individual actually walking a maze, using only local
information. To get a firm grip on what is really going on, we could drop this perspective and formulate the same
strategy recursively.
7
Once you’re familiar with recursive thinking, such formulations can make it easier to see that an
algorithm is correct, and this is one of the easiest recursive algorithms out there. For a basic implementation (which
assumes one of our standard graph representations for the tree), see Listing 5-3.
Do'stlaringiz bilan baham: |