Binary-tree
Binary-tree
Applications
Anshuman Singh
Senior Execut ive - Cont ent
Updated on Jul 15, 2024 14:27 IST
Have you ever wondered how computers organize complex data efficiently?
One answer lies in the tree data structure, a hierarchical model that
resembles a tree in nature, with a single root leading to various branches
and leaves, enabling quick data retrieval and manipulation. Let's understand
more!
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
structure.
Table of Content
What is Tree in Data Structure?
Binary Trees
Binary Search Trees
AVL Trees
B-Tree
In the relation mentioned above if ‘A’ is the grandfather of ‘F’, and ‘C’ is the uncle of
‘D’. Which of the above diagrams would you choose to answer,
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Who is the f ather of ‘E’?
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Tree Data Structure Terminologies
Example f rom
Terminology Description
Diagram
‘1’, ‘2’, ‘3’ are the
Node Each vertex of a tree is a node.
node in the tree.
Node ‘1’ is the
Root Topmost node of a tree. topmost root
node.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Node ‘2’ is the
parent of ‘5’ and
The node has an edge-sharing to a
Parent Node ‘6’, and Node ‘3’
child node.
is the parent of
‘7’.
The sub-node of a parent node is the ‘5’ and ‘6’ is the
Child Node
child node. children of ‘2’.
The last node which have any ‘5’, ‘6’, ‘9’ and ‘8’
Leaf
subnode is the leaf node. are leaf nodes.
The link
between ‘1’ and
Edge Connecting link between two nodes. ‘2’, ‘2’ and ‘5’, ‘2’
and ‘6’ are
edges
‘5’ and ‘6’ are
Nodes with the same parent are
Siblings siblings with ‘2’
siblings.
as their parent.
The height of a tree is the length of
The height of ‘1’
the longest path f rom the root to a
Height is 3. (longest
leaf node. It is calculated with the
path is 1-3-7-9)
total number of edges.
The number of edges f rom the root
The depth of
node to that node is called the Depth
root node ‘1’ is
Depth of that node.
the height of ‘1’
Depth of a tree = Height of tree –
–1=2
1
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Each step f rom top to bottom is ‘1’ or root node
called a Level. If the root node is at is at level 0, ‘2’,
Level level 0, its next child node is at level ‘3’, and ‘4’ is at
1, its grandchild is at level 2, and so level 1, and so
on. on.
Nodes ‘2’, ‘5’,
Descendants of a node represent a and ‘6’
Sub-Tree
subtree. represent a sub-
tree.
The degree of
Degree of The degree of a node represents the ‘2’ is 2 (‘5’ and
Node total number of children in it. ‘6’). The degree
of ‘4’ is 1.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Webpage Layout
The layout of a webpage is designed in the tree structure. In the below diagram, the
homepage or index page is our root node, main sections/ site index are their child
nodes, which again are parents to multiple other child nodes (subsections).
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Int roduct ion t o Linked List Dat a St ruct ure
In this article, yo u will understand what linked list are, what are vario us
o peratio ns yo u can perfo rm o n them and ho w to implement it in C.
Binary Tree
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Binary Search Tree (BST)
AVL Tree
B-Tree
Binary Tree
A binary tree is a tree data structure in which each node can have 0, 1, or 2 children
– left and right child.
Perf ect binary tree: Every internal node has two child nodes. All the
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
leaf nodes are at the same level.
Full binary tree: Every parent node or an internal node has either
exactly two children or no child nodes.
Complete binary tree: All levels except the last one are f ull of
nodes.
Degenerate binary tree: All the internal nodes have only one child.
Balanced binary tree: The lef t and right trees dif f er by either 0 or 1.
To learn more about binary trees, read our blog – Types of Binary Tree
in Data Structure
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Working with Morse Code
The organization of Morse code is done in the form of a binary tree
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
value at the left sub-tree is lesser than that of the root and the right subtree has a
value greater than that of the root.
Every binary search tree is a binary tree. However, not every binary tree is a binary
search tree. What’s the difference between a binary tree and a binary search tree?
The most important difference between the two is that in a BST, the left child
node’s value must be less than the parent’s, while the right child node’s value must
be higher.
The value of all the nodes in the lef t sub-tree is less than the value of
the root.
The value of all the nodes in the right subtree is greater than or equal
to the value of the root.
This rule is recursively valid f or all the lef t and right subtrees of the
root.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
Applications of a Binary Search Tree
Used to ef f iciently store data in the sorted f orm to quickly access
and search stored elements.
Given ‘A’ a sorted array, determine how many times x occurs in ‘A’.
Player ‘A’ chooses a secret number ‘n’. Player ‘B’ can guess a number
x and A replies how x
AVL Tree
AVL trees are a special kind of self-balancing binary search tree where the height of
every node’s left and right subtree differs by at most one.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
The heights of the two child subtrees of any node dif f er by at most
one.
-1 Balance f actor represents that the right subtree is one level higher
than the lef t.
B-Tree
B tree is a self-balancing search tree wherein each node can contain more than one
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
key and more than two children. It is a special type of m-way tree and a generalized
binary search tree. B-tree can store many keys in a single node and can have
multiple child nodes. This reduces the height and enables faster disk access.
Properties of a B-Tree
Every node contains at most m children.
Every node contains at least m/2 children (except the root node and
the leaf node).
Application of B-trees
Databases and f ile systems
Multilevel indexing
Conclusion
Data structures are the building block of programming languages. They are used in
many areas of Computer Science for simple and complex computations. Good
knowledge of Tree data structures is the foundation of writing good codes. It
can help you to grow to new heights in your career and secure high-paying jobs in
the programming world.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.
FAQs
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 16 -Jul-20 24.