cs 420: advanced algorithm design and analysis spring...
TRANSCRIPT
![Page 1: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/1.jpg)
CS 420: Advanced Algorithm Design and AnalysisSpring 2015 – Lecture 14
Department of Computer ScienceUniversity of British Columbia
February 26, 2015
1 / 31
![Page 2: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/2.jpg)
AnnouncementsAssignments...
I Sample solutions to Asst 4 (and Midterm I) have been posted
I Asst5...due today
Midterm II...
I Q/A session...next Tuesday (March 03); 5:30-7:00; DMPT310
I Exam...Wednesday (March 04); 5:30-7:00; DMPT 310
I ...on material up to and including today’s class
Readings...
I minimum-cost path problems [Erickson, Chapt 21, 22;Cormen+, Chapt 25 26; ...]
I edit-distance [Erickson, Chapt. 5.5, 6; Kleinberg&Tardos,Chapt. 6.6 & 6.7]
I Goldberg et al,. “Efficient point-to-point shortest pathalgorithms”
2 / 31
![Page 3: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/3.jpg)
Last class...
Min-cost path problems
I all-pairs of endpoints (cont.)I algorithms for dense graphs, using dynamic programming
I matrix min-sum product approach (generalized Bellman-Ford):O(n3 lg n)
I relax constraints on intermediate vertices (Floyd-Warshall):O(n3)
Edit distance problems
I dynamic programming solutions
I reformulation as (single source, single destination) min-costpath problem
3 / 31
![Page 4: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/4.jpg)
Today...
Edit distance problems (cont.)
I reformulation as (single source, single destination) min-costpath problem
I solution by reweighted Dijkstra
Min-cost path problems (cont.)
I Dijkstra modifications for single-source single-destinationproblems
I bi-directional DijkstraI goal-directed Dijkstra
4 / 31
![Page 5: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/5.jpg)
Edit distance Problem
dynamic programming solution:
1. Total cost is O(nm)I each ED-table entry is computed in O(1) time
2. Space can be reduced to O(n + m)I it suffices to keep only two active columns of ED-table
3. Optimal edit script can be reproduced efficientlyI by divide and conquer
5 / 31
![Page 6: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/6.jpg)
Edit Distance Matrix
1
n
2
1 2 m
i
j
6 / 31
![Page 7: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/7.jpg)
Edit Distance Graph
00
0
1
2
i
n
1 2 j m
7 / 31
![Page 8: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/8.jpg)
Edit Distance Graph
00
0
1
2
i
n
1 2 j m
8 / 31
![Page 9: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/9.jpg)
Edit Distance Graph
vi,jvi,j−1
vi−1,jvi−1,j−1
9 / 31
![Page 10: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/10.jpg)
Edit Distance Graph
vi,jvi,j−1
vi−1,jvi−1,j−1
cost(xi,−)
cost(−, yj)
cost(xi, yj)
10 / 31
![Page 11: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/11.jpg)
Edit Distance Graph
00
0
1
2
i
n
1 2 j m
We want to find the min-cost path from v0,0 to vn,m.
11 / 31
![Page 12: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/12.jpg)
Edit Distance Graph
00
0
1
2
i
n
1 2 j m
We want to find the min-cost path from v0,0 to vn,m.
12 / 31
![Page 13: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/13.jpg)
Edit Distance Graph
In general, Dijkstra’s algorithm will find the min-cost path (and thecorresponding edit script) in O(|E |+ |V | lg |V |) = O(nm lg(nm))time.
In the case where we are interested in the minimum length editsequence with no mismatches:
I we can assign horizontal and vertical edges a cost of 1
I and diagonal edges a cost of 0 (if xi matches yj), and ∞otherwise
In this case, any path from vi ,j to vn,m must use at least|(m − j)− (n − i)| horizontal/vertical segments, its cost must beat least |m − n + i − j |. Why?
13 / 31
![Page 14: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/14.jpg)
Edit Distance Graph
So, if we use the function z(vi ,j) = |m − n + i − j | to reweight thegraph, as c(u, v) = c(u, v)− z(u) + z(v):
I horizontal and vertical edges that point towards the diagonalthrough vn,m have their cost reduced (by 1) to zero
I horizontal and vertical edges that point away from thediagonal through vn,m have their cost increased (by 1) to two
I the weight of every diagonal edge is unchanged
I all paths from vi ,j to vn,m have their cost reduced by|m − n + i − j |
14 / 31
![Page 15: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/15.jpg)
Edit Distance Graph
00
0
1
2
n
1 2 m
Red edges have cost increased to 2, green edges have costdecreased to 0.
15 / 31
![Page 16: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/16.jpg)
Edit Distance Graph
Dijkstra’s algorithm will find vertices at (reweighted) cost1, 2, . . . , d from v0,0, where the edit-distance D is |m− n|+ d . So,explored vertices are confined to |m − n|+ d diagonals, each oflength min{n,m}.
16 / 31
![Page 17: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/17.jpg)
Edit Distance Graph
00
0
n
mm− nd/2
d/2
Range of vertices explored by Dijkstra
17 / 31
![Page 18: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/18.jpg)
Edit Distance Graph
00
0
n
mm− nd/2
d/2
Typical path of (reweighted) cost 0.
18 / 31
![Page 19: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/19.jpg)
Single-source single-destination min-cost paths
The example of the edit-distance graph illustrates two importantgeneral modifications of Dijkstra’s algorithm that applies tosingle-source single-destination min-cost path problems:
1. bi-directional Dijkstra: run Dijkstra’s algorithm from both thesource and destination, until the wavefronts collide
2. goal-directed Dijkstra: use some estimate, b(v), of thedistance from all intermediate nodes v to the destination t, toguide the exploration of nodes (using a reweighted graph)
19 / 31
![Page 20: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/20.jpg)
Single-source single-destination min-cost paths
In general, it suffices for the estimate b to satisfy two properties:
1. admissible: b(v) is a lower bound (underestimate) on δ(v , t)
2. consistent: b(u)− b(v) ≤ c(u, v)
If these hold then we can reweight the graph, byc(u, v) = c(u, v)− b(u) + b(v), and all edge-weights remainnon-negative (by consistency).
20 / 31
![Page 21: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/21.jpg)
Single-source single-destination min-cost paths
In the reweighted graph Dijkstra’s algorithm always explores thenext unexplored vertex v that minimizes the current d-value, whichmust equal
δ(s, v) = δ(s, v)− b(s) + b(v)
This, of course, is equivalent to choosing v that minimizesdS [v ] + b(v)which corresponds to the A∗ heuristic for graph search.
21 / 31
![Page 22: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/22.jpg)
Single-source single-destination min-cost paths
If we were clairvoyant, we could choose b(v) = δ(v , t). In thiscase, all edges on any min-cost path from s to t would have theirweight reduced to zero. So Dijkstra would find one such path intime proportional to the length of the path.
Without a crystal ball, how can we construct admissible andconsistent path-cost estimates?
22 / 31
![Page 23: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/23.jpg)
Single-source single-destination search in massive graphs
What if we want to give point-to point driving directions on a largemap?
I use Dijkstra
I use bidirectional DijkstraI use goal-directed (bidirectional) Dijkstra (A∗)
I with path estimates based on Euclidean distance– not very effective in practice
I with path estimates based on landmarks
23 / 31
![Page 24: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/24.jpg)
Single-source single-destination search in massive graphs
Some figures from a talk by Andrew Goldberg (MicrosoftResearch):
http://www.slideshare.net/csclub/andrew-goldberg-an-efficient-pointtopoint-shortest-path-algorithm
24 / 31
![Page 25: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/25.jpg)
Landmark based estimates
I Choose a small number of well-spaced vertices (landmarks)and compute shortest paths from all vertices to all landmarks.
I If δ(v , Li ) denotes the distance from v to landmark Li , thenestimate δ(u, v) by maxi{δ(u, Li )− δ(v , Li )}.
I This estimateI is guaranteed to be a lower bound on δ(u, v), by the triangle
inequalityI will be reasonably accurate if some landmark aligns well with
the shortest path from u to v .
25 / 31
![Page 26: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/26.jpg)
Landmark based estimates
26 / 31
![Page 27: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/27.jpg)
Landmark based estimates
t
s
27 / 31
![Page 28: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/28.jpg)
Landmark based estimates
t
s
L2
L1
L3
28 / 31
![Page 29: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/29.jpg)
Landmark based estimates
t
s
L
29 / 31
![Page 30: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/30.jpg)
Landmark based estimates
t
sL
30 / 31
![Page 31: CS 420: Advanced Algorithm Design and Analysis Spring …kirk/cs420/lectures/Lecture*14-compressed.pdf · CS 420: Advanced Algorithm Design and Analysis Spring 2015 { Lecture 14 Department](https://reader031.vdocuments.us/reader031/viewer/2022030906/5b4cd9f47f8b9a691e8d89d8/html5/thumbnails/31.jpg)
Coming up...
Min-cost path problems
I issues related to real-world constraintsI robustness (failure tolerance)I single-source single destination queries
I issues motion planning (continuous path problems)I paths on terrainsI obstacle avoidanceI curvature constraints
31 / 31