Lecture 8 Tree

9
Lecture 8 Tree

description

Lecture 8 Tree. Tree. Tree: Tree is a connected graph with no cycle Theorem: Let G be graph with more than one vertex. Then the following are equivalence: 1) G is a tree. 2) G is cycle-free with (n-1) edges. - PowerPoint PPT Presentation

Transcript of Lecture 8 Tree

Page 1: Lecture 8 Tree

Lecture 8Tree

Page 2: Lecture 8 Tree

TreeTree:Tree is a connected graph with no cycleTheorem:Let G be graph with more than one vertex. Then the following are equivalence:1) G is a tree.2) G is cycle-free with (n-1) edges.3) G is connected and has (n-1) edges. (i.e: if any edge is deleted then the resulting graph is

not connected)Rooted tree:A rooted tree R consists of a tree graph together with vertex r called the root of the tree. ( is a

directed tree where all arrows are directed a way from a single vertex)

Page 3: Lecture 8 Tree

TreeHeight or depth: The number of levels of a treeLeaves: The vertices of the tree that have no child

(vertices with degree one)Degree of tree: The largest number of children in the

vertices of the treeBinary tree : every vertex has at most 2 childrenOrder Rooted Tree (ORT): Whenever draw the

digraph of a tree, we assume some ordering at each level, by arranging children from left to right.

Or ; is a binary tree such that the set of children of each parent is linearly ordered from left to right.

Page 4: Lecture 8 Tree

Any algebraic expression involving binary operations +, -, , ÷ can be represented by an order rooted tree (ORT)the binary rooted tree for a+b is :

The variable in the expression a & b appear as leaves and the operations appear as the other vertices.

Page 5: Lecture 8 Tree

TreePolish notation (Binary Tree Traversal Algorithm):The polish notation form of an algebraic

expression represents the expression unambiguously with out the need for parentheses

1) In order LOR (infix) : a + b 2) Pre order OLR(prefix) : + a b 3) Post order LRO (postfix) : a b +

Page 6: Lecture 8 Tree

Treeexample 1: infix polish notation is : a + b prefix polish notation : + a bexample 2: infix polish notation is : a + 2 * b prefix polish notation : + a * 2 b

Page 7: Lecture 8 Tree
Page 8: Lecture 8 Tree
Page 9: Lecture 8 Tree

Example5: according to the following digraph

Post order : 1.5.3.15.30.20.9.8Pre order : 8.3.1.5.9.20.15.30In order : 1.3.5.8.9.15.20.30

8

3 9

1 520

3015