You are on page 1of 36

Tree &

Terminologies
Tree: Collection of data (Node) which is
organized in hierarchical structure
Hamza Ashraf (BCSM-F19-368) recursively.
Muhammad Usama (BCSM-F19-
474)
Table of contents
01 02
Tree Defination Applications
Non-linear data structure 3 Real life Applications of
organizes data in tree used nowadays
hierarchical structure

03 04
Terminologies Examples
15 Terminologies of Tree 2 Examples of each
Terminology
What is a Tree?
1) A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of a
distinguished node, r, called the root, and zero or more nonempty (sub)trees T1, T2, ... , Tk, each
of whose roots are connected by a directed edge from r. (DSAA by Mark Allen Weiss)
page 121.

2) A tree is a finite set of one ore more nodes such that;


● There is a specially designed node called the root.
● The remaining nodes are partitioned into n>=0 disjoined sets T1, T2, ... , Tn, Where each
of these sets is a tree and these are called the subtrees of the root. (Fundamentals
of DSA by Ellis Horowitz) page 220.

1) It consists of an ordered set of linked nodes in a connected graph, in which each node has at
most one parent node, and zero or more children nodes with a specific order. (DSA By John
Bullinaria) page31.
Applications Of Tree

Databases File Explorer


Databases also File explorer/my
uses tree data computer of
structures for Domains mobile/any
indexing. Domain Name computer.
Server(DNS) also
uses tree
structures.
Terminologies a Tree?
1. Root 2. Edge 3. Parent 4. Child 5. Siblings

7. Internal
6. Leaf 8. Degree 9. Level 10. Height
Nodes

14. External 15. Forest


11. Depth 12. Path 13. Sub Tree
Nodes
Terminologies

Root ● The first node from where the tree


originates is called as a root node.
● In any tree, there must be only one root
node.
● We can never have multiple root nodes in a
tree data structure.
Root (Examples)

1 is the root node here. Root node is


mentioned .
Terminologies

Edges
● The connecting link between any two nodes is
called as an edge.
● In a tree with n number of nodes, there are
exactly (n-1) number of edges.
Edges (Examples)

Connecting line b/w Edge or link is


two nodes. mentioned.
Terminologies

Parent
● The node which has a branch from it to any
other node is called as a parent node.
● In other words, the node which has one or more
children is called as a parent node.
● In a tree, a parent node can have any number of
child nodes.
Parent (Examples)

2 is the parent of 7 and


1 is the parent of 2 and
5
3
7 is the parent of 2 and
2 is the parent of 4 and
6
5
6 is the parent of 5, 11
5 is the parent of 6,7,8
….
Terminologies

Child

● The node which is a descendant of some node


is called as a child node.
● All the nodes except root node are child nodes.
Child (Examples)

2 and 3 are childs of 1 7 and 5 are childs of 2


4 and 5 are childs of 2 2 and 6 are childs of 7
6,7, and 8 are childs of 5 and 11 are childs of
5 6 ...
Terminologies

Siblings
● Nodes which belong to the same parent are
called as siblings.
● In other words, nodes with the same parent are
sibling nodes.
Siblings (Examples)

2 and 3 are siblings 7 and 5 are siblings


4 and 5 are siblings 2 and 6 are siblings
6,7, and 8 are siblings 5 and 11 are siblings
Terminologies

Leaf
● The node which does not have any child is
called as a leaf node.
● Leaf nodes are also called as external nodes or
terminal nodes.
Leaf (Examples)

3, 4, 6, 7, and 8 are 2, 5, 11, and 4 are


leafs Leafs
Terminologies

Internal
Nodes
● The node which has at least one child is called
as an internal node.
● Internal nodes are also called as non-terminal
nodes.
● Every non-leaf node is an internal node.
Internal Nodes (Examples)

1, 2, and 5 are Internal 2, 7, 6, 5, and 9 are


Nodes Internal Nodes
Terminologies

External
Nodes
● The node which has not any child is called as
an external node.
● External nodes are also called as terminal
nodes.
● Every leaf node is an External node.
External Nodes (Examples)

3, 4, 6, 7, and 8 are 2, 5, 11, and 4 are


External Nodes External nodes
Terminologies

Degree
● Degree of a node is the total number of children
of that node.
● Degree of a tree is the highest degree of a node
among all the nodes in the tree.
Degree (Examples)

Degree of 1 and 2 is Degree of 2, 7, and 6 is


two, and degree of 5 is two. Degree of 5 and 9 is
three. one.
Terminologies

Level
● In a tree, each step from top to bottom is called
as level of a tree.
● The level count starts with 0 and increments by
1 at each level or step.
Level (Examples)
Level Level
0 0
Level Level
1 1
Level Level
2 2
Level
3 Level
3
It has level from 0 to 3 It has level from 0 to 3
Terminologies

Height
● Total number of edges that lies on the longest
path from any leaf node to a particular node is
called as height of that node.
● Height of a tree is the height of root node.
● Height of all leaf nodes = 0
Height (Examples)

Height of root node is Height of root node is


3, and 5 is one. 3, and 7 is 2.
Terminologies

Depth ● Total number of edges from root node to a


particular node is called as depth of that node.
● Depth of a tree is the total number of edges
from root node to a leaf node in the longest
path.
● Depth of the root node = 0
● The terms “level” and “depth” are used
interchangeably.
Depth (Examples)

Depth of root is 0, and Depth of root 2 is zero,


leaf 7 is 3. and leaf 11 is 3.
Terminologies

Path
● In a tree data structure, the sequence of Nodes
and Edges from one node to another node is
called as PATH between that two Nodes.
● Length of a Path is total number of nodes in
that path.
Path (Examples)

Path of 1 to 7 is, 1,2,5, Path of 2 to 11 is, 2, 7,


and 7. 6, and 11
Terminologies

Sub Tree
● In a tree, each child from a node forms a
subtree recursively.
● Every child node forms a subtree on its parent
node.
Sub-tree (Examples)

Node 2 and 5 are Node 7 and 6 are


making subtrees making subtrees.
Terminologies

Forest
● A forest is a set of disjoint trees.
● Forest in data structure Creating forest from a
tree.
● You can create a forest by cutting the root of a
tree
Forest (Examples)

Node 2 and 5 are Node 7 and 6 are


making subtrees making subtrees.
Thanks!
Do you have any questions?

Hamza Ashraf (BCSM-F19-368)


Muhammad Usama (BCSM-F19-474)
Zain Asif (BCSM-F19-451)

CREDITS: This presentation template was created by


Slidesgo, including icons by Flaticon and infographics &
images by Freepik

You might also like