add algorithm for tree traversal