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

Binary Tree ADT

Uploaded by

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

Binary Tree ADT

Uploaded by

nvkeerthuvcet
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Binary Tree ADT

What is Binary Tree ADT?


• Binary tree is a tree data structure(non-linear) in
which each node can have at most two
children which are referred to as the left child and
the right child.
• The topmost node in a binary tree is called the root
• The bottom-most nodes are called leaves
• A binary tree can be visualized as a hierarchical
structure with the root at the top and the leaves at the
bottom.
Representation
Each node in a Binary Tree has three
parts:
•Data
•Pointer to the left child
•Pointer to the right child
Operations
• Insertion
• Deletion
• Searching
Insertion
• We can insert a node anywhere in a binary tree by inserting
the node as the left or right child of any node or by making
the node as root of the tree.
• Steps:
1. Check if there is a node in the binary tree, which has
missing left child. If such a node exists, then insert the
new node as its left child.
2. Check if there is a node in the binary tree, which has
missing right child. If such a node exists, then insert the
new node as its right child.
3. If we don’t find any node with missing left or right child,
then find the node which has both the children missing
and insert the node as its left or right child.
Deletion
• We can delete any node in the binary tree and
rearrange the nodes after deletion to again form a valid
binary tree.
• Steps:
1. Starting at the root, find the deepest and rightmost
node in the binary tree and the node which we want to
delete.
2. Replace the deepest rightmost node’s data with the
node to be deleted.
3. Then delete the deepest rightmost node.
Searching
• Start from the root node.
• Check if the current node’s value is equal to the target
value.
• If the current node’s value is equal to the target value,
then this node is the required node.
• Otherwise, if the node’s value is not equal to the target
value, start the search in the left and right child.
• If we do not find any node whose value is equal to
target, then the value is not present in the tree.

You might also like