Professional Documents
Culture Documents
8/28/16
1.Introduction
It is non-linear, two dimensional data structure which represents
hierarchical relationships between its individual data items.
Typically there is one node in the top row of a tree, with lines
connecting to more nodes on the second row, even more on the third,
and so on.
Thus trees are small on the top and large on the bottom.
A tree T is a set of nodes storing elements such that the nodes have a
parent-child relationship that satisfies the following condition .
8/28/16
8/28/16
Degree
Indegree
Indegree of node B =1
Indegree of node C = 1
Outdegree
Outdegree of node B = 3
Outdegree of node C = 2
8/28/16
(Continued..)
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.
8/28/16
(Continued..)
Parent
In a tree data structure, the
node which is predecessor of
any node is called as Parent
node.
A node is a parent if it has
successor nodes- that is, if it has
an outdegree greater than zero.
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".
8/28/16
(Continued..)
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.
A node is a parent if it has
predecessor nodes- that is, if it
has an indegree of one.
In a tree, any parent node
can have any number of child
nodes.
In a tree, all the nodes
except root are child nodes.
8/28/16
10
(Continued..)
Siblings
In a tree data
structure, nodes which
belong to same Parent
are called as Siblings.
Two or more nodes
with the same parent are
siblings.
In simple words, the
nodes with same parent
are called as Sibling
nodes.
8/28/16
11
(Continued..)
8/28/16
12
(Continued..)
Internal node
A node that is not a
root or a leaf is known
as an internal node
because it is found in the
middle portion of a tree.
8/28/16
13
(Continued..)
Level of a node
The level of a node
is its distance from the
root.
Because the root has
a zero distance from
itself, the root is at level
0. The children of the
root are at level 1, their
children are level 2, and
so forth.
8/28/16
14
(Continued..)
Height
In a tree data
structure,
the
total
number of edges from
leaf node to a particular
node in the longest path
is called as HEIGHT of
that Node.
In a tree, height of
the root node is said to
be height of the tree.
In a tree, height of
all leaf nodes is '0'.
8/28/16
15
(Continued..)
Depth
In a tree data structure,
the total number of edges from
root node to a particular node
is called as DEPTH of that
Node.
In a tree, the total number
of edges from root node to a
leaf node in the longest path is
said to be Depth of the tree.
In simple words, the
highest depth of any leaf node
in a tree is said to be depth of
that tree.
In a tree, depth of the root
node is '0'.
8/28/16
16
(Continued..)
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.
In example the path A
- B - E - J has length 4.
8/28/16
17
(Continued..)
Subtree
A tree may be divided into
subtrees. A subtree is any connected
structure below the root.
The first node in a subtree is
known as the root of the subtree and
is used to name the subtree.
Furthermore, subtrees can be
subdivided into subtrees.
The concept of subtrees leads
us to a recursive definition of a tree:
a tree is a set of nodes that either (1)
is empty, or (2) has a designated
node, called the root, from which
hierarchically descend zero or more
subtrees, which are also trees.
In Example, {B, D, E, F, I, J},
{E, I, J}, {C, G, H, K} are the
subtrees.
8/28/16
18
Length of a path =
number of edges
Depth of a node N =
length of path from root to N
Height of node N =
length of longest path from N
to a leaf
Depth and height of tree
= height of root
In this example Depth =0
and height =2 for root node A.
Depth =2 and height = 0
for leaf nodes C,D, G,H and I.
8/28/16
19
8/28/16
20
Parents: A, B, F
Leaves: C, D, G, H, I
Children: B, E, F, C, D, G, H,
I
Internal Nodes: B, F
Siblings: {B, E, F}, {C, D},
{G, H, I} Root: A
Degree of the node A is 3.
Ancestor of node H is
A, F.
Indegree of the node F is 1
and outdegree of the node F is
3.
8/28/16
21
Forest
8/28/16
22
4. Applications of Trees
1. Directory tree
Organizes directories and files hierarchically.
Directories are internal nodes; files are leaf nodes (usually).
2. Class hierarchy
Object is root, other classes are descendents.
3. Decision tree
Binary tree.
Path taken determined by Boolean expression.
4. Expression tree
Operators are internal nodes, variables and constants are leaf
nodes.
8/28/16
23
24
6. Tree Representation
A tree data structure can be represented in two methods. Those
methods are as follows,
List representation
Left Child-Right sibling representation
Consider the following tree shown in figure 3-4
In any tree with N nodes there will be maximum of N-1 edges. In
a tree every individual element is called as node.
8/28/16
25
8/28/16
26
8/28/16
27
8/28/16
28
8/28/16
29
(Continued..)
In this representation, every node's data field stores the actual value
of that node.
If that node has left child, then left reference field stores the address
of that left child node otherwise that field stores NULL.
If that node has right sibling then right reference field stores the
address of right sibling node otherwise that field stores NULL.
The above tree example 3-4 can be represented using Left Child Right Sibling representation as follows shown in the figure 3-7.
8/28/16
30
8/28/16
31
Properties of a tree
Any node can be the root of the tree and each node in a tree has the
property that there is exactly one path connecting that node with
every other node in the tree.
The tree in which the root is identified is called a rooted tree; and a
tree in which the root is not identified is called a free tree.
Each node, except the root, has a unique parent.
8/28/16
32
Questions
1.
2.
3.
8/28/16
33
(Continued..)
Explain briefly about the basic terminologies of the tree with
example.
Explain briefly about the representation of the tree.
8/28/16
34
8/28/16
35