0% found this document useful (0 votes)
70 views10 pages

Tree Data Structures Explained

Uploaded by

farhanriaz0000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views10 pages

Tree Data Structures Explained

Uploaded by

farhanriaz0000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

TREE

Data Structure and Algorithm


Tree
A tree is a non-linear abstract
data type with a hierarchy-
based structure. It consists of
nodes(where the data is
stored) that are connected via
links. The tree data structure
stems from a single node
called a root node and has
subtrees connected to the
root.
Important Terms
• Path − Path refers to the sequence of nodes
along the edges of a tree.
• Root − The node at the top of the tree is called
root. There is only one root per tree and
• one path from the root node to any node.
• Parent − Any node except the root node has
one edge upward to a node called parent.
• Child − The node below a given node
connected by its edge downward is called its
child node.
Leaf − The node which does not have any child node is
called the leaf node.
Subtree − Subtree represents the descendants of a node.
Visiting − Visiting refers to checking the value of a node
when control is on the node
Traversing − Traversing means passing through nodes in
a specific order.
Levels − Level of a node represents the generation of a
node. If the root node is at level 0,then its next child node
is at level 1, its grandchild is at level 2, and so on.
Keys − Key represents a value of a node based on which a
search operation is to becarried out for a node.
Types of Trees

• General Trees
• Binary Trees
• Binary Search Trees
General Trees
General trees are
unordered tree data
structures where the
root node has minimum
0 or maximum ‘n’
subtrees.
The General trees have
no constraint placed on
their hierarchy. The root
node thus acts like the
superset of all the other
subtrees.
Binary Tree
Binary Trees are general trees
in which the root node can
only hold up to maximum 2
subtrees:left subtree and
right subtree. Based on the
number of children,
Type of binary Tree
• Full Binary Tree
• Perfect Binary Tree
• Complete Binary Tree
• A complete binary Tree
• Binary Search Trees possess all the properties of
Binary Trees including some extra properties of their
own, based on some constraints, making them more
efficient than binary trees.
• A full binary tree is a binary tree type where every node
has either 0 or 2 child nodes.
• A complete binary tree is a binary tree type where all
the leaf nodes must be on the same level. However,
root and internal nodes in a complete binary tree can
either have 0, 1 or 2 child nodes.
• A perfect binary tree is a binary tree type where all the
leaf nodes are on the same level and every node
except leaf nodes have 2 children
Binary Search Tree
Binary Search Trees possess all the properties of
Binary Trees including some extra properties of
their own, based on some constraints, making
them more efficient than binary trees.
The data in the Binary Search Trees (BST) is
always stored in such a way that the values in
the left subtree are always less than the values in
the root node and the values in the right subtree
are always greater than the values in the root
node, i.e. left subtree < root node ≤ right subtree

You might also like