Chapter - 10: Tree Part-1
Chapter - 10: Tree Part-1
Tree
Part-1
Nature View of a Tree
Leaves
Branches
Root
2
Computer Scientist’s View
3
Definition
4
Cont.
5
Cont.
Computers”R”Us
7
Applications of Tree
8
Rooted Tree
Fig: A tree and rooted trees formed by designating two different roots.
9
Tree terminology
Tree Structure:
(1). Root (2). Parent, Children, Leaf (3). Internal node, External
Node (4). Degree of a Node and Tree (5). Path (6). Level
(7). Siblings (8). Ancestor, Descendant.
10
Cont.
Root
The node without parent is called root node. Every tree must
have root node. We can say that root node is the origin of tree
data structure. In any tree, there must be only one root node.
We never have multiple root nodes in a tree.
11
Cont.
Edge
In a tree data structure, the connecting link between any two
nodes is called as edge. In a tree with 'N' number of nodes
there will be a maximum of 'N-1' number of edges.
12
Cont.
Parent:
In a tree data structure, the node which is predecessor/ancestor
of any node is called as parent node. in simple words, the node
which has branch from it to any other node is called as parent
node. parent node can also be defined as "the node which has
child / children".
13
Cont.
Child
In a tree data structure, the node which is descendant of any
node is called as child node. In simple words, the node
which has a link from its parent node is called as child node.
In a tree, any parent node can have any number of child
nodes. In a tree, all the nodes except root are child nodes.
14
Cont.
Leaf
In a tree data structure, the node which does not have a child
is called as leaf node. In simple words, a leaf is a node with
no child.
In a tree data structure, the leaf nodes are also called as
external nodes. External node is also a node with no child. In
a tree, leaf node is also called as ‘terminal' node.
15
Cont.
Internal Node
In a tree data structure, the node which has at least one child is
called as internal node. In simple words, an internal node is a node
with at least one child.
In a tree data structure, nodes other than leaf nodes are called as
internal nodes. The root node is also said to be internal node if the
tree has more than one node. Internal nodes are also called as 'non-
terminal' nodes.
16
Cont.
Degree
In a tree data structure, the total number of children of a
node is called as degree of that node. In simple words,
the degree of a node is total number of children it has.
The highest degree of a node among all the nodes in a
tree is called as 'degree of tree‘.
17
Cont.
Level
In a tree data structure, the root node is said to be at Level 0
and the children of root node are at Level 1 and the children of
the nodes which are at Level 1 will be at Level 2 and so on...
In simple words, in a tree each step from top to bottom is
called as a Level and the Level count starts with '0' and
incremented by one at each level (Step).
18
Cont.
Sub Tree
In a tree data structure, each child from a node forms a subtree
recursively. Every child node will form a subtree on its parent
node.
19
Cont.
Siblings
In a tree data structure, nodes which belong to same parent
are called as siblings. In simple words, the nodes with same
parent are called as sibling nodes.
20
Cont.
Ancestor: The ancestors of a node are all the nodes along the path
from node to the root node. [parent, grandparent, grand-grandparent, etc.]
If node A is an
ancestor of node B
then node B is a
descendant of node A.
21
Cont.
Descendant: The descendent of a node are all the nodes along the
path from node to the leaf node. [child, grandchild, grand-grandchild, etc.]
If node A is an
ancestor of node B
then node B is a
descendant of node A.
22
Cont.
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.
23
Cont.
24
Cont.
25
Binary Tree
27
Cont.
28
Binary Tree Terminology
29
Full Binary Trees
Here are two important types of binary trees. Note that the
definitions, while similar, are logically independent.
Full Binary Tree: A full binary tree (sometimes proper binary
tree) is a tree in which every node other than the leaves has two
children.
30
Properties of Trees
31
Cont.
32
Complete binary tree
33
Perfect Binary tree
34
Extended Binary Trees: 2-Trees
35