The recursive algorithm is simple and straightforward. Now I am discussing the nonrecursive version. One solution is to use an auxiliary stack, with time and space both \(O(n)\) in worst case.
The above code can be modified a little bit as shown below. These 2 versions will work exactly the same.
Related Posts:
Nonrecursive Algorithm without Stack to Inorder Traverse Binary Tree
No comments:
Post a Comment