MAZE PROBLEM

 

Explanation of the Maze Problem

 

Given a Maze with one starting position and one ending position, find your way from the starting position to the ending position.

 

 

Explanation of the Maze Creation

 

Recursive backtracker:

This is somewhat related to the recursive backtracker solving method described below, and requires stack up to the size of the Maze. When carving, be as greedy as possible, and always carve into an unmade section if one is next to the current cell. Each time you move to a new cell, push the former cell on the stack. If there are no unmade cells next to the current position, pop the stack to the previous position. The Maze is done when you pop everything off the stack. This algorithm results in Mazes with about as high a "river" factor as possible, with fewer but longer dead ends, and usually a very long and twisty solution. It runs quite fast, although Prim's algorithm is a bit faster. Recursive backtracking doesn't work as a wall adder, because doing so tends to result in a solution path that follows the outside edge, where the entire interior of the Maze is attached to the boundary by a single stem.

 

 

Explanation of the Maze Solution

 

Recursive backtracker (Depth First Search):

This will find a solution, but it won't necessarily find the shortest solution. It focuses on you, is fast for all types of Mazes, and uses stack space up to the size of the Maze. Very simple: If you're at a wall (or an area you've already plotted), return failure, else if you're at the finish, return success, else recursively try moving in the four directions. Plot a line when you try a new direction, and erase a line when you return failure, and a single solution will be marked out when you hit success. In Computer Science terms this is basically a depth first search. This method will always find a solution if one exists, but it won't necessarily be the shortest solution.

 

The Algorithma 2004 algorithm used for solution

solve(Cell cell)
{
 if cell has been visited
  return
 else 
  visit cell and color it yellow 	

 if cell is equal to destination
  done = true
  
 if !done && North cell accessible
  done = solve( North cell)
 if !done && South cell accessible
  done = solve( South cell)
 if !done && East cell accessible
  done = solve( East cell)
 if !done && West cell accessible
  done = solve( West cell)

 if(!done) 
   color cell gray
}

Big O of Maze solution

 

Time complexity is an exponential relationship O(bm) where b is the branching factor, and m is the maximal depth of a leaf node.  Number of nodes generated:

 

1 + b + b2 + … + bm = O(bm)

 

Space complexity is O(bm) or O(m).  It is a linear relationship, not an exponential relationship like the Time complexity.

 

 

Interesting side notes

 

The time complexity for a Depth first search is O(bm), where b is the branching factor and m is the maximum depth. The time complexity is the same with respect to the Breadth first search. The Depth first search may be faster because it has a better chance of finding a solution with respect to exploring nodes that are deeper in the tree, instead of only a small portion of the beginning nodes.

 

The drawback to the Depth first search is that it can get stuck gong down the wrong path and never recover, with respect to time, from an unlucky choice at one of the nodes near the top of the tree. The Depth first search will continuing going downward even though a solution may be very close to the top of the tree.

 

Depth first search has moderate memory requirements. For a Depth first search in memory, it only needs to store a single path from the root to a leaf node, along with the remaining unexpanded sibling nodes for each node on the path. With a branching factor of b and a maximum depth m, the Depth first search requires storage of only bm nodes.

 

 

http://www.astrolog.org/labyrnth/daedalus.htm

http://www.cs.ualberta.ca/~lindek/366/slides/BlindSearch.ppt

http://www.cs.usask.ca/resources/tutorials/csconcepts/1998_3/DFS/2-2.html