[go: up one dir, main page]

0% found this document useful (0 votes)
26 views4 pages

Thread Representation of A Binary Tree: Inorder Listing: Head, C, B, A, E, F, D, G, Head

The document describes the representation and traversal of a threaded binary tree, including functions to find the inorder successor and predecessor of a node. It outlines the process for inserting a new node into the tree and provides an example of inorder listing. The document emphasizes the structure and operations of threaded binary trees for efficient traversal and manipulation.

Uploaded by

uttam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Thread Representation of A Binary Tree: Inorder Listing: Head, C, B, A, E, F, D, G, Head

The document describes the representation and traversal of a threaded binary tree, including functions to find the inorder successor and predecessor of a node. It outlines the process for inserting a new node into the tree and provides an example of inorder listing. The document emphasizes the structure and operations of threaded binary trees for efficient traversal and manipulation.

Uploaded by

uttam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Thread Representation of a Binary Tree

Inorder Listing: Head, C, B, A, E, F, D, G, Head


Searching the address of inorder successor of a node
with address X
e
P-RPTR(X)|

Function INS(X)

1. P:= RPTR(X)
If RPTR(X) < 0 then
Return(P)

2. Repeat while LPTR(P) > 0


P:= LPTR(P)

3. Return(P)
Searching the address of inorder predecessor of a node
with address X
Function INP(X)

1. P:= LPTR(X)
If LPTR(X) < 0 then
Return(P)

2. Repeat while RPTR(P) > 0


P:= RPTR(P)

3. Return(P)

Inorder Traversal of a Threaded Binary Tree

1. P:= HEAD

2. Repeat while True


P:= INS(P)
If P=HEAD then
Exit
Else Write (INFO(P))

Inorder Listing: Head, C, B, A, E, F, D, G, Head


Insertion into a Threaded Binary Tree

Case 1: LEFT(X) = Null Case 2: Insert between X and LEFT(X)


INS-LEFT(X, ITEM)
1. P:=NEW
INFO(P):=ITEM
2. LPTR(P):=LPTR(X)
LPTR(X):= P
RPTR(P):= - X
3. If LPTR(P) > 0 then
RPTR(INP(P)):= -P
Return

You might also like