added depth limit and previous node to traversal algorithms