Minimum Spanning Trees Ch 23 Traversing graphs
|
|
- Myles Stokes
- 6 years ago
- Views:
Transcription
1 Net: Graph Algorithms Graphs Ch 22 Graph representations adjacenc list adjacenc matri Minimum Spanning Trees Ch 23 Traersing graphs Breadth-First Search Depth-First Search 7/16/2013 CSE
2 Graphs Definition A graph G = (V,E) is composed of: V: set of ertices E V V: set of edges connecting the ertices An edge e = (u,) is a pair of ertices (u,) is ordered, if G is a directed graph 7/16/2013 CSE
3 Graph Terminolog adjacent ertices: connected b an edge degree (of a erte): # of adjacent ertices V deg( ) = 2(# of edges) Since adjacent ertices each count the adjoining edge, it will be counted twice path: sequence of ertices 1, 2,... k such that consecutie ertices i and i+1 are adjacent 7/16/2013 CSE
4 Graph Terminolog (2) simple path: no repeated ertices 7/16/2013 CSE
5 Graph Terminolog (3) ccle: simple path, ecept that the last erte is the same as the first erte connected graph: an two ertices are connected b some path 7/16/2013 CSE
6 Graph Terminolog (4) subgraph: subset of ertices and edges forming a graph connected component: maimal connected subgraph. E.g., the graph below has 3 connected components 7/16/2013 CSE
7 Graph Terminolog (5) (free) tree - connected graph without ccles forest - collection of trees 7/16/2013 CSE
8 Data Structures for Graphs The Adjacenc list of a erte : a sequence of ertices adjacent to Represent the graph b the adjacenc lists of all its ertices Space =Θ ( n+ deg( )) =Θ ( n+ m) 7/16/2013 CSE
9 Data Structures for Graphs Adjacenc matri Matri M with entries for all pairs of ertices M[i,j] = true there is an edge (i,j) in the graph M[i,j] = false there is no edge (i,j) in the graph Space = O(n 2 ) 7/16/2013 CSE
10 Spanning Tree A spanning tree of G is a subgraph which is a tree contains all ertices of G 7/16/2013 CSE
11 Minimum Spanning Trees Undirected, connected graph G = (V,E) Weight function W: E R (assigning cost or length or other alues to edges) Spanning tree: tree that connects all ertices Minimum spanning tree: tree that connects all the ertices and minimizes wt ( ) = wu (, ) ( u, ) T 7/16/2013 CSE
12 Optimal Substructure MST T T 2 T 1 Remoing the edge (u,) partitions T into T 1 and T 2 wt ( ) = wu (, ) + wt ( ) + wt ( ) 1 2 We claim that T 1 is the MST of G 1 =(V 1,E 1 ), the subgraph of G induced b ertices in T 1 Also, T 2 is the MST of G 2 7/16/2013 CSE
13 Greed Choice Greed choice propert: locall optimal (greed) choice ields a globall optimal solution Theorem Let G=(V, E), and let S V and let(u,) be min-weight edge in G connecting S to V S Then (u,) T somemstof G 7/16/2013 CSE
14 Proof Greed Choice (2) suppose (u,) T look at path from u to in T swap(, ) the first edge on path from u to in T that crosses from S to V S this improes T contradiction (T supposed to be MST) S V-S u 7/16/2013 CSE
15 Generic MST Algorithm Generic-MST(G, w) w) 1 A // // Contains edges that belong to to a MST MST 2 while A does not not form a spanning tree do do 3 Find an an edge (u,) that is is safe for for A 4 A A {(u,)} 5 return A Safe edge edge that does not destro A s propert MoreSpecific-MST(G, w) w) 1 A // // Contains edges that belong to to a MST MST 2 while A does not not form a spanning tree do do Make a cut cut (S, (S, V-S) of of G that respects A Take the the min-weight edge (u,) connecting S to to V-S V-S 4 A A {(u,)} 5 return A 7/16/2013 CSE
16 Prim s Algorithm Verte based algorithm Grows one tree T, one erte at a time A cloud coering the portion of T alread computed Label the ertices outside the cloud with ke[] the minimum weight of an edge connecting to a erte in the cloud, ke[] =, if no such edge eists 7/16/2013 CSE
17 Prim s Algorithm (2) MST-Prim(G,w,r) 01 Q V[G] // Q ertices out of T 02 for each u Q 03 ke[u] 04 ke[r] 0 05 π[r] NIL 06 while Q do 07 u EtractMin(Q) // making u part of T 08 for each Adj[u] do 09 if Q and w(u,) < ke[] then 10 π[] u 11 ke[] w(u,) updating kes 7/16/2013 CSE
18 Prim Eample 7/16/2013 CSE
19 Prim Eample (2) 7/16/2013 CSE
20 Prim Eample (3) 7/16/2013 CSE
21 Priorit Queues A priorit queue is a data structure for maintaining a set S of elements, each with an associated alue called ke We need PQ to support the following operations BuildPQ(S) initializes PQ to contain elements of S EtractMin(S) returns and remoes the element of S with the smallest ke ModifKe(S,,newke) changes the ke of in S A binar heap can be used to implement a PQ BuildPQ O(n) EtractMin and ModifKe O(lg n) 7/16/2013 CSE
22 Prim s Running Time Time = V T(EtractMin) + O( E )T(ModifKe) Time = O( V lg V + E lg V ) = O( E lg V ) Q T(EtractMin) T(DecreaseKe) Total arra O( V ) O(1) O( V 2 ) binar heap O(lg V ) O(lg V ) O( E lg V ) Fibonacci heap O(lg V ) O(1) amortized O( V lg V + E ) 7/16/2013 CSE
23 Kruskal's Algorithm Edge based algorithm Add the edges one at a time, in increasing weight order The algorithm maintains A a forest of trees. An edge is accepted it if connects ertices of distinct trees We need an ADT that maintains a partition, i.e.,a collection of disjoint sets MakeSet(S,): S S {{}} Union(S i,s j ): S S {S i,s j } {S i S j } FindSet(S, ): returns unique S i S, where S i 7/16/2013 CSE
24 Kruskal's Algorithm The algorithm keeps adding the cheapest edge that connects two trees of the forest MST-Kruskal(G,w) 01 A 02 for each erte V[G] do 03 Make-Set() 04 sort the edges of E b non-decreasing weight w 05 for each edge (u,) E, in order b nondecreasing weight do 06 if Find-Set(u) Find-Set() then 07 A A {(u,)} 08 Union(u,) 09 return A 7/16/2013 CSE
25 Kruskal's Algorithm: eample 7/16/2013 CSE
26 Kruskal's Algorithm: eample (2) 7/16/2013 CSE
27 Kruskal's Algorithm: eample (3) 7/16/2013 CSE
28 Kruskal's Algorithm: eample (4) 7/16/2013 CSE
29 Kruskal running time Initialization O( V ) time Sorting the edges Θ( E lg E ) = Θ( E lg V ) (wh?) O( E ) calls to FindSet Union costs Let t() the number of times is moed to a new cluster Each time a erte is moed to a new cluster the size of the cluster containing the erte at least doubles: t() log V Total time spent doing Union t () Vlog V Total time: O( E lg V ) V 7/16/2013 CSE
30 Net: Graph Algorithms Graphs Graph representations adjacenc list adjacenc matri Traersing graphs Breadth-First Search Depth-First Search 7/16/2013 CSE
31 Graph Searching Algorithms Sstematic search of eer edge and erte of the graph Graph G = (V,E) is either directed or undirected Toda's algorithms assume an adjacenc list representation Applications Compilers Graphics Maze-soling Mapping Networks: routing, searching, clustering, etc. 7/16/2013 CSE
32 Breadth First Search A Breadth-First Search (BFS) traerses a connected component of a graph, and in doing so defines a spanning tree with seeral useful properties BFS in an undirected graph G is like wandering in a labrinth with a string. The starting erte s, it is assigned a distance 0. In the first round, the string is unrolled the length of one edge, and all of the edges that are onl one edge awa from the anchor are isited (discoered), and assigned distances of 1 7/16/2013 CSE
33 Breadth First Search (2) In the second round, all the new edges that can be reached b unrolling the string 2 edges are isited and assigned a distance of 2 This continues until eer erte has been assigned a leel The label of an erte corresponds to the length of the shortest path (in terms of edges) from s to 7/16/2013 CSE
34 7/16/2013 CSE Breadth First Search: eample 0 r s u t w 0 s Q r s u t w 1 w 1 r Q r s u t 2 w 2 t 1 r 2 Q r s u t 2 w 2 2 t 2 Q
35 7/16/2013 CSE Breadth First Search: eample r s u 3 t 2 w u Q r s u 3 t 2 w 3 u 2 3 Q r s u 3 t 2 w 3 3 u Q r s u 3 t 2 w 3 Q
36 Breadth First Search: eample r s t u w Q - 7/16/2013 CSE
37 BFS Algorithm BFS(G,s) 01 for each erte u V[G]-{s} 02 color[u] white 03 d[u] 04 π[u] NIL 05 color[s] gra 06 d[s] 0 07 π[u] NIL 08 Q {s} 09 while Q do 10 u head[q] 11 for each Adj[u] do 12 if color[] = white then 13 color[] gra 14 d[] d[u] π[] u 16 Enqueue(Q,) 17 Dequeue(Q) 18 color[u] black Init all ertices Init BFS with s Handle all u s children before handling an children of children 7/16/2013 CSE
38 BFS Algorithm: running time Gien a graph G = (V,E) Vertices are enqueued if there color is white Assuming that en- and dequeuing takes O(1) time the total cost of this operation is O( V ) Adjacenc list of a erte is scanned when the erte is dequeued (and onl then ) The sum of the lengths of all lists is O( E ). Consequentl, O( E ) time is spent on scanning them Initializing the algorithm takes O( V ) Total running time O( V + E ) (linear in the size of the adjacenc list representation of G) 7/16/2013 CSE
39 BFS Algorithm: properties Gien a graph G = (V,E), BFS discoers all ertices reachable from a source erte s It computes the shortest distance to all reachable ertices It computes a breadth-first tree that contains all such reachable ertices For an erte reachable from s, the path in the breadth first tree from s to, corresponds to a shortest path in G 7/16/2013 CSE
40 BFS Tree Predecessor subgraph of G G = ( V, E ) π π π { : [ ] } { } {( [ ], ) : {}} V = V π NIL s π E = π E V s π G p is a breadth-first tree V p consists of the ertices reachable from s, and for all V p, there is a unique simple path from s to in G p that is also a shortest path from s to in G The edges in G p are called tree edges π 7/16/2013 CSE
41 Depth-first search (DFS) A depth-first search (DFS) in an undirected graph G is like wandering in a labrinth with a string and a can of paint We start at erte s, ting the end of our string to the point and painting s isited (discoered). Net we label s as our current erte called u Now, we trael along an arbitrar edge (u,). If edge (u,) leads us to an alread isited erte we return to u If erte is unisited, we unroll our string, moe to, paint isited, set as our current erte, and repeat the preious steps 7/16/2013 CSE
42 Depth-first search (2) Eentuall, we will get to a point where all incident edges on u lead to isited ertices We then backtrack b unrolling our string to a preiousl isited erte. Then becomes our current erte and we repeat the preious steps Then, if all incident edges on lead to isited ertices, we backtrack as we did before. We continue to backtrack along the path we hae traeled, finding and eploring uneplored edges, and repeating the procedure 7/16/2013 CSE
43 Depth-first search algorithm Initialize color all ertices white Visit each and eer white erte using DFS- Visit Each call to DFS-Visit(u) roots a new tree of the depth-first forest at erte u A erte is white if it is undiscoered A erte is gra if it has been discoered but not all of its edges hae been discoered A erte is black after all of its adjacent ertices hae been discoered (the adj. list was eamined completel) 7/16/2013 CSE
44 Depth-first search algorithm (2) Init all ertices Visit all children recursiel 7/16/2013 CSE
45 Depth-first search eample u 1/ w u 1/ 2/ w u 1/ 2/ w z z 3/ z u w u w u w 1/ 2/ 1/ 2/ B 1/ 2/ B 4/ 3/ z 4/ 3/ z 4/5 3/ z 7/16/2013 CSE
46 Depth-first search eample (2) u w u w u w 1/ 2/ B 4/5 3/6 z 1/ 2/7 B 4/5 3/6 z 1/ 2/7 F B 4/5 3/6 z u w u w u w 1/8 2/7 F B 4/5 3/6 z 1/8 2/7 F B 4/5 3/6 9/ z 1/8 2/7 F B 4/5 3/6 C 9/ z 7/16/2013 CSE
47 Depth-first search eample (3) u w u w u w 1/8 2/7 F B 4/5 3/6 C 9/ 10/ z 1/8 2/7 F B 4/5 3/6 C 9/ 10/ B z 1/8 2/7 F B 4/5 3/6 C 9/ 10/11 B z u w 1/8 2/7 F B 4/5 3/6 C 9/12 10/11 B z 7/16/2013 CSE
48 Depth-first search eample (4) When DFS returns, eer erte u is assigned a discoer time d[u], and a finishing time f[u] Running time the loops in DFS take time Θ(V) each, ecluding the time to eecute DFS-Visit DFS-Visit is called once for eer erte its onl inoked on white ertices, and paints the erte gra immediatel for each DFS-isit a loop interates oer all Adj[] the total cost for DFS-Visit is Θ(E) the running time of DFS is Θ(V+E) Adj[] =Θ( E) 7/16/2013 CSE V
49 Predecessor Subgraph Defined slightl different from BFS G π {( [ ], ) : and [ ] NIL} E = π E V π π = ( V, E ) π The PD subgraph of a depth-first search forms a depth-first forest composed of seeral depth-first trees The edges in G p are called tree edges 7/16/2013 CSE
50 DFS Timestamping The DFS algorithm maintains a monotonicall increasing global clock discoer time d[u] and finishing time f[u] For eer erte u, the inequalit d[u] < f[u] must hold 7/16/2013 CSE
51 Verte u is DFS Timestamping white before time d[u] gra between time d[u] and time f[u], and black thereafter Notice the structure througout the algorithm. gra ertices form a linear chain correponds to a stack of ertices that hae not been ehaustiel eplored (DFS-Visit started but not et finished) 7/16/2013 CSE
52 DFS Parenthesis Theorem Discoer and finish times hae parenthesis structure represent discoer of u with left parenthesis "(u" represent finishin of u with right parenthesis "u)" histor of discoeries and finishings makes a wellformed epression (parenthesis are properl nested) Intuition for proof: an two interals are either disjoint or enclosed Oerlaping interals would mean finishing ancestor, before finishing descendant or starting descendant without starting ancestor 7/16/2013 CSE
Minimum Spanning Trees Ch 23 Traversing graphs
Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs
More informationElementary Graph Algorithms
Elementary Graph Algorithms Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) Types of graphs» Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.)» Directed: (u, v)
More informationData Structures and Algorithms. Werner Nutt
Data Structures and Algorithms Werner Nutt nutt@inf.unibz.it http://www.inf.unibz/it/~nutt Part 9 Academic Year 2011-2012 1 Acknowledgements & Copyright Notice These slides are built on top of slides developed
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 18 Graph Algorithm Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Graphs Graph G = (V,
More informationLecture 10. Elementary Graph Algorithm Minimum Spanning Trees
Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo
More informationGraphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)
Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from
More informationRepresentations of Graphs
ELEMENTARY GRAPH ALGORITHMS -- CS-5321 Presentation -- I am Nishit Kapadia Representations of Graphs There are two standard ways: A collection of adjacency lists - they provide a compact way to represent
More informationData Structures and Algorithms. Chapter 7. Graphs
1 Data Structures and Algorithms Chapter 7 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples
More informationIntroduction to Algorithms. Lecture 11
Introduction to Algorithms Lecture 11 Last Time Optimization Problems Greedy Algorithms Graph Representation & Algorithms Minimum Spanning Tree Prim s Algorithm Kruskal s Algorithm 2 Today s Topics Shortest
More informationGraph Representation
Graph Representation Adjacency list representation of G = (V, E) An array of V lists, one for each vertex in V Each list Adj[u] contains all the vertices v such that there is an edge between u and v Adj[u]
More informationECE250: Algorithms and Data Structures Elementary Graph Algorithms Part B
ECE250: Algorithms and Data Structures Elementary Graph Algorithms Part B Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp.
More informationGreedy Algorithms. At each step in the algorithm, one of several choices can be made.
Greedy Algorithms At each step in the algorithm, one of several choices can be made. Greedy Strategy: make the choice that is the best at the moment. After making a choice, we are left with one subproblem
More informationPart VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths
Part VI Graph algorithms Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths 1 Chapter 22 Elementary Graph Algorithms Representations of graphs
More informationChapter 22. Elementary Graph Algorithms
Graph Algorithms - Spring 2011 Set 7. Lecturer: Huilan Chang Reference: (1) Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 2nd Edition, The MIT Press. (2) Lecture notes from C. Y. Chen
More informationOutlines: Graphs Part-2
Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree
More informationUnit 2: Algorithmic Graph Theory
Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw
More informationGraph representation
Graph Algorithms 1 Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent for algorithms: 1. Adjacency lists. 2. Adjacency matrix. When expressing
More informationMinimum Spanning Trees
Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no
More informationGraph Algorithms. Definition
Graph Algorithms Many problems in CS can be modeled as graph problems. Algorithms for solving graph problems are fundamental to the field of algorithm design. Definition A graph G = (V, E) consists of
More informationGraph Search. Adnan Aziz
Graph Search Adnan Aziz Based on CLRS, Ch 22. Recall encountered graphs several weeks ago (CLRS B.4) restricted our attention to definitions, terminology, properties Now we ll see how to perform basic
More informationGraph: representation and traversal
Graph: representation and traversal CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang! Acknowledgement The set of slides have use materials from the following resources Slides for textbook
More informationDFS & STRONGLY CONNECTED COMPONENTS
DFS & STRONGLY CONNECTED COMPONENTS CS 4407 Search Tree Breadth-First Search (BFS) Depth-First Search (DFS) Depth-First Search (DFS) u d[u]: when u is discovered f[u]: when searching adj of u is finished
More informationCOT 6405 Introduction to Theory of Algorithms
COT 6405 Introduction to Theory of Algorithms Topic 14. Graph Algorithms 11/7/2016 1 Elementary Graph Algorithms How to represent a graph? Adjacency lists Adjacency matrix How to search a graph? Breadth-first
More informationMinimum Spanning Trees
Minimum Spanning Trees Overview Problem A town has a set of houses and a set of roads. A road connects and only houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and
More informationMinimum Spanning Trees My T. UF
Introduction to Algorithms Minimum Spanning Trees @ UF Problem Find a low cost network connecting a set of locations Any pair of locations are connected There is no cycle Some applications: Communication
More informationMinimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem
Minimum Spanning Trees (Forests) Given an undirected graph G=(V,E) with each edge e having a weight w(e) : Find a subgraph T of G of minimum total weight s.t. every pair of vertices connected in G are
More informationGraph implementations :
Graphs Graph implementations : The two standard ways of representing a graph G = (V, E) are adjacency-matrices and collections of adjacencylists. The adjacency-lists are ideal for sparse trees those where
More informationECE250: Algorithms and Data Structures Elementary Graph Algorithms Part A
ECE250: Algorithms and Data Structures Elementary Graph Algorithms Part A Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp.
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401J LECTURE 13 Graph algorithms Graph representation Minimum spanning trees Greedy algorithms Optimal substructure Greedy choice Prim s greedy MST algorithm Prof.
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 s of s s are abstract data types that are applicable
More informationGraphs. Graphs. Representation of Graphs. CSE 680 Prof. Roger Crawfis. Two standard ways. Graph G = (V, E)» V = set of vertices
Introduction to Algorithms Graph Algorithms CSE 680 Prof. Roger Crawfis Partially from io.uwinnipeg.ca/~ychen2 Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) V) Types of graphs» Undirected:
More informationGraph Algorithms: Chapters Part 1: Introductory graph concepts
UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationMinimum Spanning Trees
Minimum Spanning Trees 1 Minimum- Spanning Trees 1. Concrete example: computer connection. Definition of a Minimum- Spanning Tree Concrete example Imagine: You wish to connect all the computers in an office
More informationGraph: representation and traversal
Graph: representation and traversal CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Acknowledgement The set of slides have use materials from the following resources Slides for textbook
More informationW4231: Analysis of Algorithms
W4231: Analysis of Algorithms 10/21/1999 Definitions for graphs Breadth First Search and Depth First Search Topological Sort. Graphs AgraphG is given by a set of vertices V and a set of edges E. Normally
More informationCOP 4531 Complexity & Analysis of Data Structures & Algorithms
COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 9 Minimum Spanning Trees Thanks to the text authors who contributed to these slides Why Minimum Spanning Trees (MST)? Example 1 A
More informationChapter 23. Minimum Spanning Trees
Chapter 23. Minimum Spanning Trees We are given a connected, weighted, undirected graph G = (V,E;w), where each edge (u,v) E has a non-negative weight (often called length) w(u,v). The Minimum Spanning
More information22 Elementary Graph Algorithms. There are two standard ways to represent a
VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph
More information1 Start with each vertex being its own component. 2 Merge two components into one by choosing the light edge
Taking Stock IE170: in Systems Engineering: Lecture 19 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 16, 2007 Last Time Minimum This Time More Strongly Connected
More informationCS473-Algorithms I. Lecture 14-A. Graph Searching: Breadth-First Search. Cevdet Aykanat - Bilkent University Computer Engineering Department
CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search 1 Graph Searching: Breadth-First Search Graph G =(V, E), directed or undirected with adjacency list repres. GOAL: Systematically explores
More informationLecture Notes for Chapter 23: Minimum Spanning Trees
Lecture Notes for Chapter 23: Minimum Spanning Trees Chapter 23 overview Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has
More informationContext: Weighted, connected, undirected graph, G = (V, E), with w : E R.
Chapter 23: Minimal Spanning Trees. Context: Weighted, connected, undirected graph, G = (V, E), with w : E R. Definition: A selection of edges from T E such that (V, T ) is a tree is called a spanning
More informationTutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].
Tutorial Question 1 A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first tree can also be used to classify the edges reachable from the source
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 05 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction
More information22 Elementary Graph Algorithms. There are two standard ways to represent a
VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph
More informationTaking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 26 Jeff Linderoth Last Time Department of Industrial and Systems Engineering Lehigh University April 2, 2007 This Time Review! Jeff Linderoth
More informationBasic Graph Algorithms
Basic Graph Algorithms 1 Representations of Graphs There are two standard ways to represent a graph G(V, E) where V is the set of vertices and E is the set of edges. adjacency list representation adjacency
More informationCS 270 Algorithms. Oliver Kullmann. Breadth-first search. Analysing BFS. Depth-first. search. Analysing DFS. Dags and topological sorting.
Week 5 General remarks and 2 We consider the simplest graph- algorithm, breadth-first (). We apply to compute shortest paths. Then we consider the second main graph- algorithm, depth-first (). And we consider
More informationWeek 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms.
1 2 Week 5 3 4 5 General remarks We finish, by analysing it. Then we consider the second main graph- algorithm, depth-first (). And we consider one application of, of graphs. Reading from CLRS for week
More informationCHAPTER 23: ELEMENTARY GRAPH ALGORITHMS Representations of graphs
CHAPTER 23: ELEMENTARY GRAPH ALGORITHMS This chapter presents methods for representing a graph and for searching a graph. Searching a graph means systematically following the edges of the graph so as to
More informationDepth-first Search (DFS)
Depth-first Search (DFS) DFS Strategy: First follow one path all the way to its end, before we step back to follow the next path. (u.d and u.f are start/finish time for vertex processing) CH08-320201:
More informationTaking Stock. IE170: Algorithms in Systems Engineering: Lecture 16. Graph Search Algorithms. Recall BFS
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 16 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University February 28, 2007 Last Time The Wonderful World of This
More informationDecreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )
Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 1. if >. 2. error new key is greater than current key 3.. 4.. 5. if NIL and.
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401J LECTURE 16 Greedy Algorithms (and Graphs) Graph representation Minimum spanning trees Optimal substructure Greedy choice Prim s greedy MST algorithm Prof. Charles
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 04 Elementary Graph Algorithms (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction
More informationIntroduction to Algorithms
Introduction to Algorithms, Lecture 1 /1/200 Introduction to Algorithms.04J/1.401J LECTURE 11 Graphs, MST, Greedy, Prim Graph representation Minimum spanning trees Greedy algorithms hallmarks. Greedy choice
More informationReview: Graph Theory and Representation
Review: Graph Theory and Representation Graph Algorithms Graphs and Theorems about Graphs Graph implementation Graph Algorithms Shortest paths Minimum spanning tree What can graphs model? Cost of wiring
More informationCS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.
General remarks Week 5 2 We finish, by analysing it. Then we consider the second main graph- algorithm, depth-first (). And we consider one application of, of graphs. Reading from CLRS for week 5 Chapter
More informationMinimum Spanning Trees
Chapter 23 Minimum Spanning Trees Let G(V, E, ω) be a weighted connected graph. Find out another weighted connected graph T(V, E, ω), E E, such that T has the minimum weight among all such T s. An important
More informationData Structures. Elementary Graph Algorithms BFS, DFS & Topological Sort
Data Structures Elementary Graph Algorithms BFS, DFS & Topological Sort 1 Graphs A graph, G = (V, E), consists of two sets: V is a finite non-empty set of vertices. E is a set of pairs of vertices, called
More informationTaking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search
Taking Stock IE170: Algorithms in Systems Engineering: Lecture 17 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 2, 2007 Last Time Depth-First Search This Time:
More informationWeek 11: Minimum Spanning trees
Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,
More informationSample Solutions to Homework #4
National Taiwan University Handout #25 Department of Electrical Engineering January 02, 207 Algorithms, Fall 206 TA: Zhi-Wen Lin and Yen-Chun Liu Sample Solutions to Homework #4. (0) (a) Both of the answers
More informationGraph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1
Graph Algorithms Chapter 22 CPTR 430 Algorithms Graph Algorithms Why Study Graph Algorithms? Mathematical graphs seem to be relatively specialized and abstract Why spend so much time and effort on algorithms
More informationData Structures and Algorithms. Werner Nutt
Data Structures and Algorithms Werner Nutt nutt@inf.unibz.it http://www.inf.unibz/it/~nutt Chapter 10 Academic Year 2012-2013 1 Acknowledgements & Copyright Notice These slides are built on top of slides
More informationCSI 604 Elementary Graph Algorithms
CSI 604 Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. (Second edition) 1 / 25 Graphs: Basic Definitions Undirected Graph G(V, E): V is set of nodes (or vertices) and E is the
More informationElementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:
Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. Representing a graph: Graph G(V, E): V set of nodes (vertices); E set of edges. Notation: n = V and m = E. (Vertices are numbered
More informationWe ve done. Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding
We ve done Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding Matroid Theory Now Matroids and weighted matroids Generic
More informationCS583 Lecture 09. Jana Kosecka. Graph Algorithms Topological Sort Strongly Connected Component Minimum Spanning Tree
CS3 Lecture 0 Jana Kosecka Graph Algorithms Topological Sort Strongly Connected Component Minimum Spanning Tree Many slides here are based on E. Demaine, D. Luebke, Kleinberg-Tardos slides Graph Algs.
More informationMinimum Spanning Trees Outline: MST
Minimm Spanning Trees Otline: MST Minimm Spanning Tree Generic MST Algorithm Krskal s Algorithm (Edge Based) Prim s Algorithm (Vertex Based) Spanning Tree A spanning tree of G is a sbgraph which is tree
More informationCSE 100 Minimum Spanning Trees Prim s and Kruskal
CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:
More informationCOMP251: Single source shortest paths
COMP51: Single source shortest paths Jérôme Waldispühl School of Computer Science McGill University Based on (Cormen et al., 00) Problem What is the shortest road to go from one city to another? Eample:
More informationWeek 12: Minimum Spanning trees and Shortest Paths
Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601
More informationCS 220: Discrete Structures and their Applications. graphs zybooks chapter 10
CS 220: Discrete Structures and their Applications graphs zybooks chapter 10 directed graphs A collection of vertices and directed edges What can this represent? undirected graphs A collection of vertices
More informationGraphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington
Graphs CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington 1 Representation Adjacency matrix??adjacency lists?? Review Graphs (from CSE 2315)
More informationUndirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1
Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching
More information2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23)
2pt 0em Computer Science & Engineering 423/823 Design and of s Lecture 04 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 18 Given a connected, undirected
More informationShortest path problems
Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths
More informationCS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya
CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Graphs (review) Definition. A directed graph (digraph) G = (V, E) is an ordered pair consisting of a set V of vertices
More informationCIS 121 Data Structures and Algorithms Minimum Spanning Trees
CIS 121 Data Structures and Algorithms Minimum Spanning Trees March 19, 2019 Introduction and Background Consider a very natural problem: we are given a set of locations V = {v 1, v 2,..., v n }. We want
More informationCS Elementary Graph Algorithms
CS43-09 Elementary Graph Algorithms Outline Representation of Graphs Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS43
More informationCS Elementary Graph Algorithms
CS483-09 Elementary Graph Algorithms Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/
More informationFundamental Algorithms CSCI-GA /Summer Solution to Homework 8
Fundamental Algorithms CSCI-GA.70-00/Summer 206 Solution to Homework 8 Problem (CLRS 23.-6). ( point) Show that a graph has a unique minimum spanning tree if, for every cut of the graph, there is a unique
More informationKruskal s MST Algorithm
Kruskal s MST Algorithm CLRS Chapter 23, DPV Chapter 5 Version of November 5, 2014 Main Topics of This Lecture Kruskal s algorithm Another, but different, greedy MST algorithm Introduction to UNION-FIND
More informationMinimum spanning trees
Minimum spanning trees [We re following the book very closely.] One of the most famous greedy algorithms (actually rather family of greedy algorithms). Given undirected graph G = (V, E), connected Weight
More informationAnnouncements. HW3 is graded. Average is 81%
CSC263 Week 9 Announcements HW3 is graded. Average is 81% Announcements Problem Set 4 is due this Tuesday! Due Tuesday (Nov 17) Recap The Graph ADT definition and data structures BFS gives us single-source
More informationCHAPTER 23. Minimum Spanning Trees
CHAPTER 23 Minimum Spanning Trees In the design of electronic circuitry, it is often necessary to make the pins of several components electrically equivalent by wiring them together. To interconnect a
More informationCSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo
CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve
More informationMinimum Spanning Tree (undirected graph)
1 Minimum Spanning Tree (undirected graph) 2 Path tree vs. spanning tree We have constructed trees in graphs for shortest path to anywhere else (from vertex is the root) Minimum spanning trees instead
More informationCS 561, Lecture 9. Jared Saia University of New Mexico
CS 561, Lecture 9 Jared Saia University of New Mexico Today s Outline Minimum Spanning Trees Safe Edge Theorem Kruskal and Prim s algorithms Graph Representation 1 Graph Definition A graph is a pair of
More informationCSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li
CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast
More informationThree Graph Algorithms
Three Graph Algorithms Shortest Distance Paths Distance/Cost of a path in weighted graph sum of weights of all edges on the path path A, B, E, cost is 2+3=5 path A, B, C, E, cost is 2+1+4=7 How to find
More informationThree Graph Algorithms
Three Graph Algorithms Shortest Distance Paths Distance/Cost of a path in weighted graph sum of weights of all edges on the path path A, B, E, cost is 2+3=5 path A, B, C, E, cost is 2+1+4=7 How to find
More informationMinimum Spanning Trees
CSMPS 2200 Fall Minimum Spanning Trees Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 11/6/ CMPS 2200 Intro. to Algorithms 1 Minimum spanning trees Input: A
More informationGreedy Algorithms Part Three
Greedy Algorithms Part Three Announcements Problem Set Four due right now. Due on Wednesday with a late day. Problem Set Five out, due Monday, August 5. Explore greedy algorithms, exchange arguments, greedy
More informationComputer Science & Engineering 423/823 Design and Analysis of Algorithms
s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 Spring 2010 s of s s are abstract data types that
More informationCIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018
CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018 Q1: Prove or disprove: You are given a connected undirected graph G = (V, E) with a weight function w defined over its
More informationTrees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006
Trees and Graphs Basic Definitions Tree: Any connected, acyclic graph G = (V,E) E = V -1 n-ary Tree: Tree s/t all vertices of degree n+1 A root has degree n Binary Search Tree: A binary tree such that
More informationCSE 100: GRAPH ALGORITHMS
CSE 100: GRAPH ALGORITHMS Dijkstra s Algorithm: Questions Initialize the graph: Give all vertices a dist of INFINITY, set all done flags to false Start at s; give s dist = 0 and set prev field to -1 Enqueue
More information