Title: Master Method (4. 3)
1Master Method (4. 3)
size of sub problem
how many sub problems
- Recurrent formula T(n) a?T(n/b) f(n)
- 1) if for some ?
gt 0 then - 2) if then
- 3) if for some ?
gt 0 and a? f(n/b)? c? f(n) for
some c lt 1 then
time to merge
Sorting T(n)2T(n/2)n
2Strassens Algorithm Matrix Muliplication (31.2)
- Divide and conquer
- Merge
- Recurrence
- Strassens recurrence
- Strassens merge
- Best
3Single-Source Shortest Paths (25.0)
- Given a graph G(V,E) and w E ? ?
- weight of ltv1,...,vkgt is w(p) ? w(vi)
- 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
v
x
lt0
Ex.
5
-3
-3
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 dv ? ? ds ? 0
- Relaxation
- for i 1,...,V-1 do
- for each edge (u,v) ? E do
- dv ? mindv, dvw(u,v)
- Negative cycle checking
- for each v ?V do if dvgt du w(u,v) then no
solution
V E
s
6 Bellman-Ford Analysis (25.3)
- Runtime O(VE)
- Correctness
- Lemma dv ? ?(s,v)
- Initially true
- Let dv du w(u,v)
- by triangle inequality for first violation
dv lt ?(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 ? v1 ? v2 ? ... ? v
- After i-th iteration ds,vi is correct and
final
7 Bellman-Ford - Application
- Systems of difference constraints
- example placing features on a chip, certain
conditions have to be satisfied
Using layers
Lot of features (elements on chips), usually
rectangular, polygons parallel to x or y axes
8 Bellman-Ford - Application
- Systems of difference constraints
- example placing features on a chip, certain
conditions have to - be satisfied
Intersections are not allowed
1
2
1
1- 1st layer 2 - 2nd layer 3 - 3rd layer
2
1
C
Distance not more than C
3
2
1. Place elements, connect them, put in right
layer 2. Squeeze them following the designers
rule close as possible, but not to close,
layers should overlap, otherwise they would not
connect ... ? constraints
9 Bellman-Ford - Application
x2 x3 x4 x5 x6 x7 x8
x1
x2-x1 ? C1 x3-x2 ? C2
x2-x1 ? C3 ? x1-x2 ? -C3
xi-xj ? Ck
xi-xj ? Ck
origin
Ck
x0
i
j
xi-x0 ? 0
10Compaction 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)
11Multi-commodity flows
sink
source
- Connect pairs (si,si)
- 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
2
C(v)
sink
source
v
3
G
4
12Multi-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
4
2
w ? 0 w(P)? w(v) v ?P
3
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 gt0 Problem 2Give 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 3Find the shortest
path with at most K edges between source and sink.