



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Lecture Slides of Algorithm and Complexity Analysis which includes Approximation Algorithms, Coping with Np-Hardness, Fully Polynomial-Time, Brute-Force Algorithms, Approximation Scheme, Knapsack Problem, Profit Subset of Items, Nonnegative Values etc. Key important points are:Shortest Path with Negative Weights, Negative Cycle Detection, Currency Exchange Arbitrage, Tramp Steamer Problem, Optimal Pipelining, Negative Cost Cycle, Finding Shortest Paths
Typology: Slides
1 / 6
This page cannot be seen from the preview
Don't miss anything!




s
3
t
2
6
7
4
5
(^1018)
9
6 15
30 20
44
11 16
6
19
6
Contents.^ n^
Directed shortest path with negative weights. n^
Negative cycle detection.^ –
application: currency exchange arbitrage n^
Tramp steamer problem.^ –
application: optimal pipelining of VLSI chips
3
Negative cost cycle.If some path from s to v contains a negative cost cycle, there does notexist a shortest s-v path; otherwise, there exists one that is simple.
s^
v
W c(W) < 0
3 4
5
-6 7
OPT(i, v) = length of shortest s-v path using at most i arcs.^ n^
Let P be such a path. n^
Case 1: P uses at most i-1 arcs. n^
Case 2: P uses exactly i arcs.^ –
if (u, v) is last arc, then OPT selects best s-u path using at mosti-1 arcs, and then uses (u, v)
Goal: compute OPT(n-1, t) and find a corresponding s-t path.
∈
otherwise
) , ( ) , 1 (
min
i if
) , (
v u c u i
OPT
v i
OPT
vi
E v u
5
Shortest Paths with Negative Weights: Algorithm
s, t
n^
ARRAY: OPT[0..n, V]FOREACH v
v] =
OPT[0,s]
FOR i
to n
FOREACH v
m^
OPT[i-1,
v]
m’
FOREACH (u,
v)
m’ =
min
(m’, OPT[i-1,
u] +
c[u,v])
OPT[i, v] =
min(m,
m’)
RETURN OPT[n-1, t]
Dynamic Programming Shortest Path
min
) , (
v u c u i
OPT E v u
∈
Shortest Paths: Running Time
Dynamic programming algorithm requires
(mn) time and space.
n^
Outer loop repeats n times. n^
Inner loop for vertex v considers indegree(v) arcs. Finding the shortest paths.^ n^
Could maintain predecessor variables. n^
Alternative: compute optimal distances, consider only zeroreduced cost arcs.
V v
7
Shortest Paths: Detecting Negative Cycles L1: if OPT(n,v) < OPT(n-1,v) for some node v, then (any) shortest pathfrom s to v using at most n arcs contains a cycle; moreover any suchcycle has negative cost.^ n^
Proof (by contradiction). n^
Since OPT(n,v) < OPT(n-1,v), P has n arcs. n^
Let C be any directed cycle in P. n^
Deleting C gives us a path from s to v of fewer than n arcs
C has negative cost.
s^
v
C c(C) < 0
Shortest Paths: Detecting Negative Cycles L1: if OPT(n,v) < OPT(n-1,v) for some node v, then (any) shortest pathfrom s to v using at most n arcs contains a cycle; moreover any suchcycle has negative cost.^ n^
Proof (by contradiction). n^
Since OPT(n,v) < OPT(n-1,v), P has n arcs. n^
Let C be any directed cycle in P. n^
Deleting C gives us a path from s to v of fewer than n arcs
C has negative cost. Corollary: can detect negativecost cycle in O(mn) time.^ n^
Need to trace backthrough sub-problems.
2
1 3
5
4
18
2
5
6
s^0
0
0
0
0
Docsity.com
13
Tramp-Steamer Problem
Tramp-steamer (min cost to time ratio) problem.^ n^
A tramp steamer travels from port to port carrying cargo. A voyagefrom port v to port w earn p(v,w) dollars, and requires t(v,w) days. n^
Captain wants a tour that achieves largest mean daily profit.
p = 30t = 7 p = 12t = 3
p = -3t = 5
mean daily profit =
Westward Ho (
Tramp-Steamer Problem
Tramp-steamer (min cost to time ratio) problem.^ n^
Input: digraph G = (V, E), arc costs c, and arc traversal times t > 0. n^
Goal: find a directed cycle W that minimizes ratio Novel application.^ n^
Minimize cycle time (maximize frequency) of logic chip on IBMprocessor chips by adjusting clocking schedule. Special case.^ n^
Find a negative cost cycle.
∈ ∈^ We
e W e^
15
Tramp-Steamer Problem
Linearize objective function.^ n^
Let
μ
n^
Let
μ
be a constant.
n^
Define
l
= ce
- e^
μ
t e
Case 1: there exists negative cost cycle W using lengths
l
. e
Case 2: every directed cycle has positive cost using lengths
le
∈ ∈
∈
W e^
e W e^
e
W e^
e
e^
∈
W e^
e W e^
e
W e^
e
e
Tramp-Steamer Problem
Linearize objective function.^ n^
Let
μ
n^
Let
μ
be a constant.
n^
Define
l
= ce
- e^
μ
t e
Case 3: every directed cycle has nonnegative cost using lengths
le
and there exists a zero cost cycle W.*
∈
W e^
e W e^
e
W e^
e
e
e W e^
Docsity.com
17
Tramp-Steamer Problem
Linearize objective function.^ n^
Let
μ
n^
Let
μ
be a constant.
n^
Define
l
= ce
- e^
μ
t e
Case 1: there exists negative cost cycle W using lengths
l
. e
n^
μ *** <**
μ
Case 2: every directed cycle has positive cost using lengths
le
n^
μ *** >**
μ
Case 3: every directed cycle has nonnegative cost using lengths
le
and there exists a zero cost cycle W.*^ n^
μ *** =**
μ
Tramp-Steamer: Sequential Search Procedure Theorem: sequential algorithm terminates.^ n^
Case 1
⇒ μ
strictly decreases from one iteration to the next.
n^
μ^ Let is the ratio of some cycle, and only finitely many cycles.
μ
be a
known
upper bound on
μ
REPEAT (forever)
l e
c
e^
μ
Solve shortest
path problem
with
lengths
l
e
(negative
cost
cycle
w.r.t.
l
)e
μ ←
μ
Find
a zero
cost cycle W*
w.r.t.
l
.e
Sequential Tramp Steamer
19
Tramp-Steamer: Binary Search Procedure^ W
cycle left
-C, right
REPEAT (forever)
μ (W)
μ
μ ←
(left +
right) /
l e
c
e^
μ
Solve
shortest
path problem
with lengths
l
e
IF (negative
cost
cycle
w.r.t.
l
)e
right
μ
negative
cost
cycle w.r.t.
l
e
ELSE IF (zero cost cycle
left
μ
Binary Search Tramp Steamer
left
μ
right
Tramp-Steamer: Binary Search Procedure Invariant: interval
[left, right]
and cycle W satisfy:
left
μ
μ (W) <
right
n^
Proof by induction follows from cases 1-2. Lemma. Upon termination, the algorithm returns a min ratio cycle.^ n^
Immediate from case 3. Assumption.^ n^
All arc costs are integers between
–C and C.
n^
All arc traversal times are integers between –T and T. Lemma. The algorithm terminates after O(log(nCT)) iterations.^ n^
Proof on next slide. Theorem. The algorithm finds min ratio cycle in O(mn log (nCT)) time.
Docsity.com