chap 8 trees def 1: a tree is a connected,undirected, graph with no simple circuits. ex1. theorem1:...
TRANSCRIPT
![Page 1: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/1.jpg)
Chap 8 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.
![Page 2: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/2.jpg)
Chap 8 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.
![Page 3: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/3.jpg)
Chap 8 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.
![Page 4: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/4.jpg)
Chap 8 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
![Page 5: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/5.jpg)
Chap 8 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
![Page 6: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/6.jpg)
Chap 8 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.
![Page 7: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/7.jpg)
Chap 8 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
![Page 8: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/8.jpg)
Chap 8 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
![Page 9: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/9.jpg)
Chap 8 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.
![Page 10: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/10.jpg)
Chap 8 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.
![Page 11: Chap 8 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](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f305503460f94c4b6e7/html5/thumbnails/11.jpg)
Chap 8 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 algorithmEx2. Kruskal’s algorithmEx3.