×

What is a Threaded Binary Tree?

When we consider those binary trees that are interlinked with each other, we do come across the fact that the fields present in there do consist of NULL values that ultimately lead to the damage and wastage of the storage space that we use for the tree. If we have a binary tree that comprises n number of nodes, then the n+1 link fields would definitely have the NULL values.

In order to save and manage the wastage of this storage space, a new convention was introduced by two people named Perlis and Thornton. In this particular method, the links which were previously filled with NULL are significantly replaced by threads. So, the binary trees that contains threads as a replacement, those binary trees are termed threaded binary trees. Each and every node in a threaded binary tree either contain a link to their child node or thread to various other nodes present in the tree.

Types of threaded binary tree

There are majorly two types of the threaded binary trees. They are given below: -

  • One-way threaded binary tree
  • Two-way threaded binary tree

Now, we will explain each of these trees one by one in the given section.

One-way threaded binary tree

In this type of threaded binary tree, the thread usually occurs either at the left or right link of the field of a given node. If, for example, say the link pops up at the right link of the field, then it will ultimately lead and point to the next adjacent node that will appear and perform the inorder traversal operation on the tree.

Such types of trees are vividly known as the Right threaded binary trees. Whereas on the other hand, if suppose the link pops out at the left link of a given node, then it will ultimately lead and point to the next adjacent node that will appear and perform the inorder predecessor operation on the tree. Such types of trees are known as the left threaded binary trees. In such kind of threaded binary trees, the right link of the last node and the left link of the first node generally occupies a NULL value.

WHAT IS A THREADED BINARY TREE

A question arises here how do we distinguish links from threads so the answer to the same question is that threads are generally denoted by dotted lines and are pretty visible to human eyes as well.

WHAT IS A THREADED BINARY TREE

The above picture depicts that the inorder traversal and exploration of the threaded binary tree turns out to be vivid with the nodes D, B, E, A, C, and F. When this given tree is represented as the right threaded binary tree, the right link present on the tree placed on the leaf node D that also contains NULL value is generally exchanged with a thread which is represented by a dotted line. This node directly heads out and points to node B, which is the successor of node D. Likewise, in the same way, all the other trees are allotted threads.

Two-way threaded binary tree

In this type of threaded binary tree, the right link of the node which contains the NULL value is generally changed by the thread that usually enacts and points out to the nodes that are inorder successor and the left link of the node which also contains the NULL value is generally replaced by the thread. It points out the nodes that are present in the inorder predecessor.

WHAT IS A THREADED BINARY TREE
WHAT IS A THREADED BINARY TREE

Take a look at the above picture that shows us the inorder traversal of the threaded binary tree having the vertices D, B, E, G, A, C, and F. If we look at this threaded binary tree, the node that is named E that contains the value NULL is generally interchanged by a simple thread which is a dotted line to its inorder former which node B.

Likewise, the node G that we see in the above picture contains left and right field links that already contain NULL values that are also exchanged by threads which are represented by dotted lines. This is done in such a way that the right link field generally points inorder successor, and in the same manner the left link heads out to the inorder predecessor. In the same manner, all the nodes that are present in the field are allotted threads.


Related Topics

What is a 2-3 Tree in Data Structure?

Tree Data structure The information about the tree is self-explanatory. Trees are ordered and, therefore, not linear. But they are actually designed differently. Tree A node-based data model that represents and...

5 minutes read.

Types of Data Structures

Almost every programme or software system that has been built makes use of data structures. Furthermore, data structures are basics of computer science and software engineering. When it comes to...

7 minutes read.

Inorder Successor in Binary Trees

The next node in the Inorder traversal of a binary tree is known as Inorder successor of that particular node. In a Binary Search Tree, the definition of Inorder successor can...

9 minutes read.

Quick Sort

Quicksort is a sorting algorithm that uses a divide-and-conquer strategy. A pivot element is used to divide an array into subarrays (element selected from the array).  The pivot element should be...

4 minutes read.

B Tree in Data Structure

Data management is called database management. A data model is a system that stores, manages, and optimizes computer resources. Data processing is not just about data storage. Almost every app...

9 minutes read.

Bottom view of the binary tree

The bottom of the binary tree is generally defined as the number of nods present in the bottom-most part of the tree. In this article, we will see the implementation...

3 minutes read.

Selection Sort

In each iteration of the selection sort algorithm, the smallest item from an unsorted list is chosen and placed at the top of the unsorted list. Algorithm of Selection Sorting In order...

3 minutes read.

Buffer overflow attack with examples

You have undoubtedly faced the term buffer overflow in your programming journey. Many times it occurs when we try to run a piece of code with user input, but it...

4 minutes read.

Counts the number of times a given element occurs in a Linked List

Counts the number of times a given element occurs in a Linked List This article will explain how we can count the occurrences of a particular element in a list. Here,...

3 minutes read.

B+ Tree Program in Q language

A B+ tree is just an improvised version of a self-balancing and well-maintained tree in which all the key values that hold valuable information is present at the bottom, which...

9 minutes read.

Primitive Data Structure in C

The data structure is a logical or mathematical model for organizing and structuring the main memory or elements. We can classify the data structures in two ways one is primitive, and...

10 minutes read.

Difference Between Linear and Non Linear Data Structures

Data Structure A data structure is a data object together with the relationships between the instances and the individual elements that compose an instance. These relationships are defined by the operations...

5 minutes read.

Sparse Matrix in Data Structure

Sparse Matrix The sparse matrix is a two-dimensional data object which is made by m rows and n columns, so we can say the number of data values in sparse matrix...

6 minutes read.

Hashing

Hashing: Hashing is a process in which a large amount of data is mapped to a small table with the help of hashing function. It is a searching technique. Hash table We...

4 minutes read.

Red-black Tree in Data Structures?

A type of binary tree which is known as the Red-Black tree, is a specialized and unique tree. What is the urgency or, to be more precise, the necessity of...

10 minutes read.

Sort the linked list of 0s, 1s and 2s

Sort the linked list of 0s, 1s and 2s In this, we are given a linked list of 0s, 1s, and 2s, and we need to sort it. Examples: Input: 1  ->  1 ...

2 minutes read.

Stack vs Queue: Data Structure

 Difference Between Stack and Queue What is Stack? The LIFO principle applies on insertion and deletion operations of the stack which means last inserted element to the stack will remove first....

3 minutes read.

Given a Binary Tree Return All Root-to-Leaf Paths

Implementation #include <bits/stdc++.h> using namespace std; // A binary tree node generally consists of data, a pointer to the left and right child, and a pointer to the right child.  class __nod { public: int record; __nod* Lft; __nod*...

9 minutes read.

Trim a binary search tree

Implementation //writing a C++ program will help us eliminate the keys that are out of the league.  #include<bits/stdc++.h> using namespace std; //we are now creating a binary search tree node consisting of key left...

8 minutes read.

Cycle sort

Cycle sort is an examination arranging calculation which powers exhibit to be figured into the quantity of cycles where every one of them can be pivoted to create an arranged...

5 minutes read.