Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 10.

Slides:



Advertisements
Similar presentations
Coloring Warm-Up. A graph is 2-colorable iff it has no odd length cycles 1: If G has an odd-length cycle then G is not 2- colorable Proof: Let v 0, …,
Advertisements

COMP 482: Design and Analysis of Algorithms
Single Source Shortest Paths
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
Spring 2007Shortest Paths1 Minimum Spanning Trees JFK BOS MIA ORD LAX DFW SFO BWI PVD
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 4.
Introduction to Algorithms 6.046J/18.401J/SMA5503
Discussion #34 1/17 Discussion #34 Warshall’s and Floyd’s Algorithms.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Shortest Paths1 C B A E D F
Hardness Results for Problems P: Class of “easy to solve” problems Absolute hardness results Relative hardness results –Reduction technique.
Topics: 1. Finding a cycle in a graph 2. Propagation delay - example 3. Trees - properties מבנה המחשב - אביב 2004 תרגול 3#
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Shortest Paths Definitions Single Source Algorithms
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
Shortest Paths1 C B A E D F
Tirgul 13 Today we’ll solve two questions from last year’s exams.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 8 Greedy Graph.
CISC 235: Topic 11 Shortest Paths Algorithms. CISC 235 Topic 112 Outline Single-Source Shortest Paths Algorithm for Unweighted Graphs Algorithm for Weighted,
A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
Shortest Paths C B A E D F
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
Introduction to Algorithms Jiafen Liu Sept
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
Lecture 23 CSE 331 Oct 24, Reminder 2 points for Piazza participation 3 points for mini-project.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 20.
Section 13  Questions  Graphs. Graphs  A graph representation: –Adjacency matrix. Pros:? Cons:? –Neighbor lists. Pros:? Cons:?
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 10.
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
SSSP in DAGs (directed acyclic graphs). DFS (depth first search) DFS(vertex v) { v.visited = TRUE; for each w adjacent to v do if(!w.visited) then dfs(w);
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
1 COMP9024: Data Structures and Algorithms Week Twelve: Graphs (II) Hui Wu Session 1, 2014
Data Structures and Algorithm Analysis Lecture 5
Graph Algorithms BFS, DFS, Dijkstra’s.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Lecture 23 CSE 331 Oct 26, 2016.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
CS 3343: Analysis of Algorithms
Data Structures and Algorithms CMPSC 465
Elementary graph algorithms Chapter 22
CSCE 411 Design and Analysis of Algorithms
Lectures on Graph Algorithms: searching, testing and sorting
Lecture 23 CSE 331 Oct 25, 2017.
Lecture 24 CSE 331 Oct 29, 2012.
Lecture 23 CSE 331 Oct 24, 2011.
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Depth-First Search Graph Traversals Depth-First Search DFS.
CSCE 411 Design and Analysis of Algorithms
Lecture 13 Algorithm Analysis
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Chapter 24: Single-Source Shortest Paths
Autumn 2016 Lecture 10 Minimum Spanning Trees
Chapter 24: Single-Source Shortest Paths
CSE 417: Algorithms and Computational Complexity
Elementary graph algorithms Chapter 22
Chapter 24: Single-Source Shortest-Path
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Dominating Set By Eric Wengert.
Data Structures and Algorithm Analysis Lecture 8
Presentation transcript:

Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 10

Q1: Topological ordering Give an extension of the topological sort algorithm that we studied in class that does the following. The input of the algorithm is an arbitrary directed graph G that may or may not be a DAG. The output is one of two things: (a) a topological ordering, thus establishing that G is a DAG; or (b) a cycle in the graph, establishing that G is not a DAG. The runtime of the algorithm should be O(m + n). 2

Answer Use the topological sort algorithm. If you find that every node has an incoming edge, report a cycle. How to find this cycle? Just follow the incoming edges backwards. At some point you will have to revisit a node, as there are only n nodes. At this point you have your cycle. 3

Q2: Dijkstra with negative edge costs Give an example of a directed graph with negative edge costs where the algorithm produces an incorrect output. 4

Q3: Number of weighted shortest paths Given a weighted directed graph (positive edge weights), find the number of shortest paths from node u to node v. 5

6 Dijkstra's Algorithm Dijkstra's algorithm. n Maintain a set of explored nodes S for which we have determined the shortest path distance d(u) from s to u. n Initialize S = { s }, d(s) = 0. n Repeatedly choose unexplored node v which minimizes add v to S, and set d(v) =  (v). s v u d(u) shortest path to some u in explored part, followed by a single edge (u, v) S e

Answer: Modify Dijkstra’s algorithm MODIFIED-DIJKSTRA (G = (V; E); s in V ) Set d[v] = ∞ and count[v] = 0 for every node v in (V – {s}) Set d[s] = 0 and count[s] = 1 S = Ø, Q = V while Q ≠ Ø Let u be a node in Q such that d[u] ≤ d[v] for all nodes v in Q Q = Q – {u}; add u to S for each node v adjacent to u if d[v] > d[u] + w(u, v) d[v] = d[u] + w(u, v) count[v] = count[u] else if d[v] = d[u] + w(u, v) count[v] = count[v] + count[u] return count[v] for every node v in V 7

Q5: Graphs with specified degrees Given a list of natural numbers d 1,…, d n, show how to decide in polynomial time if there exists an undirected graph G = (V, E) where the node degrees are precisely the numbers d 1,…,d n. 8

Answer If any of the degrees is 0, this should be an isolated node in the graph; so we can just delete that degree from the list. Let us now sort the list so that d 1 ≥ … ≥ d n > 0. Let d n = k. Now consider the list L = {d 1 – 1, …, d k – 1, d k + 1, …, d n – 1 }. Claim: the graph we want exists iff there is a graph whose degrees are the items of L. Note that L has one less element than the original list. So we can proceed recursively to check if G satisfies the desired property. 9

Proof of Claim from previous slide We prove the two directions of the “if and only if” separately. (  ) If a graph G whose degrees are the elements of L exist, then we can add a node v n and connect it to the first d n nodes of G in the descending order of degrees. (  ) Suppose there’s no graph whose degrees are the elements of L, but at the same time, there’s a graph G of the sort demanded by the problem. Let v i be the node with degree d i in G. By assumption, we have i and j, with j < i, such that G has an edge of the form (v n, v i ) but no edge of the form (v n, v j ). But because of the way the list is sorted, we have d j ≥ d i. This means there is some v such that G has an edge (v j, v) but no edge (v i, v). Now let us apply an exchange argument. Let us replace G by a graph G’ which is exactly like G, but where: (1) there is no edge (v n, v i ) or (v j, v), and (2) there are edges (v i, v) and (v n, v j ). Applied repeatedly, this transformation gives us a graph whose degrees belong to L, giving a contradiction. 10