Threaded Binary Trees
Threaded Binary Trees
Threaded Binary Trees
Speeding up traversals
Objectives
. 40 . . 72 .
30 . 50 . 69 80
60
One Way Threaded Binary Trees
The empty left child field of a node can be used to point to its inorder
predecessor.
Similarly, the empty right child field of a node can be used to point to
its in-order successor.
Such a type of binary tree is known as a one way threaded binary tree.
A field that holds the address of its in-order successor is known as thread.
In-order :- 30 40 50 60 65 69 72 80 . 65 .
. 40 . . 72 .
30 50 . 69 80
60
Two way Threaded Binary Trees
. 40 . . 72 .
30 50 . 69 80
60
Node 30 does not have an inorder predecessor because it
is the first node to be traversed in inorder sequence.
Similarly, node 80 does not have an inorder successor.
. 65 .
. 40 . . 72 .
30 50 . 69 80
60
Two way Threaded Binary Trees with header Node
Header Node
. 65 .
. 40 . . 72 .
30 50 . 69 80
60
The threaded binary tree is represented as the left child of the header node.
Header Node
. 65 .
. 40 . . 72 .
30 50 . 69 80
60
The left thread of node 30 and the right thread of node 80
point to the header node. Header Node
. 65 .
. 40 . . 72 .
. 30 50 . 69 80 .
60
Representing a Threaded Binary Tree
Answer:
successor, predecessor