Threaded Binary Tree (TBT)
In a Threaded Binary Tree, the empty (NULL) left or right pointers in a binary tree are used to
point to the in-order predecessor or successor. This helps in faster in-order traversal without
using recursion or a stack.
Why use it?
In a normal binary tree, many pointers are NULL. We use these NULLs to store extra info
(threads) to make traversal easier.
Types:
Single Threaded – only left or right is threaded.
Double Threaded – both left and right are threaded.
Example:
For this tree:
4
/\
2 5
/\
1 3
In-order: 1 → 2 → 3 → 4 → 5
In a threaded tree:
Node 1's right points to 2 (its next node).
Node 3's right points to 4.
Node 5's right is NULL (no thread needed).
Benefits:
Saves memory
Faster traversal (no stack or recursion)