More Algorithm Examples Mani Chandy

Slides:



Advertisements
Similar presentations
Chapter 9 Greedy Technique. Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible - b feasible.
Advertisements

Lecture 15. Graph Algorithms
Great Theoretical Ideas in Computer Science
Single Source Shortest Paths
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
October 31, Algorithms and Data Structures Lecture XIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CS138A Single Source Shortest Paths Peter Schröder.
Data Structures and Algorithms Graphs Single-Source Shortest Paths (Dijkstra’s Algorithm) PLSD210(ii)
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Discussion #34 1/17 Discussion #34 Warshall’s and Floyd’s Algorithms.
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
All Pairs Shortest Paths and Floyd-Warshall Algorithm CLRS 25.2
Minimum Spanning Tree Algorithms
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Shortest Paths Definitions Single Source Algorithms
Algorithms All pairs shortest path
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
The Traveling Salesperson Problem
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Dynamic Programming Mani Chandy
Dynamic Programming 2 Mani Chandy
The Shortest Path Problem
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
Theory of Computing Lecture 7 MAS 714 Hartmut Klauck.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Network Optimization Chapter 3 Shortest Path Problems.
Graphs, BFS, DFS and More…
Dijkstra’s Algorithm. Announcements Assignment #2 Due Tonight Exams Graded Assignment #3 Posted.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
Dijkstra’s Algorithm Supervisor: Dr.Franek Ritu Kamboj
Lecture 7 All-Pairs Shortest Paths. All-Pairs Shortest Paths.
Introduction to Algorithms Jiafen Liu Sept
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 9 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Shortest Path in Weighted Graph : Dijkstra’s Algorithm.
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)
Introduction to Graphs And Breadth First Search. Graphs: what are they? Representations of pairwise relationships Collections of objects under some specified.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Chapter 7 Dynamic Programming 7.1 Introduction 7.2 The Longest Common Subsequence Problem 7.3 Matrix Chain Multiplication 7.4 The dynamic Programming Paradigm.
8.4 Closures of Relations Definition: The closure of a relation R with respect to property P is the relation obtained by adding the minimum number of.
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
Graphs. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
CSE 326: Data Structures Lecture #23 Dijkstra and Kruskal (sittin’ in a graph) Steve Wolfman Winter Quarter 2000.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Lecture 7 All-Pairs Shortest Paths
Analysis and design of algorithm
CSE 373: Data Structures and Algorithms
Shortest Path Algorithms
Minimum Spanning Tree Algorithms
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
CSE 373 Data Structures and Algorithms
Lecture 12 Shortest Path.
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Directed Graphs (Part II)
Presentation transcript:

More Algorithm Examples Mani Chandy

Goal for Today Review data structures, dynamic programming and greedy algorithms by applying them to new problems. Creative step: decide which tools to apply for a given problem.

Single-Source Shortest Path Find shortest path from vertex 1 to all vertices. All edge weights are non-negative

Single-Source vs All-Points 1.For single source the algorithm computes the shortest paths from a single specified vertex whereas in all-points the shortest paths between all pairs of vertices is computed. 2.For single source we are assuming that there are no negative weights whereas for all-points we allowed negative weights.

Data Structure Assumption To begin with, assume that the graph is specified by an edge weight matrix W, where W[j,k] is the weight of the edge from vertex j to vertex k. The memory required by the matrix is proportional to N 2 A more efficient (in terms of time and space) implementation for sparse graphs is to use an array of adjacency lists. AdjacenyList[j] is a list of neighboring vertices of vertex j. the amount of storage is proportional to E, the number of edges, and not to N 2 (where N is the number of vertices).

Creative Step What tool shall we apply? –Dynamic programming –Greedy algorithms –Clevel data structures Let’s postpone the data structure design issue. Sometimes greedy algorithms and dynamic programming are similar. Try greedy.

What do non-negative weights give? Crucial insight: There exists a shortest path to the k-th nearest vertex that has intermediate vertices only from the set of (k-1) nearest vertices. Proof: Consider a path from the source to the j-th nearest Vertex, let us call it u, and then on an edge from u to the k-th nearest vertex, let us call it v. for j > k. v u source

