Presentation is loading. Please wait.

Presentation is loading. Please wait.

Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for.

Similar presentations


Presentation on theme: "Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for."— Presentation transcript:

1 Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for some c < 1 then how many sub problems size of sub problem time to merge Sorting: T(n)=2T(n/2)+n

2 Strassen’s Algorithm: Matrix Muliplication (31.2) Divide and conquer Merge Recurrence Strassen’s recurrence Strassen’s merge Best

3 Single-Source Shortest Paths (25.0) Given a graph G=(V,E) and w: E   weight of is w(p) =  w(v[i]) Single-source shortest-paths find a shortest path from a source s to every vertex v  V Single pair shortest path problem asks for a u-v shortest path for some pair of vertices All pairs shortest-paths problem will be next time

4 Shortest Paths (25.0-1) Predecessor subgraph for restoring shortest paths Shortest-paths tree rooted at source s Th: Subpath of a shortest path is a shortest path Triangle Inequality:  (u,v)   (u,x) +  (x,v) Well defined: some paths may not exist if there is a negative-weight cycle in graph: u x v <0 5 -3 Ex.

5 Bellman-Ford (25.3) (Single-Source Shortest Paths) Most basic (BFS based) algorithm, shortest paths (tree) easy to reconstruct. for each v  V do d[v]   ; d[s]  0 Relaxation for i =1,...,|V|-1 do for each edge (u,v)  E do d[v]  min{d[v], d[v]+w(u,v)} Negative cycle checking for each v  V do if d[v]> d[u] + w(u,v) then no solution |V| |E| s

6 Bellman-Ford Analysis (25.3) Runtime = O(VE) Correctness –Lemma: d[v]   (s,v) Initially true Let d[v] = d[u] +w(u,v) by triangle inequality for first violation d[v] <  (s,v)   (s,u)+w(u,v)  d(s,u)+w(u,v) –After |V|-1 passes all d values are  ’s if there are no negative cycles s  v[1]  v[2] ...  v After i-th iteration d[s,v[i]] is correct and final

7 Bellman-Ford - Application Systems of difference constraints example: placing features on a chip, certain conditions have to be satisfied Lot of features (elements on chips), usually rectangular, polygons parallel to x or y axes Using layers

8 Bellman-Ford - Application Systems of difference constraints example: placing features on a chip, certain conditions have to be satisfied 1 1 2 2 Intersections are not allowed 1 2 3 1- 1st layer 2 - 2nd layer 3 - 3rd layer 1. Place elements, connect them, put in right layer 2. “Squeeze” them following the designer’s rule: close as possible, but not to close, “layers” should overlap, otherwise they would not connect...  constraints C Distance not more than C

9 Bellman-Ford - Application x1x1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 2 -x 1  C 1 x 3 -x 2  C 2 x 2 -x 1  C 3  x 1 -x 2  -C 3 x i -x j  C k ij CkCk origin x0x0 x i -x 0  0

10 Compaction for VLSI (Application of Bellman-Ford Algorithm) 1. Sweepline (movable) 2. Constraint weighted graph G 3. Bellman-Ford for G with negated weights (possible positive weights - originaly negative) Finds shortest (longest) path from the left most node. Output: for each node we get the longest path from the left most point (root). (we look only at the right)

11 Multi-commodity flows Connect pairs (s i,s i ’) such that for each node v  V of G # of paths containing v  c(v) (capacity) - difficult problem - to many constrains - lot of problems in practice could be reduced to this problem - solution? 1 2 3 4 v C(v) G source sink 2 source

12 Multi-commodity flows Approximation algorithm by N. Garg,… For some pair find the shortest path -never solved when capacities are on edges, only when capacities are on nodes s s’ 2 4 3 w  0 w(P)=  w(v) v  P We want to apply Dijkstra for shortest path

13 Homework problems Problem 1: Give an algorithm, based on Dijkstra, (use Dijkstra as a “black box”) that finds the single source shortest paths in a NODE weighted graph. Length of the path = sum of weights of nodes in the path weight (path)=  v  P w(v), weights >0 Problem 2:Give an algorithm to find the shortest EVEN paths from source to sink. (assumption: we reduced Problem 1 from node weights to edge weights) Note: if there is no even path, we will assume that we have loops, loops have weights. Problem 3:Find the shortest path with at most K edges between source and sink.


Download ppt "Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for."

Similar presentations


Ads by Google