Reductions and Decomposition
Solving problems by reducing them to other problems.
1
Kevin Lin, with thanks to many others.
DAG Shortest Paths
Given a weighted DAG (possibly negative edge weights), find the single-source shortest paths tree from s to every other vertex in the graph.
Your algorithm should be faster than Dijkstra’s algorithm.
2
B
C
A
s
1
5
D
-4
2
4
0
1
2
4
Q
DAG Shortest Paths
Topological ordering.
Topological ordering algorithm:
3
B
C
A
s
1
5
D
-4
2
4
0
1
2
4
A
Positive Integer-Weighted Shortest Paths
Given a weighted, directed graph (possibly cyclic) with positive integer edge weights, find the single-source shortest paths tree from s to every other vertex in the graph.
Your algorithm should be asymptotically faster than Dijkstra’s algorithm on cyclic graphs.
Dijkstra’s: O(E log V) because of PQ operations (log V) part of the runtime.
O(log V)? O(E)?
4
Q
B
C
A
s
5
5
D
1
2
1
0
1
2
4
Positive Integer-Weighted Shortest Paths
Given a weighted, directed graph (possibly cyclic) with positive integer edge weights, find the single-source shortest paths tree from s to every other vertex in the graph.
Your algorithm should be asymptotically faster than Dijkstra’s algorithm on cyclic graphs.
Two contrasting ways of approaching the problem: algorithmic or reduction.
Both result in O(E) runtime.
See the external demo link in the upper-righthand corner.
5
A
DAG Longest Paths
Given a weighted DAG (possibly negative edge weights), find the single-source longest paths tree from s to every other vertex in the graph.
Give the runtime of your algorithm.
6
Q
B
C
A
s
5
5
D
1
2
1
0
1
2
4
DAG Longest Paths
Given a weighted DAG (possibly negative edge weights), find the single-source longest paths tree from s to every other vertex in the graph.
Give the runtime of your algorithm.
Reduction approach:
7
A
Vertex Weights in Shortest Paths
How would you model vertex weights for shortest paths problems?
8
Q
v
b
e
x
Shortest Paths (Robert Sedgewick, Kevin Wayne/Princeton)
a
c
d
Vertex Weights in Shortest Paths
How would you model vertex weights for shortest paths problems?
The answer to this will help with seam carving since the energy function is defined per pixel.
Place weights on c, d, and e. (Why doesn’t it work to only place weights on a and b instead?)
Other answers might depend on the particular problem you want to solve.
9
A
v
b
e
x
Shortest Paths (Robert Sedgewick, Kevin Wayne/Princeton)
a
c
d
10
11
Longest Simple Paths in Arbitrary Graphs
It turns out that finding the longest simple path (containing no cycles) in a directed graph (possibly cyclic) is a “hard” problem. Best known algorithms involve brute force search.
Based on what we know about DAG longest paths, explain why this is much harder.
12
Q
Longest Simple Paths in Arbitrary Graphs
It turns out that finding the longest simple path (containing no cycles) in a directed graph (possibly cyclic) is a “hard” problem. Best known algorithms involve brute force search.
Based on what we know about DAG longest paths, explain why this is much harder.
13
A