START _________________________________________ | |f7 | |_____ A|________________ G |_______ | | B | _____| | | |__|____________|C | | ________| | | |____ | | | _ | | |_______ | | | | |____________| | _____| H | |f1| | | | | | _ _____| |__| | | _______ | |____ | | | | |f2| | | | f6| | | | | | | | | | |______| F | |_____ | |____| | | ___| | f5| | | f8 | | | | | | |____| | | | | | |__| |__ E_____| | | | | | | | | ______| |________| | |_____ D |________| | | | | f3| f4| | |______________________|________|_|____ | GOAL We can traverse this maze in two different ways. Every time that we have a choice to make, we can either do one of two things: (1) always go the left (or right) but consistently. I.e., always go left when a choice. (2) stay at the same level. If a choice (at say A), then first go left until another choice (say B), then backtrack (back to A in our example) and do the other choice (at A) until one finds a choice. Then go back to the choice from the first branch at A (B in our example) and continue there until a choice or a dead-end. The choice of paths can be diagrammed as follows: A / \ B C / \ / \ f1 f2 D F / \ / \ E f3 G f4 / \ / \ f6 f5 f7 H / \ GOAL f8 In (1) we would visit the nodes as : A,B,f1,f2,C,D,E,f6,f5,f3,F,G,f7,H,GOAL, while in (2) we would visit the the nodes as : A,B,C,f1,f2,D,F,E,f3,G,f4,f5,f6,f7,H,GOAL. In (1) we use a stack to store the elements I have not yet visited in the depth first search. (In fact, this is a NLR (preorder) search.) In (2) we use a queue to store the elements we have not yet visited, which is a breath first search.