Tree Concepts

17
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 algorithms 1

description

Tree Concepts. 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 - PowerPoint PPT Presentation

Transcript of Tree Concepts

Page 1: 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

Page 2: Tree Concepts

2

A starting node called root.The rest of nodes can be split into T1, T2, -, Tn, which are subtrees of the root.

Page 3: Tree Concepts

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

Page 4: Tree Concepts

4

Page 5: Tree Concepts

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

Page 6: Tree Concepts

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

Page 7: Tree Concepts

7 7

Page 8: Tree Concepts

8

Page 9: Tree Concepts

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

Page 10: Tree Concepts

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

Page 11: Tree Concepts

11 11

Page 12: Tree Concepts

12 12

A null tree is a tree with no nodes

Page 13: Tree Concepts

13

Page 14: Tree Concepts

14

Page 15: Tree Concepts

15

Page 16: Tree Concepts

16

Page 17: Tree Concepts

17