Tree Concepts
description
Transcript of Tree Concepts
Tree Concepts
1
A tree are very flexible, versatile and powerful
non-liner data structure that consists of finite set
of elements, called nodes, and a finite set of
directed lines called branches, that connect the
nodes.
A tree is a data structure. It is used for storing files
compiler design
text processing
searching algorithms1
2
A starting node called root.The rest of nodes can be split into T1, T2, -, Tn, which are subtrees of the root.
3
Degree Of Node :- Number of sub trees for that node
A leaf :is any node with an outdegree of zero, that is, a node
with no successors.
A node that is not a root or a leaf is known as an internal node.
A node is a parent if it has successors nodes; that is, if it has
outdegree greater than zero.
A node with a predecessor is called a child.
A path is a sequence of nodes in which each node is adjacent
to the next node.
Basic Terminology
4
5
A
B C D
E F G H I J
L M
node
leaf
parentB
childrenE
siblingsB, D
1
2
3
4ancestorsA, D, H
height or depth tree = maximum level of any node in the tree = 4degree of a tree = maximum of the degree of the nodes = 3
degree3
K
6
When the branch is directed toward the node,
it is indegree branch.
When the branch is directed away from the
node, it is an outdegree branch.
If the tree is not empty, the first node is called
the root.
Node degree=number of output paths for it.
6
7 7
8
9 9
Binary Trees
A binary tree is a finite set of nodes that is either empty or consists of a root and two disjoint binary trees called the left subtree and the right subtree.A binary tree can have no more than two descendents. In this A binary tree can have no more than two descendents. In this section we discuss the properties of binary trees, four different section we discuss the properties of binary trees, four different binary tree traversalsbinary tree traversals
• Properties• Binary Tree Traversals• Expression Trees
Binary Trees
10
A binary tree is a tree in which no node can have more than two subtrees; the maximum outdegree for a node is two.
In other words, a node can have zero, one, or two subtrees.
These subtrees are designated as the left subtree and the right subtree.
10
11 11
12 12
A null tree is a tree with no nodes
13
14
15
16
17