1 / 11

Chap 9 Trees

Chap 9 Trees. Def 1: A tree is a connected,undirected, graph with no simple circuits . Ex1. Theorem1: An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices. Chap 9 Trees.

jaron
Download Presentation

Chap 9 Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chap 9 Trees • Def 1: A tree is a connected,undirected, graph with no simple circuits . Ex1. • Theorem1: An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.

  2. Chap 9 Trees • Root , rooted tree, parent , child , siblings , ancestors , descendants,leaf ,subtree,internal vertices:have children • Ex2 • Def 2:m-ary tree : every internal vertex has no more than m children;full m-ary tree ; binary tree.

  3. Chap 9 Trees • Trees as models • Properties of trees • Theorem2: A tree with n vertices has n-1 edges. • Theorem3: A full m-ary tree with i internal vertices contains n=mi+1 vertices.

  4. Chap 9 Trees • Level of a vertex :length of the unique path from the root to the vertex • height of a rooted tree:length of the longest path from the root • Ex10 a rooted m-ary tree of height h is balance if all leaves are at levels h or h-1

  5. Chap 9 Trees • Tree traversal ordered rooted tree ; left/right child/subtree • Def1: preorder traversal of an ordered rooted tree Fig 2; Ex2 Def 2: inorder traversal Fig 5, Ex3 Def 3: postorder traversal Fig 7, Ex4

  6. Chap 9 Trees • Fig 9 : preorder : list each vertex the first time this curve passes it . inorder : list a leaf the first time the curve passes it ; list each internal vertex the second time the curve passes it postorder :list a vertex the last time it is passed on the way back up to its parent.

  7. Chap 9 Trees • Represent complicated expressions using ordered rooted trees • Ex5 inorder traversal produces the original expression with the elements and operations in the same order as they originally occurred . infix form ( Fig 11) : need to include parentheses whenever an operation is encountered in the inorder traversal

  8. Chap 9 Trees • Prefix form : no parenthesis are needed (Polish notation) Ex6 We can evaluate an expression in prefix form by working from right to left Ex7 Postfix form (reverse Polish notation) : no parenthesis are needed

  9. Chap 9 Trees • Ex8 evaluate an expression from left to right Ex9 Ex10 Because prefix and postfix expressions are unambiguous and can easily be evaluated , they are extensively used in computers science.

  10. Chap 9 Trees • Spanning Tree Def1 : let G be a simple graph .A spanning tree of G is a subgraph of G that is a tree containing every vertex of G (n vertices with n-1 edges) Ex1. Algorithm for constructing spanning tree depth-first search /backtracking Ex3. breadth-first search Ex4.

  11. Chap 9 Trees Minimum Spanning Tree • Def 1 : A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible sum of weights of its edges Prim’s algorithm Ex2. Kruskal’s algorithm Ex3.

More Related