Q. Write down the non-recursive algorithm to traverse a tree in preorder.
Ans:
The Non- Recursive algorithm for preorder traversal is written below: Initially in the begnining
push NULL onto stack and then set PTR=Root. Keep on repeating the following steps until PTR= NULL.
1. Preorder down the left most paths routed at the PTR.
2. Processing each node N on the path and pushing each right child if there is onto the stack.[The traversing will stop when (PTR)=NULL]
3. Backtracking: pop and assign to PTR the top element on stack. If PTR is not equal to NULL then return to step 1 otherwise it exits.