Q. Write down a non recursive algorithm to traverse a binary tree in order.
Non - recursive algorithm to traverse a binary tree in inorder is as follows:-
Initially in the beginning push NULL onto STACK and then set PTR = ROOT. Then repeat the steps written below until NULL is popped from STACK.
i. Continue down the left -most path rooted at PTR, pushing each node N onto STACK and stopping when a node N with no left child is pushed onto
ii. [Backtracking.] Pop and process the nodes on
STACK. If the NULL is popped then Exit. If a node N
Having a right child R(N) is processed, set PTR = R(N) (by assigning PTR = RIGHT[PTR] and return to the Step(a)).