update with top-down solution
modified preorder traversal
array and hash table