Download presentation

Presentation is loading. Please wait.

Published byMike Blessing Modified over 2 years ago

1
15.082J & 6.855J & ESD.78J Shortest Paths 2: Bucket implementations of Dijkstra’s Algorithm R-Heaps

2
2 A Simple Bucket-based Scheme Let C = 1 + max(c ij : (i,j) ∈ A); then nC is an upper bound on the minimum length path from 1 to n. RECALL: When we select nodes for Dijkstra's Algorithm we select them in increasing order of distance from node 1. SIMPLE STORAGE RULE. Create buckets from 0 to nC. Let BUCKET(k) = {i ∈ T: d(i) = k}. Buckets are sets of nodes stored as doubly linked lists. O(1) time for insertion and deletion.

3
3 Dial’s Algorithm u Whenever d(j) is updated, update the buckets so that the simple bucket scheme remains true. u The FindMin operation looks for the minimum non-empty bucket. u To find the minimum non-empty bucket, start where you last left off, and iteratively scan buckets with higher numbers. Dial’s Algorithm

4
4 Running time for Dial’s Algorithm C = 1 + max(c ij : (i,j) ∈ A). u Number of buckets needed. O(nC) u Time to create buckets. O(nC) u Time to update d( ) and buckets. O(m) u Time to find min. O(nC). u Total running time. O(m+ nC). u This can be improved in practice; e.g., the space requirements can be reduced to O(C).

5
5 Additional comments on Dial’s Algorithm u Create buckets when needed. Stop creating buckets when each node has been stored in a bucket. u Let d* = max {d*(j): j ∈ N}. Then the maximum bucket ever used is at most d* + C. Suppose j ∈ Bucket( d* + C + 1) after update(i). But then d(j) = d(i) + c ij ≤ d* + C d*d*+1 j d*+2d*+3 d*+Cd*+C+1 ∅

6
A 2-level bucket scheme u Have two levels of buckets. Lower buckets are labeled 0 to K-1 (e.g., K = 10) Upper buckets all have a range of K. First upper bucket’s range is K to 2K – 1. Store node j in the bucket whose range contains d(j). 6 0123456789 10-1920-2930-3940-4950-5960-6970-7980-8990-99 2 1 2 1 5 distance label 3 21 5

7
Find Min u FindMin consists of two subroutines SearchLower: This procedure searches lower buckets from left to right as in Dial’s algorithm. When it finds a non-empty bucket, it selects any node in the bucket. SearchUpper: This procedure searches upper buckets from left to right. When it finds a bucket that is non-empty, it transfers its elements to lower buckets. 7 FindMin If the lower buckets are non-empty, then SearchLower; Else, SearchUpper and then SearchLower.

8
More on SearchUpper u SearchUpper is carried out when the lower buckets are all empty. u When SearchUpper finds a non-empty bucket, it transfers its contents to lower buckets. First it relabels the lower buckets. 8 10-1920-2930-3940-4950-5960-6970-7980-8990-99 0123456789 4 30313233343536373839 3 5 3 33 5 30 4 54 2-Level Bucket Algorithm

9
Running Time Analysis u Time for SearchUpper: O(nC/K) O(1) time per bucket u Number of times that the Lower Buckets are filled from the upper buckets: at most n. u Total time for FindMin in SearchLower O(nK); O(1) per bucket scanned. u Total Time for scanning arcs and placing nodes in the correct buckets: O(m) u Total Run Time: O(nC/K + nK + m). Optimized when K = C.5 O(nC.5 + m) 9

10
More on multiple bucket levels u Running time can be improved with three or more levels of buckets. u Runs great in practice with two levels u Can be improved further with buckets of range (width) 1, 1, 2, 4, 8, 16 … Radix Heap Implementation 10

11
11 A Special Purpose Data Structure u RADIX HEAP: a specialized implementation of priority queues for the shortest path problem. u A USEFUL PROPERTY (of Dijkstra's algorithm): The minimum temporary label d( ) is monotonically non-decreasing. The algorithm labels node in order of increasing distance from the origin. u C = 1 + max length of an arc

12
12 Radix Heap Example 1 24 53 6 13 5 2 8 15 20 9 0 012-34-7 8-1516-3132-63 Buckets: bucket sizes grow exponentially ranges change dynamically Radix Heap Animation

13
Analysis: FindMin u Scan from left to right until there is a non-empty bucket. If the bucket has width 1 or a single element, then select an element of the bucket. Time per find min: O(K), where K is the number of buckets 13 01 2-34-7 8-1516-3132-63 2 4 5

14
Analysis: Redistribute Range u Redistribute Range: suppose that the minimum non-empty bucket is Bucket j. Determine the min distance label d* in the bucket. Then distribute the range of Bucket j into the previous j-1 buckets, starting with value d*. Time per redistribute range: O(K). It takes O(1) steps per bucket. Time for determining d*: see next slide. 14 01 2-34-7 8-1516-3132-63 2 4 5 91011-1213-15 d(5) = 9 (min label)

15
Analysis: Find min d(j) for j in bucket u Let b the the number of items in the minimum bucket. The time to find the min distance label of a node in the bucket is O(b). Every item in the bucket will move to a lower index bucket after the ranges are redistributed. Thus, the time to find d* is dominated by the time to update contents of buckets. We analyze that next 15

16
Analysis: Update Contents of Buckets u When a node j needs to move buckets, it will always shift left. Determine the correct bucket by inspecting buckets one at a time. O(1) whenever we need to scan the bucket to the left. For node j, updating takes O(K) steps in total. 16 01 2-34-7 8-1516-3132-63 2 4 91011-1213-15 d(5) = 9 5

17
Running time analysis u FindMin and Redistribute ranges O(K) per iteration. O(nK) in total u Find minimum d(j) in bucket Dominated by time to update nodes in buckets u Scanning arcs in Update O(1) per arc. O(m) in total. u Updating nodes in Buckets O(K) per node. O(nK) in total u Running time: O(m + nK) O(m + n log nC) u Can be improved to O(m + n log C) 17

18
18 Summary u Simple bucket schemes: Dial’s Algorithm u Double bucket schemes: Denardo and Fox’s Algorithm u Radix Heap: A bucket based method for shortest path buckets may be redistributed simple implementation leads to a very good running time unusual, global analysis of running time

19
MITOpenCourseWare http://ocw.mit.edu 15.082J / 6.855J / ESD.78J Network Optimization Fall 2010 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.http://ocw.mit.edu/terms

Similar presentations

OK

Chapter 4 Shortest Path Label-Setting Algorithms Introduction & Assumptions Applications Dijkstra’s Algorithm.

Chapter 4 Shortest Path Label-Setting Algorithms Introduction & Assumptions Applications Dijkstra’s Algorithm.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on bluetooth network security Ppt on group development model Ppt on harmful effects of drinking alcohol Ppt on barack obama leadership skills Ppt on milk products for students Ppt on rural entrepreneurship Ppt on regional rural banks in india Ppt on save environment in hindi Appt only Ppt on soft skills for bpo