VOOZH about

URL: https://www.geeksforgeeks.org/dsa/reverse-morris-traversal-using-threaded-binary-tree/

⇱ Reverse Morris traversal using Threaded Binary Tree - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Reverse Morris traversal using Threaded Binary Tree

Last Updated : 11 Jul, 2025

Given a binary tree, the task is to perform reverse in-order traversal using Morris Traversal.

Example:

Input:

πŸ‘ Iterative-Postorder-Traversal

Output: 3 1 5 2 4
Explanation: Inorder traversal (Right->Root->Left) of the tree is 3 1 5 2 4

Input:

πŸ‘ Iterative-Postorder-Traversal-2

Output: 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 :

  • Morris Traversals
  • Threaded Binary Trees: In a binary tree with n nodes, n + 1 NULL pointers waste memory. Threaded binary trees use these NULL pointers to store useful information.
    • Left-threaded: Stores ancestor information in NULL left pointers.
    • Right-threaded: Stores successor information in NULL right pointers.
    • Fully-threaded: Stores both predecessor (NULL left) and successor (NULL right) 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:

  • Initialize Current as root.
  • While current is not NULL :
  • If current has no right child, visit the current node and move to the left child of current.
  • Else, find the in-order successor of current node. In-order successor is the left most node in the right subtree or right child itself.
    • If the left child of the in-order successor is NULL, set current as the left child of its in-order successor and move current node to its right.
    • Else, if the threaded link between the current and it's in-order successor already exists, set left pointer of the in-order successor as NULL, visit Current node and move to its left child node.

Output
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)

Comment
Article Tags: