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.

Slides:



Advertisements
Similar presentations
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Advertisements

CS138A Single Source Shortest Paths Peter Schröder.
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
CPSC 411, Fall 2008: Set 9 1 CPSC 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Fall 2008.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
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 Path Problems
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
BellmanFord. BellmanFord(G,w,s) 1 InitializeSingleSource(G,s) 2 for i 1 to |V[G]| do for each (u,v) E[G] 4 do Relax(u,v,w) 5 for each edge (u,v)
Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping.
Shortest Paths Definitions Single Source Algorithms
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.
Analysis of Algorithms CS 477/677 Shortest Paths Instructor: George Bebis Chapter 24.
DAST 2005 Tirgul 13 (and more) sample questions. DAST 2005 (back to previous week) We’ve seen that solving the shortest paths problem requires O(VE) time.
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.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
CS 253: Algorithms Chapter 24 Shortest Paths Credit: Dr. George Bebis.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Topological Sorting and Least-cost Path Algorithms.
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
David Luebke 1 9/10/2015 CS 332: Algorithms Single-Source Shortest Path.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
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,
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.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Shortest Path Problems How can we find the shortest route between two points on a road map? Model the problem as a graph problem: –Road map is a weighted.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
David Luebke 1 9/15/2015 CS 332: Algorithms Topological Sort Minimum Spanning Trees.
Minimum Spanning Trees and Kruskal’s Algorithm CLRS 23.
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.
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
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)
Finding Minimum Spanning Trees Algorithm Design and Analysis Week 4 Bibliography: [CLRS]- Chap 23 – Minimum.
Lecture 13 Algorithm Analysis
Greedy Algorithms Z. GuoUNC Chapel Hill CLRS CH. 16, 23, & 24.
1 2/23/2016 ITCS 6114 Topological Sort Minimum Spanning Trees.
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
Shortest paths Given: A single source vertex (given s) in a weighted, directed graph. Want to compute a shortest path for each possible destination. (Single.
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.
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Greedy Algorithms General principle of greedy algorithm
Topological Sort Minimum Spanning Tree
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Algorithms and Data Structures Lecture XIII
Minimum Spanning Tree Shortest Paths
CSC 413/513: Intro to Algorithms
CISC 235: Topic 10 Graph Algorithms.
Introduction to Graphs
Many slides here are based on E. Demaine , D. Luebke slides
Algorithms and Data Structures Lecture XII
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Minimum Spanning Tree Algorithms
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Algorithms Searching in a Graph.
Minimum spanning tree Shortest path algorithms
Advanced Algorithms Analysis and Design
Presentation transcript:

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 algorithm or O((V+E)logV) using the Dijkstra algorithm (might be even O(VlogV+E) when using Fibonacci heaps). Suppose you know that your graph is a DAG, can you do better? 6  y uv 11 4 x

DAST 2005 A.Yep, the algorithm is: Dag-Shortest-Paths(G,w,s) 1. topologically sort the vertices of G 2. Initialize-Single-Source(G,s) 3. For each vertex u (taken in topologically sorted order) 4. For each vertex v  Adj[u] 5. Relax(u,v,w) This procedure runs in  (V+E)  (|V+E|)  (|V|) (  (|V|))  (|E|)

DAST 2005 We first run topological sort (O(|V+E|)) Reminder: A topological sort takes a directed acyclic graph, or DAG, and returns an ordered list of the vertices such that if there is an edge (v,u) in the graph, then v will appear before u in the list.  If there are a few paths from s to v, we will relax all the vertices along these paths before calculating the distance from v → When we relax the distances of all the neighbors of v, the distance to v is the shortest path (since we relax vertices in topologically ordered manner, we will relax all vertices that have incoming edges to v, before relaxing all those reachable from v )

DAST 2005 (a bit) More formally: We want to prove: The algorithm calculates the shortest paths between the source vertex and all other vertices ♦ The proof of correctness is by induction on the length of the number of nodes on the shortest path between s and a node v: p=(v 0,..,v k ) with v 0 = s, v k = v. ♦ We run through the nodes in topological order: the edges of p are relaxed in the order of the path (we did not have this property in Bellman-Ford). ♦ Assuming inductively d[v i-1 ]=δ[s, v i-1 ] when the for loop reached v i-1 the relaxation of ( v i-1, v i ) has the effect of setting d[v i ]=D[s, v i ]. ♦ Initially d[v 0 ]=0=D[s,s].

DAST 2005 Modified MST Your friend suggests an improved recursive MST algorithm: Given a graph G = (V,E), partition the set V of vertices into two sets V 1 and V 2 such that | V 1 | and | V 2 | differ by at most 1. Let E 1 be the set of edges that are incident only on vertices in V 1, and let E 2 be the set of edges that are incident only on vertices in V 2. Recursively solve a minimum-spanning tree problem on each of the two subgraphs G 1 = (V 1,E 1 ) and G 2 = (V 2,E 2 ). Finally, select the minimum-weight edge in E that crosses the cut (V1; V2), and use this edge to unite the resulting two minimum spanning trees into a single spanning tree. Will it work?

DAST 2005 Modified MST No, it won’t work, counter example: a b c 1 2 3

DAST 2005 Most Reliable path Assume you are given a directed graph on which each edge has an associated value which is a real number in the range 0 ≤ ≤ 1 that represents the reliability of a communication channel from vertex u to vertex v. Interpret to be the probability that the channel from u to v will not fail, and assume that these probabilities are independent. Give an efficient algorithm to find the most reliable path between two given vertices.

DAST 2005 Most Reliable path 1. Modify the initialization routine to initialize the reliability estimate (formerly the distance estimate), d [ u ], to zero for each vertex 2. Let vertex u be the source vertex and assign d [ u ] = 1 3. Modify the RELAX routine to maximize the reliability estimate, where the reliability estimate estimate along any path is the product of the reliabilities of each link (due to independent probabilities). Relaxing an edge (a; b) will update the reliability estimate d [ b ] = max( d [ b ]; d [ a ]* R ( a,b )) 4. Use a priority queue based on a Max-Heap (most reliable vertex on top)

DAST 2005 Counting paths Q.Give an efficient algorithm to count the total number of paths in a DAG G between a source vertex s and each other vertex A.The algorithm exploits the fact that G is a DAG and can therefore be topologically sorted. 1.Set the path counts of all vertices to 0, and set s ’s path count to one. 2.Topologically sort the vertices. 3.For each vertex u in topological order, do the following: 4.For each neighbor v of u, add u ’s path count to v ’s path count.

DAST 2005 Counting paths Correctness: Since the vertices are topologically ordered, a vertex v is not reachable until the path count to all vertices have been updated. (The proof is by induction on the topological order of the vertices)

DAST 2005 Prim with adjacency matrix Reminder: Prim’s algorithm (G, w, v) Q ← V[G] for each u in Q do key [u] ← ∞ key [r] ← 0 π [r] ← NIl while queue is not empty do u ← EXTRACT_MIN (Q) for each v in Adj[u] do if v is in Q and w(u, v) < key [v] then π [v] ← w(u, v) key [v] ← w(u, v) ← decrease_key O(log|V|) loop executed a total of O(|E|) times ← build heap O(|V|) O(|V|) O(|V|log|V|)

DAST 2005 Prim with adjacency matrix The time complexity of the algorithm using a min heap is O(|V|log|V| + |E|log|V|) = O(|E|log|V|) We will now see a variant that works with graphs represented using adjacency matrices in O(|V| 2 ) time

DAST 2005 Prim with adjacency matrix Reminder: Prim’s algorithm (G, w, v) A ← V[g] // Array For each vertex u in A do key [u]= ∞ key [r] ← 0 π [r] ← NIL while Array A is not empty do scan over A find the node u with smallest key, and remove it from array A for each vertex v in Adj[u] if v in A and w[u,v] < key[v] then π [v] ← u key[v] ← w[u,v] O(|V|) ← build an array  (|V|)  (|V|) O(|V|) *|V|