Implement depth-first search traversal