Saturday, August 27, 2011

Depth First Search

  1. Push the root node onto a Stack.
  2. Pop a node from the stack and examine it.
    • If the element sought is found in this node, quit the search and return a result.
    • Otherwise push all its successors (child nodes) that have not yet been discovered onto the stack. ( *Push Right first then Left )
  3. If the stack is empty, every node in the tree has been examined – quit the search and return "not found".
  4. If the stack is not empty, repeat from Step 2.

No comments:

Post a Comment