Function Search(maze): //initialize data structure for tracking what cells we've seen and how we got there (parents) frontier = new OrderedCollection //Stack for Depth-first search, Queue for Breadth-first search frontier.insert(start) mark start as seen While frontier not empty: cell = frontier.remove() For each neighbor of cell: If neighbor is Finish: follow parent pointers to build path return path End If If neighbor not seen: frontier.insert(neighbor) mark neighbor as seen mark cell as neighbor's parent End If End For End While Return failure End Function