iterative tree traversal