1
votes

For inorder binary search tree traversal there is an iterative algorithm that uses no auxiliary memory (stack, parent pointers, visited flags) known as Morris Traversal. Is there a similar algorithm for preorder and postorder traversals?

1

1 Answers

1
votes

just worked out a solution for preorder traversal, might work

Initialize current as root 
While current is not NULL
If current does not have right child
  a) print current root
  b) Go to the left, i.e., current = current->left
Else
  a) print current root
  a) Make the whole right sub-tree of current as the left node of the rightmost child in the left sub tree(inorder predecessor of current)
  b) Go to the left child, i.e., current = current->left

do comment if it there is something wrong with the algorithm