![]() |
VOOZH | about |
Given a binary tree, the task is to perform reverse in-order traversal using Morris Traversal.
Example:
Input:
π Iterative-Postorder-TraversalOutput: 3 1 5 2 4
Explanation: Inorder traversal (Right->Root->Left) of the tree is 3 1 5 2 4Input:
π Iterative-Postorder-Traversal-2Output: 6 5 10 6 8 10 7 1
Explanation: Inorder traversal (Right->Root->Left) of the tree is 6 5 10 6 8 10 7 1
Morris (In-order) Traversal is a tree traversal algorithm that operates without recursion or a stack by creating temporary links in the tree, using them to traverse nodes, and then restoring the treeβs original structure.
Prerequisites :
n nodes, n + 1 NULL pointers waste memory. Threaded binary trees use these NULL pointers to store useful information.Reverse Morris Traversal:
This is the inverse process of Morris Traversals , where links to the in-order descendants are created, used to traverse in reverse order, and then removed to restore the original structure.
Approach:
7 3 6 1 5 2 4
Time Complexity : O(n), where n is the number of nodes in the tree. Each node will be traversed at most 3 times.
Auxiliary Space : O(1)