0% found this document useful (0 votes)
13 views

Threads Algorithm

Threaded binary trees are a modification to binary trees that reduce wasted storage space. In threaded binary trees, NULL links are replaced with special links called threads that point to other nodes. There are two types of threaded binary trees: one-way threaded trees that use threads in either the left or right links, and two-way threaded trees that use threads in both left and right links to directly connect predecessors and successors in inorder traversal. Threaded binary trees allow faster traversal without wasting space on NULL links.

Uploaded by

123abc jk
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Threads Algorithm

Threaded binary trees are a modification to binary trees that reduce wasted storage space. In threaded binary trees, NULL links are replaced with special links called threads that point to other nodes. There are two types of threaded binary trees: one-way threaded trees that use threads in either the left or right links, and two-way threaded trees that use threads in both left and right links to directly connect predecessors and successors in inorder traversal. Threaded binary trees allow faster traversal without wasting space on NULL links.

Uploaded by

123abc jk
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

UNIVERSITY INSTITUTE OF

ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE
AND ENGG.

Bachelor of Engineering (Computer Science & Engineering)


DATA STRUCTURES 22CSH-211/22ITH-211

TREES DISCOVER . LEARN . EMPOWER


THREADS 1
Threaded Binary Tree

• In the linked representation of binary trees, more than one half of the
link fields contain NULL values which results in wastage of storage
space.
• If a binary tree consists of n nodes then n+1 link fields contain NULL
values. So in order to effectively manage the space, a method was
devised by Perlis and Thornton in which the NULL links are replaced
with special links known as threads. Such binary trees with threads
are known as threaded binary trees.
• Each node in a threaded binary tree either contains a link to its child
node or thread to other nodes in the tree.

2
3
Types of Threaded Binary Tree

• One-way threaded Binary Tree


• Two-way threaded Binary Tree

4
One-way threaded Binary trees
• In one-way threaded binary trees, a thread will appear either in the right or left
link field of a node.
• If it appears in the right link field of a node then it will point to the next node that
will appear on performing in order traversal. Such trees are called Right threaded
binary trees.
• If thread appears in the left field of a node then it will point to the nodes inorder
predecessor. Such trees are called Left threaded binary trees.
• Left threaded binary trees are used less often as they don't yield the last
advantages of right threaded binary trees.
• In one-way threaded binary trees, the right link field of last node and left link field
of first node contains a NULL. In order to distinguish threads from normal links
they are represented by dotted lines.
5
The above figure shows the inorder traversal of this binary tree yields D, B, E, A, C, F.
When this tree is represented as a right threaded binary tree, the right link field of leaf
node D which contains a NULL value is replaced with a thread that points to node B
which is the inorder successor of a node D. In the same way other nodes containing
values in the right link field will contain NULL value.
6
Two-way threaded Binary Trees
• In two-way threaded Binary trees, the right link field of a node
containing NULL values is replaced by a thread that points to nodes
inorder successor and left field of a node containing NULL values is
replaced by a thread that points to nodes inorder predecessor.

7
The above figure shows the inorder traversal of this binary tree yields D, B, E, G, A, C, F. If we consider the
two-way threaded Binary tree, the node E whose left field contains NULL is replaced by a thread pointing to its
inorder predecessor i.e. node B. Similarly, for node G whose right and left linked fields contain NULL values
are replaced by threads such that right link field points to its inorder successor and left link field points to its
inorder predecessor. In the same way, other nodes containing NULL values in their link fields are filled with
threads.
8
References
1. Li`pschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
2. Data structure and algorithm by Narasimha Karumanchi.
3. www.tutorialspoint.com
4. www.geeksforgeeks.com

9
Books Recommended
• Goodrich, Michael T., Tamassia, Roberto, and Mount, David M., “Data Structures and
Algorithms in C++”, Wiley Student Edition.
• Aho, Alfred V., Ullman, Jeffrey D., Hopcroft ,John E. “Data Structures and Algorithms”,
Addison Wesley
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
• Gilberg/Forouzan,” Data Structure with C ,Cengage Learning.
• Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures using C and C++”, Prentice Hall
of India
THANK YOU

11

You might also like