Proof of Crucial Insight v u source The length of this path is the length of the path to u + W[u,v] Since W[u,v] is non-negative, the length of this path is at least the length of the path to u.

The Greedy Decision Make a decision that is optimal, and from which we can make subsequent decisions. The j-th greedy decision: identify the vertex that is j-th closest to the source.

The Greedy Algorithm Intuition: have a weight, say 1Kg, at each node, and have strings between weights, where the length of the string is the weight of the corresponding edge source Some strings will be lose. Some strings will be taut. Closest vertexNext closestThird closest

The Greedy Steps Identified closest At each greedy step, the next closest vertex is identified. progression of greedy steps

The Crucial Insight To find the distance to the k-th nearest vertex we do not need to consider vertices farther away as intermediate vertices. 3-rd nearest vertex We don’t need to consider the 4-th nearest vertex as a possible intermediate vertex in computing distance to 3-rd nearest.

The Creative Step Step j, we have identified the j closest vertices. What information do we need to identify the next closest vertex?

Data Structures Let L[t] be the set of the j closest vertices identified at step t L[0] = {} L[1] = {1} L[2] = {1,3} L[3] = {1,3,2} L[4] = {1,3,2,4}

Recursion Relation for L L[t+1] = L[t] union {v} –Where v is the (t+1)-th closest vertex. How do we find the (t+1)-th closest vertex?

More Data Structures Let D[j,t] be the shortest distance to vertex j over all paths for which the intermediate vertices (if any) are from set L[t]. A C B E D L[2] = {A,C} D[B,2]: Restrict attention to paths from source, vertex A, to vertex B that can only pass through vertex C, and do not pass through vertices B, E, D.

Theorem For all j in L[t]: D[j,t] is the shortest distance to j over all paths Recall D[j,t] is the shortest distance to vertex j over all paths for which the intermediate vertices (if any) are from set L[t]. This theorem tells us that for j in L[t], D[j,t] is the shortest distance to j regardless of the intermediate vertices. Proof follows directly from the crucial insight.

Recursion for D[j,t] Recall L[t+1] = L[t] union {v} where v is the (t+1)-th closest vertex. D[j,t+1] = min(D[j,t], D[v,t] + W[v,j]) Proof ?

Proof for Recursion of D[j,t+1] Partition the set of paths from the source to vertex j that can only pass through vertices in set L[t+1] into two subsets: the paths that can only pass through vertices in L[t] the paths that pass though v and can pass through vertices in L[t] The distance of paths in the first subset is at least D[j,t] from the induction hypothesis. We must prove that the distance of paths in the second subset is at least D[v,t]+W[v,j]

Proof for Recursion of D[j,t+1] We must prove that the distance of paths in the second subset is at least D[v,t]+W[v,j] Partition the paths that pass through v on their way to j into Two subsets: 1.Paths that go through v and then go to some other intermediate vertex in L[t] and then to j. 2. Paths that go to v and then directly to j. Consider a path in the first subset: from source to v to some vertices in L[t] with a vertex k being the prefinal vertex. There is an optimal path to k without going through v (from the induction hypothesis). So ignore the first subset.

The Recursive Relations L[t+1] = L[t] union {v} where v is ? v is a vertex that is not in L[t], and where D[v, t+1] is the minimum over all vertices not in L[t] of D[j,r+1] D[j, t+1] = min(D[j,t], D[v,t] + W[v,j]) For j not in L[t+1], D[j, t+1] is ?:

Initial Conditions L[0] = {}, the empty set. D[j,0] = 0 if j is the source, I (infinity) if j is not the source.

The Algorithm in Action I I I I I I I I Array D

Proof Assume induction hypothesis for t = 0 … r and prove the hypothesis for t= r+1 D[j,t] is the shortest distance from vertex 1 to vertex j that can have intermediate vertices only from set L[t]. The vertex set L[t] is the set of vertices at step t for which D[j,t] is the shortest distance from vertex 1 to vertex j. The vertices in L[t] are closer or as close to the source as the Vertices that are not in L[t]. The Induction Hypothesis

Proof of Induction Step Most of the steps have already been proved. Details are left to you.

The Homework Problem 1234 modules wires Given C[j,k] the number of wires between modules j and k, order the modules in a straight line to minimize wire length. Note C[j,k] = C[k,j]