Threaded Binary Tree.pptx
Threaded Binary Tree.pptx
• The threads are also useful for fast accessing ancestors of a node.
Threaded Binary Tree
Threaded Binary Tree
Advantages of Threaded Binary Tree
• It enables linear traversal of elements.
• It eliminates the use of stack as it perform linear traversal, so save memory.
• Enables to find parent node without explicit use of parent pointer
• Threaded tree give forward and backward traversal of nodes by in-order fashion
• Nodes contain pointers to in-order predecessor and successor
• For a given node, we can easily find inorder predecessor and successor. So, searching is
much more easier.
• In threaded binary tree there is no NULL pointer present. Hence memory wastage in
occupying NULL links is avoided.
• The threads are pointing to successor and predecessor nodes. This makes us to obtain
predecessor and successor node of any node quickly.
• There is no need of stack while traversing the tree, because using thread links we can
reach to previously visited nodes.
Disadvantages of Threaded Binary Tree
• Every node in threaded binary tree need extra memory to indicate whether its left or right node indicated its child nodes or its
inorder predecessor or successor. So, the node consumes extra memory.
• Insertion and deletion are more complex and time consuming as both threads and ordinary links need to be maintained.
• Implementing threads for every possible node is complicated.
• Increased complexity: Implementing a threaded binary tree requires more complex algorithms and data structures than a
regular binary tree. This can make the code harder to read and debug.
• Extra memory usage: In some cases, the additional pointers used to thread the tree can use up more memory than a regular
binary tree. This is especially true if the tree is not fully balanced, as threading a skewed tree can result in a large number of
additional pointers.
• Limited flexibility: Threaded binary trees are specialized data structures that are optimized for specific types of traversal. While
they can be more efficient than regular binary trees for these types of operations, they may not be as useful in other scenarios.
For example, they cannot be easily modified (e.g. inserting or deleting nodes) without breaking the threading.
• Difficulty in parallelizing: It can be challenging to parallelize operations on a threaded binary tree, as the threading can
introduce data dependencies that make it difficult to process nodes independently. This can limit the performance gains that
can be achieved through parallelism.
Applications of threaded binary tree
• Expression evaluation: Threaded binary trees can be used to evaluate arithmetic expressions in a way that avoids recursion or a stack. The tree can
be constructed from the input expression, and then traversed in-order or pre-order to perform the evaluation.
• Database indexing: In a database, threaded binary trees can be used to index data based on a specific field (e.g. last name). The tree can be
constructed with the indexed values as keys, and then traversed in-order to retrieve the data in sorted order.
• Symbol table management: In a compiler or interpreter, threaded binary trees can be used to store and manage symbol tables for variables and
functions. The tree can be constructed with the symbols as keys, and then traversed in-order or pre-order to perform various operations on the
symbol table.
• Disk-based data structures: Threaded binary trees can be used in disk-based data structures (e.g. B-trees) to improve performance. By threading
the tree, it can be traversed in a way that minimizes disk seeks and improves locality of reference.
• Navigation of hierarchical data: In certain applications, threaded binary trees can be used to navigate hierarchical data structures, such as file
systems or web site directories. The tree can be constructed from the hierarchical data, and then traversed in-order or pre-order to efficiently
access the data in a specific order.