CSE 21 Mathematics for Algorithm and System Analysis

Similar documents
Foundations of Discrete Mathematics

Graph Algorithms Using Depth First Search

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Spanning Trees. Lecture 20 CS2110 Spring 2015

Notation Index. Probability notation. (there exists) (such that) Fn-4 B n (Bell numbers) CL-27 s t (equivalence relation) GT-5.

Graph and Digraph Glossary

Math 485, Graph Theory: Homework #3

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Discrete mathematics

EE 368. Weeks 5 (Notes)

Undirected Graphs. Hwansoo Han

Trees Algorhyme by Radia Perlman

Answers to specimen paper questions. Most of the answers below go into rather more detail than is really needed. Please let me know of any mistakes.

Warm Up. Use Kruskal s algorithm to find the minimum spanning tree and it s weight.

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

Notation Index 9 (there exists) Fn-4 8 (for all) Fn-4 3 (such that) Fn-4 B n (Bell numbers) CL-25 s ο t (equivalence relation) GT-4 n k (binomial coef

6c Lecture 3 & 4: April 8 & 10, 2014

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Chapter 2 Graphs. 2.1 Definition of Graphs

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

Discrete mathematics II. - Graphs

18 Spanning Tree Algorithms

K 4 C 5. Figure 4.5: Some well known family of graphs

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

Lower Bound on Comparison-based Sorting

Lecture 4: Walks, Trails, Paths and Connectivity

In this lecture, we ll look at applications of duality to three problems:

What is a minimal spanning tree (MST) and how to find one

Major Themes. Trees. Types of Graphs. Which of the following are trees? G 3 G 1 G 2 G 4. Dr Papalaskari 1

Treewidth and graph minors

Disjoint Sets. The obvious data structure for disjoint sets looks like this.

LECTURE 26 PRIM S ALGORITHM

CSC 373: Algorithm Design and Analysis Lecture 4

Introduction to Optimization

License. Discrete Mathematics. Tree. Topics. Definition tree: connected graph with no cycle. examples. c T. Uyar, A. Yayımlı, E.

March 20/2003 Jayakanth Srinivasan,

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

We ve done. Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding

Optimization I : Brute force and Greedy strategy

Trees Rooted Trees Spanning trees and Shortest Paths. 12. Graphs and Trees 2. Aaron Tan November 2017

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

CSE 100: GRAPH ALGORITHMS

A generalization of Mader s theorem

Let G = (V, E) be a graph. If u, v V, then u is adjacent to v if {u, v} E. We also use the notation u v to denote that u is adjacent to v.

Lecture 8: PATHS, CYCLES AND CONNECTEDNESS

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

MAL 376: Graph Algorithms I Semester Lecture 1: July 24

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Spanning Trees. Lecture 22 CS2110 Spring 2017

Minimal Spanning Trees

Minimum spanning trees

Lecture 8: The Traveling Salesman Problem

Trees. CSC 1300 Discrete Structures Villanova University

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

HW Graph Theory SOLUTIONS (hbovik) - Q

2. Lecture notes on non-bipartite matching

Topics on Computing and Mathematical Sciences I Graph Theory (3) Trees and Matchings I

Minimum Spanning Trees My T. UF

INTRODUCTION TO GRAPH THEORY. 1. Definitions

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Assignment 5: Solutions

implementing the breadth-first search algorithm implementing the depth-first search algorithm

Lecture 4: September 11, 2003

8 Colouring Planar Graphs

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Hamilton paths & circuits. Gray codes. Hamilton Circuits. Planar Graphs. Hamilton circuits. 10 Nov 2015

Fixed-Parameter Algorithms, IA166

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

Fundamental Properties of Graphs

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

11.9 Connectivity Connected Components. mcs 2015/5/18 1:43 page 419 #427

Minimum Spanning Trees

Solutions to Exercises 9

Graphs (MTAT , 6 EAP) Lectures: Mon 14-16, hall 404 Exercises: Wed 14-16, hall 402

Notes on Binary Dumbbell Trees

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

Chapter 3 Trees. Theorem A graph T is a tree if, and only if, every two distinct vertices of T are joined by a unique path.

Combinatorics Summary Sheet for Exam 1 Material 2019

TA: Jade Cheng ICS 241 Recitation Lecture Notes #12 November 13, 2009

Minimum cost spanning tree

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

A note on Baker s algorithm

CSE 638: Advanced Algorithms. Lectures 10 & 11 ( Parallel Connected Components )

University of Toronto Department of Mathematics

Lecture notes on: Maximum matching in bipartite and non-bipartite graphs (Draft)

The minimum cost spanning tree problem

Math 15 - Spring Homework 2.6 Solutions 1. (2.6 # 20) The following graph has 45 vertices. In Sagemath, we can define it like so:

Info 2950, Lecture 16

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Graph Theory CS/Math231 Discrete Mathematics Spring2015

Lecture 20 : Trees DRAFT

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Lecture 19 Thursday, March 29. Examples of isomorphic, and non-isomorphic graphs will be given in class.

Transcription:

CSE 21 Mathematics for Algorithm and System Analysis Unit 4: Basic Concepts in Graph Theory Section 3: Trees 1

Review : Decision Tree (DT-Section 1) Root of the decision tree on the left: 1 Leaves of the decision tree: 4, 5, 8, 9, 10, 11, 7 Child and parent in the decision tree 4 and 5 are children of 2 2 is the parent of 4 and 5 CSE21: Lecture 15 2

Review : Circuit and Cycle Let G = (V, E, φ) be a graph and let e 1, e 2,..., e n be a trail with vertex sequence a 1, a 2,..., a n, a 1. (namely returns to its starting point.) The subgraph G of G induced by the set of edges {e 1, e 2,..., e n } is called a circuit of G. If the only repeated vertices on the trail are a 1 (the start and end), then the circuit is called a simple circuit or cycle. Both circuit and cycle are graphs, not just edge sequences. A graph with loop is a cycle. CSE21: Lecture 13 3

Review : Connected Graph and Components Let G = (V, E, φ) be a graph. If for any two distinct elements u and v of V there is a path P from u to v then G is a connected graph. For a graph G = (V, E, φ), the vertex set is partitioned into subsets V 1,V 2,...,V m such that if u and v are in the same subset then there is a path from u to v and if they are in different subsets there is no such path. The subgraphs G 1 = (V 1, E 1, φ 1 ),..., G m = (V m, E m, φ m ) induced by the sets V 1,V 2,...,V m are called the connected components of G. An example of a graph with two connected components: CSE21: Lecture 13 4

Learning Outcomes By the end of this lesson, you should be able to Get possible relationships between vertex number, edge number and component number of a graph. Use the algorithms to get minimum weight spanning tree for a connected graph. 5

Why do we need to learn them? Tree structure is an important data structure type in computer science. Decision tree is a special kind of tree. We can use tree structure to describe hierarchy Organization chart Ancestry (family tree) 6

Definition 13 : Tree If G is a connected graph without any cycles, then G is called a tree. If V = 1, then G is connected and hence is a tree. Example The graph on the right is connected but is not a tree, because it has many cycles, including G = ({A, B, C}, {a, e, c}). The subgraph of this graph induced by the edges {a, e, g} is a tree. If G is a tree, then φ is an injection. If e 1 e 2 and φ(e 1 ) = φ(e 2 ), then {e 1, e 2 } induces a cycle. 7

Theorem 4 : Alternative definitions of a tree If G is a connected graph, the following are equivalent. (a) G is a tree. (b) G has no cycles. (c) For every pair of vertices u v in G, there is exactly one path from u to v. (d) Removing any edge from G gives a graph which is not connected. (e) The number of vertices of G is one more than the number of edges of G. 8

Definition 14 : Forest A forest is a graph all of whose connected components are trees. In particular, a forest with one component is a tree. Example: The forest has two trees. a b c d h i e f g 9

Example 15 : A relation for forests Suppose a forest has v vertices, e edges and c (connected) components. Question: What values are possible for the triple of numbers (v, e, c)? Let the forest consist of trees T 1,..., T c and let the triples for T i be (v i, e i, c i ). Since a tree is connected, c i = 1. By Theorem 4, e i = v i 1. Since v=v 1 + +v c and e=e 1 + +e c, e = (v 1 1)+(v 2 1)+ +(v c 1) = (v 1 + +v c ) c = v c. Example: Suppose a forest has e = 12 and v = 15. It must be made up of 3 trees because c = v e = 15 12. 10

Example 15 : A relation for forests (2) A graph G = (V, E, φ) has v = 15 and c = 3, what is the minimal edge number it could have? For each component of G, remove edges one by one until we cannot remove any more without breaking the component into two components. At this point, we are left with each component a tree. Now we get a forest of c = 3 trees that still has v = 15 vertices. Because v c = e, this forest has 12 edges. Since we may have removed edges from the original graph to get to this forest, the original graph has at least 12 edges. 11

Example 15 : A relation for forests (3) A simple graph G = (V, E, φ) has v = 15 and c = 3, what is the maximal edge number it could have? If c is not specified, the edges in a simple graph are a subset of P 2 (V) which has C(v, 2) elements, so the a simple graph with v vertices has at most C(v, 2) edges. If c is specified, we need get vertex number for each component. The maximum occurs when one of v i is as large as possible and the others equal 1. We only need to count the edge number for the v i because edge number for others are 0. The result for this example is C(13, 2) = (13 12)/(2 1). 12

Example 15 : A relation for forests (4) Suppose a graph has v vertices, e edges and c (connected) components. There is no graph G = (V, E, φ) with v c > e. If v c = e, the graph is a forest of c trees. If v c < e, there are many graphs, but none of them are forests. If v c < e and the graph is a simple graph, then e C(v+1 c, 2). If v c < e and the graph is a simple graph with loops, then e C(v+1 c, 2) + v. If v c < e and the graph is a graph, then there is no upper bound for e, namely e can be any large number. 13

Definition 15 and 16 : Rooted graph, parent, child, sibling and leaf A pair (G, v), consisting of a graph G = (V, E, φ) and a specified vertex v, is called a rooted graph with root v. Let (T, r) be a rooted tree. If w is any vertex other than r, let r = v 0, v 1,..., v k, v k+1 = w, be the list of vertices on the unique path from r to w. We call v k the parent of w and call w a child of v k. Parents and children are also called fathers and sons. Vertices with the same parent are siblings. A vertex with no children is a leaf. All other vertices are internal vertices of the tree. 14

Examples of rooted graph, parent, child, sibling and leaf The graph on the right is a rooted graph with root a, also a rooted tree with root a. a, c, f is the unique path from root a to vertex f. So c is the parent of f and f is a child of c. Similarly, we know both e and g are children of c. So e, f, g are siblings. b has no children, so b is a leaf. a, c are internal vertices of the tree. g d f c e b a 15

Definition 17 : Rooted plane tree Let (T, r) be a rooted tree. For each vertex, order the children of the vertex. The result is a rooted plane tree, which we abbreviate to RP-tree. RP-trees are also called ordered trees. An RP-tree is also called, in certain contexts, a decision tree. So we can traverse a RP-tree by depthfirst and breadth-first search. Almost all trees in computer science are rooted and plane, so computer scientists usually call a rooted plane tree simply a tree. 16

Example 16 : A rooted plane tree A rooted plane tree T = (V, E, φ) where V = 11 and E = {a,..., j} and φ s definition is in the picture. The vertex 6 is the parent of the vertex 9. The vertices 8, 9, 10, and 11 are the children of 6 and, they are siblings of each other. The leaves of the tree are 4, 5, 7, 8, 9, 10, 11. All other vertices (including the root) are internal vertices of the tree. If we change the order of the children of a vertex, it is still the same graph and tree, but becomes a different RP-tree. 17

Definition 18 : Spanning tree A spanning tree of a (simple) graph G = (V, E) is a subgraph T = (V, E ) which is a tree and has the same set of vertices as G. Example The left graph is a spanning tree of the right graph. c c d e d e A graph is connected if and only if it has a spanning tree. 18

Definition 19 : Weights in a graph Let G = (V, E) be a simple graph and let λ be a function from E to the positive real numbers. We call λ(e) the weight of the edge e. If H = (V, E ) is a subgraph of G, then λ(h), the weight of H, is the sum of λ(e ) over all e E. A minimum weight spanning tree for a connected graph G is a spanning tree such that λ(t) λ(t ) whenever T is another spanning tree. Example Weight of each edge is shown on the right graph. The tree on the left is a minimum weight spanning tree for the graph. d c e d c 1 1 3 e 19

Theorem 5 : Minimum weight spanning tree - Prim s algorithm Let G = (V, E) be a simple graph with edge weights given by λ. If the algorithm stops with V V, G has no spanning tree; otherwise, (V, E ) is a minimum weight spanning tree for G. 1. Start: Let E = and let V ={v 0 } where v 0 is any vertex in V. 2. Possible Edges: Let F Ebe those edges f = {x, y} with one vertex in V and one vertex not in V. If F =, stop. 3. Choose Edge Greedily: Let f = {x, y} be such that λ(f) is a minimum over all f F. Replace V with V {x, y} and E with E {f}. Go to Step 2. 20

Theorem 5 : Minimum weight spanning tree - Prim s algorithm (2) Applying Prim s algorithm for the graph, the changes of E, V and F are: 1. E =, V = {c}, F = {{c, d}, {c, e}} 2. E = {{c, d}}, V = {c, d}, F = {{d, e}, {c, e}} 3. E = {{c, d}, {c, e}}, V = {c, d, e}, F = No matter which vertex to start, this algorithm can guarantee the generated spanning tree has minimum weight. A graph could have multiple minimum weight spanning trees. If λ({d, e}) =1, both G = ({c, d, e}, {{c, d}, {c, e}}) and G = ({c, d, e}, {{c, d}, {d, e}}) have minimum weight. d c 1 1 3 e 21

Variation of Theorem 5 - Kruskal s algorithm In Kruskal s algorithm, step 2 of Prim s algorithm is changed to: 2. Possible Edges: Let F Ebe those edges f = {x, y} where x and y do not belong to the same (connected) component of (V, E ). If F =, stop. The step also means f Fif f forms a cycle with any collection of edges from E. Otherwise, f F. Its difference from Prim s algorithm is that f doesn t have to have a vertex in V (more freedom to choose f). So F in Prim s algorithm is a subset of F in this algorithm. 22

Variation of Theorem 5 - Kruskal s algorithm (2) For Prim s algorithm, the first a few changes of E, V a and F are: 1. E =, V = {a}, F = {{a, b}, {a, d}} 2. E = {{a, b}}, V = {a, b}, F = {{b, c}, {a, d}} 3. For Kruskal s algorithm, the first a few changes of E, V and F are: 1. E =, V = {a}, F = {{a, b}, {a, d}, {b, c}, {c, d}} 2. E = {{b, c}}, V = {a, b, c}, F = {{a, b}, {a, d}, {c, d}} 3. b 1 1 c 2 2 d 23

Homework and Pre-Reading Assignment Homework: Exercise 3.2, 3.3, 3.5, 3.6, 3.7, in page GT-35 to GT- 36. For next class, please finish reading Section 3 and the first a few pages of Section 4 (GT-33 to GT-41). Try to understand the algorithm to get lineal spanning trees from a graph. Try to understand the meanings of Θ and O, and how we can use them to describe time complexities of algorithms. 24