CISC 235: Topic 10 Graph Algorithms.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Minimum Spanning Tree CSE 331 Section 2 James Daly.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
Analysis of Algorithms CS 477/677
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
DAST 2005 Tirgul 12 (and more) sample questions. DAST 2005 Q.We’ve seen that solving the shortest paths problem requires O(VE) time using the Belman-Ford.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
1 Minimum Spanning Trees. Minimum- Spanning Trees 1. Concrete example: computer connection 2. Definition of a Minimum- Spanning Tree.
1 Greedy Algorithms and MST Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
Chapter 23: Minimum Spanning Trees: A graph optimization problem Given undirected graph G(V,E) and a weight function w(u,v) defined on all edges (u,v)
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
1 2/23/2016 ITCS 6114 Topological Sort Minimum Spanning Trees.
MST Lemma Let G = (V, E) be a connected, undirected graph with real-value weights on the edges. Let A be a viable subset of E (i.e. a subset of some MST),
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Graph Search Applications, Minimum Spanning Tree
Greedy Algorithms General principle of greedy algorithm
Lecture ? The Algorithms of Kruskal and Prim
Data Structures and Algorithms I Day 19, 11/3/11 Edge-Weighted Graphs
Introduction to Algorithms
Minimum Spanning Tree Chapter 13.6.
Discrete Mathematicsq
Topological Sort Minimum Spanning Tree
CS 3343: Analysis of Algorithms
Minimum Spanning Trees
CSC 413/513: Intro to Algorithms
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Minimum Spanning Trees
Short paths and spanning trees
Minimum Spanning Trees
Data Structures & Algorithms Graphs
Graph Algorithm.
Minimum Spanning Tree.
Connected Components Minimum Spanning Tree
Graph Algorithm.
Minimum Spanning Tree.
"Learning how to learn is life's most important skill. " - Tony Buzan
Minimum Spanning Trees
CSE 373 Data Structures and Algorithms
Algorithms and Data Structures Lecture XII
Spanning Trees.
Data Structures – LECTURE 13 Minumum spanning trees
Greedy Algorithm (17.4/16.4) Greedy Algorithm (GA)
Analysis of Algorithms CS 477/677
Lecture 12 Algorithm Analysis
CSCI2100 Data Structures Tutorial
Minimum Spanning Tree.
Minimum Spanning Trees
Algorithms Searching in a Graph.
Minimum spanning tree Shortest path algorithms
Greedy Algorithms Comp 122, Spring 2004.
Lecture 12 Algorithm Analysis
Total running time is O(E lg E).
Advanced Algorithms Analysis and Design
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Binhai Zhu Computer Science Department, Montana State University
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum Spanning Trees
Presentation transcript:

CISC 235: Topic 10 Graph Algorithms

Outline Spanning Trees Minimum Spanning Trees Topological Sort Kruskal’s Algorithm Prim’s Algorithm Topological Sort CISC 235 Topic 10

Spanning Trees A spanning tree of an undirected graph is a subgraph that contains all its vertices and is a tree. The complete graph on four vertices o---o |\ /| | X | |/ \| has 16 spanning trees. o---o o---o o o o---o | | | | | | o o o---o o---o o---o o---o o o o o o o \ / |\ / \ / \ /| X | X X X | / \ |/ \ / \ / \| o o o o o---o o o o o o---o o o o---o |\ | / | /| \ | \ | / | / | \ | \| / |/ | \ o---o o o o o o---o |\ | / \ | /| | \ | / \ | / | | \ |/ \| / | o o o---o o---o o o CISC 235 Topic 10

Example Graph CISC 235 Topic 10

DFS & BFS Spanning Trees What property does the BFS spanning tree have that the DFS spanning tree does not? CISC 235 Topic 10

Minimum Spanning Trees The cost of a spanning tree of a weighted, undirected graph is the sum of the costs (weights) of the edges in the spanning tree. A minimum-cost spanning tree is a spanning tree of least cost. Is there more than one minimum spanning tree? CISC 235 Topic 10

Kruskal’s Algorithm Begin with a subgraph S of a weighted, connected undirected graph G, that includes all of its vertices, but none of its edges (i.e., a forest of one-node trees). Add edges from G one at a time to S, each time picking a least-cost edge that will not form a cycle in S, until V-1 edges have been added (so we have a single spanning tree). CISC 235 Topic 10

Kruskal’s Algorithm CISC 235 Topic 10

Kruskal’s Algorithm: O( |E| lg |V| ) MST-Kruskal(G, w) // weight function w : E  R S ← Ø // Subgraph S has no edges (but has all vertices) for each vertex v ∈ V[G] MAKE-SET(v) // Each vertex is a tree of one node sort the edges of E into nondecreasing order by weight w for each edge (u, v) ∈ E, taken in nondecreasing order if FIND-SET(u) ≠ FIND-SET(v) // If not in same tree S ← S ∪ {(u, v)} // Add edge to subgraph S UNION(u, v) // Join their two trees return S CISC 235 Topic 10

Prim’s Algorithm Begin with a tree T that contains any single vertex, w, from a weighted, connected undirected graph G. Then add a least-cost edge (u, w) to T such that T ∪ {(u, w)} is also a tree. This edge-addition step is repeated until T contains V-1 edges. Notice that edge (u, w) is always such that exactly one of u and w is in T. CISC 235 Topic 10

Prim’s Algorithm CISC 235 Topic 10

Prim’s Algorithm Using a Priority Queue : O( |E| lg |V| ) MST-Prim(G, w, r) // r is the root vertex (start vertex) for each u ∈ V [G] // Initially, all vertices u are set to: key[u] ← ∞ // No edge connecting u to MST, so cost is ∞ π[u] ← NIL // No parent of u in MST key[r] ← 0 // Initially, r is the only vertex in MST Q ← V [G] // All vertices are placed in priority queue while Q ≠ Ø u ← EXTRACT-MIN(Q) for each v ∈ Adj[u] // Update adjacent edges if if v ∈ Q and w(u, v) < key[v] // this path is cheaper π[v] ← u // Reset parent of v to be u key[v] ← w(u, v) // Reset minimum cost CISC 235 Topic 10

Kruskal’s Algorithm CISC 235 Topic 10

Kruskal’s Algorithm, con. CISC 235 Topic 10

Prim’s Algorithm CISC 235 Topic 10

Topological Sorting A topological sort of a dag (directed, acyclic graph) is a linear ordering of all its vertices such that if the graph contains an edge (u, v), then u appears before v in the ordering. A topological sort of a graph can be viewed as an ordering of its vertices along a horizontal line so that all directed edges go from left to right. If the graph has a cycle, then no linear ordering is possible. CISC 235 Topic 10

What other topological sorts are possible? Topological Sorting What other topological sorts are possible? CISC 235 Topic 10

A dag for Topological Sorting In general, which vertex will be first in a topological sort? CISC 235 Topic 10

Topological Sort Algorithm Begin with an empty list L and a dag G. While G is not empty, Find a vertex v with no incoming edges Delete v and its outgoing edges from G Add v to L CISC 235 Topic 10

Topological Sort Algorithm Topological-Sort( G ) Create empty lists L & K Create a count array for each vertex v in G count[v]  number of incoming edges to v if count[v] = 0 add v to K while K is not empty remove a vertex v from K for each outgoing edge (v,w) decrement count[w] if count[w] = 0 add w to K add v to L return L CISC 235 Topic 10