





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
Lecture notes on dijkstra's algorithm with bounded edge weights, using fib-heaps as the data structure. The notes cover the key observation, minor adjustments, and the implementation of insert, deckey, and deletemin operations. The algorithm is used for the single source shortest path problem and is shown to run in time o(v log v + e).
Typology: Study notes
1 / 9
This page cannot be seen from the preview
Don't miss anything!






By using Fib-heaps as our data structure we obtained an algorithm for the Single Source Shortest Path (SPPP) problem that runs in time
O(V log V + E).
Can we do better? Dijkstra’s algorithm can be used to SORT numbers (this is an easy exercise). Hence, Dijkstra’s algorithm cannot do better than O(V log V ) time (the lower bound for sorting). But what if all the weights are (non-negative) integers bounded by a constant C? We can do better! We will exhibit an algorithm that runs in time
O((log C)V + E).
We will not change the algorithm, just the the data structure that supports it. This algorithm has been used at Bell Labs as a subroutine in an algorithm for min-cost flow which assigned clients to nearby copies of websites.
Key Observation: Assume C bounds the edge weights. Assume that Dijk- stra’s algorithm is run. Assume that DELETEMIN removes vertex v which has value d(v). Let w be the very next vertex that is removed by DELTET- MIN. Then d(v) ≤ d(w) ≤ d(v) + C.
Minor Adjustment: We need one minor adjustment in Dijkstra’s algo- rithms. Note that since the bound on the weights is C, and all paths are of length ≤ n we will obtain d(v) ≤ Cn. In the usual Dijkstra’s algorithm we initially set the d(v)’s to be ∞. We will instead set them equal to Cn + 1. Note that the largest integer ever encountered for a value of d() will be Cn+1. We will describe a data structure that supports INSERT, FINDMIN, DELETEMIN, DECKEY.
The data structure itself depends on the number C. We will assume C is a power of 2. Let L = lg C. We describe the data structure.
Bi = { 2 i−^2 ,... , 2 i−^1 − 1 } (for 2 ≤ i ≤ L + 2) ..
. =
BL+3 = { 2 L+1,... , nC + 1}
In general we will denote the endpoints of Bi by [si, mi] where si = mi− 1 + 1. (si stands for Smallest in bucket i, mi stands for Max in bucket i.)
INSERT(x):
Do the comparisons x < si for decreasing i until you get a YES. Now you have s 1 , s 2 ,... , si− 1 ≤ x < si We now know that x should go into Bi− 1.
Link x to the linked list Bi− 1. (Formally we actually link (x, i) so that x ‘knows’ what bucket its in.)
H[i − 1] = H[i − 1] + 1.
END OF ALGORITHM FOR INSERT
The actual cost is dominated by the cost for the comparisons and is O(log L). (We could have used binary search to speed it up to O(log log(L)) but this will not help the analysis.) The most the potential function can increase occurs when we add the element to bucket L + 3. In this case the change in potential is O(log C). So the amortized cost is O(log C).
Note 1.1 There are two ways to decrease the amortized cost of INSERT. Unfortunately they still result in O(log C).
The increase in potential is still O(log L) per insert, so the amortized cost is still O(log L).
DECKEY(x, x′)
Let i be such that x ∈ Bi (this takes O(1) to find since all elements know the bucket they are in).
Do the comparisons x′^ ≥ si? x′^ ≥ si− 1? etc until you get a YES. If x′^ ≥ si then x ∈ Bi then just replace x by x′. If x′^ ∈ B[j], j < i, then
Remove x from B[i]. H[i] = H[i] − 1 Place x′^ into B[j]. H[j] = H[j] + 1.
END OF ALGORITHM FOR DECKEY
The number of comparisons made to find out which bucket to put x′^ into is i − j. So the actual cost is O(i − j). Since x is removed from Bi and placed into Bj , the potential is decreased by α(i − j). Hence the amortized cost is
O(i − j) − α(i − j).
Pick α so that this is O(1).
We now look at DELETEMIN which will be more complicated. Every time DELETEMIN is called we will change the intervals of the buckets and (more important) if the min is found in any bucket other than B 1 then every element in the bucket where the min was found will be moved into a bucket of lower index.
that makes the wrong things not a problem, while maintaining the right thing.
Bi = {dmin + 2i−^2 ,... , min{dmin + 2i−^1 − 1 , mj }}(for 2 ≤ i ≤ j) ..
. =
Bj = {dmin + 2j−^2 ,... , min{dmin + 2j−^1 − 1 , sj+1 − 1 }} Bj+1 = old Bj+ ..
. =
BL+1 = old BL+ BL+2 = old BL+ BL+3 = old BL+
Assume that Bj has b elements in it. Amortized cost:
The last part of the amortized cost is the possible moving of the b − 1 elements in Bj into lower buckets. First note that every one of them will go into a lower indexed bucket: The old Bj had minimal element dmin and had ≤ 2 j−^2 elements in it. Hence the old Bj is contained in
{dmin,... , dmin + 2j−^2 − 1 }.
The new Bj has least element dmin + 2j−^2. Hence every element from the old Bj will get moved to a lower indexed bucket. Note that it is crucial that j 6 = L + 3, which comes from our particular application to Dijkstra’s algorithm with bound C on the edges. For each of the b − 1 elements in Bj (that are not dmin) we ask a number of questions and then place it in a lower indexed bucket. We count this carefully since we are balancing two things:
Let x ∈ Bj (the old Bj ). If we have to make q questions to find out which new bucket it is in, then it is in bucket Bj−q. Hence the potential decreases by αq. The potential change of just dealing with x is q − αq = (1 − α)q. Since we will be taking α > 1 the amortized cost is highest when q is lowest. Hence we assume the worst case where every element is placed into Bj− 1. Then the potential change is at at most (b − 1)(1 − α) (which is negative). The total amortized cost is
O(j + b + b(1 − α)). We take α large enough so that this is O(j) = O(L) = O(log C).