cmps 2433 discrete structures chapter 5 - trees midwestern state university
TRANSCRIPT
![Page 1: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/1.jpg)
CMPS 2433 Discrete StructuresChapter 5 - Trees MIDWESTERN STATE UNIVERSITY
![Page 2: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/2.jpg)
Basic TreeTree: Connected graph with no cyclesTheorem 5.1: Let U & V be vertices in a tree. Then there is exactly one simple path between U & V.• Since connected, there exists at least one path• If 2, then there must be a cycle (discussion pg. 231)
![Page 3: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/3.jpg)
More Tree Theorems• 5.2: In a tree with more than 1 vertex, there are at
least 2 vertices of degree 1.• 5.3: A tree with n vertices has exactly n-1 edges.
(Proof by induction – p. 232)• 5.4a: If an edge is removed from a tree, the
resulting graph is not connected (so not a tree)• 5.4b: If an edge is added to a tree, the result is a
cycle (so not a tree)
![Page 4: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/4.jpg)
Theorem 5.5:Following statements are equivalent for a graph T
a) T is a treeb) T is connected & V = E+1c) T has 0 cycles & V = E+1d) There is exactly 1 simple path between any 2 verticese) T is connected & removal of any edge results in graph that is not
connectedf) T has no cycles & addition of edge between 2 non-adjacent
vertices results in a cycle
![Page 5: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/5.jpg)
Homework• Section 5.1 – pages 234-236• Exercises 1 – 18, 27
![Page 6: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/6.jpg)
Example 5.2 – page 229• Build telephone network among a group towns
using fewest lines possible; connections do not have to be direct, just connected
• Consider 5 towns• Fully connected• Tree
• See also Example 5.6 – p. 238 – Oil Pipeline
![Page 7: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/7.jpg)
Spanning Tree• Spanning tree of a graph G is a tree (connected
graph with no cycles) containing all vertices of G• May not be unique• Note: A tree is a spanning tree.• How? Remove 1 edge from each cycle.• How do you find the cycles?
![Page 8: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/8.jpg)
Breadth First Search Algorithm
• Using from previous chapter• Edges connecting vertex to its predecessor forms a
tree• Can start at any vertex• Produces Shortest Paths Tree
![Page 9: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/9.jpg)
Theorem 5.6• A graph is connected iff it has a spanning tree.
![Page 10: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/10.jpg)
Minimal & Maximal Spanning Trees• Applies to Weighted Graphs• Minimal Spanning Tree • No other spanning tree of the graph has smaller weight• May be multiple with same weight• Figure 5.15 – pg. 242
![Page 11: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/11.jpg)
Minimal Spanning Tree - Prim’s Algorithm• Select any vertex, V1• Select smallest edge incident on V1• Now, some V2 is also included in selection• Select smallest edge with 1 end a selected vertex &
other end not selected vertex• Repeat until all vertices are included
![Page 12: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/12.jpg)
Prim’s Algorithm• Complexity O(n3) – n = number vertices• Maximal Spanning Tree?? How can we do this?
![Page 13: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/13.jpg)
Kruskal’s Minimal Spanning Tree Alg. (p. 252)• Start with all vertices in separate sets• Select smallest edge; the 2 vertex endpoints have been
selected; Union the sets containing the 2 vertices• Select smallest edge for which 2 endpoints are NOT in
same set• Repeat until all vertices are in one setHow is this different from Prim’s?
![Page 14: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/14.jpg)
Homework• Section 5.2 – Pages 248 – 253• Exercises 1 – 43 (except 12, 13, 36, 37)
![Page 15: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/15.jpg)
Section 5.3 – Depth-First Search
• OMIT
![Page 16: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/16.jpg)
5.4 Rooted Trees• Example: Family Tree• Rooted Tree: a directed graph T such that
1. If ignore direction of edges, graph is a tree2. There exists unique vertex R with in-degree 0, in-degree
of all other V is 1 (R is called the Root)
• Usually draw with Root at top & other edges going down
![Page 17: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/17.jpg)
Theorem 5.9In a rooted tree:1. V = E + 12. No Directed Cycles3. Unique simple directed path from root to all other
Vertices
![Page 18: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/18.jpg)
Tree Terminology (page 268)
• Parent • Child• Ancestor • Descendant• Terminal Vertex – Leaf• Internal Vertex
![Page 19: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/19.jpg)
Section 5.4 Homework• Omit Pages 269 – 270• Exercises Pages 271-274• 1 – 12, 14, 20 – 25, 33 – 38
![Page 20: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/20.jpg)
5.5 Binary Trees & Traversals• A rooted tree in which each vertex has at most 2
children, denoted left child & right child• Left subtree of V: subtree rooted by left child of V• Right subtree
![Page 21: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/21.jpg)
5.6 Binary Search Tree (BST) (p.296)
Consider – each vertex has a value.BST: For every vertex, all vertices in left subtree have greater value that root and all vertices in right subtree have values less than root.
![Page 22: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/22.jpg)
Insertion to a Binary Search Tree (p. 298)
![Page 23: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/23.jpg)
BST Traversals• Inorder Traversal (p.282)• Preorder Traversal (p. 277)• Postorder Traversal (p. 281)
![Page 24: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/24.jpg)
Searching a BST (p. 300)
![Page 25: CMPS 2433 Discrete Structures Chapter 5 - Trees MIDWESTERN STATE UNIVERSITY](https://reader036.vdocuments.us/reader036/viewer/2022062805/5697bfa71a28abf838c990ab/html5/thumbnails/25.jpg)
Homework – 5.5 & 5.6• 5.5: pages 284+• Exercises 7 – 30, 55 – 64
• 5.6: pages 302+• Exercises 48 – 73, demonstrate 74 with 2 different BST’s