Dijkstra’s Algorithm with two levels of buckets
description
Transcript of Dijkstra’s Algorithm with two levels of buckets
![Page 1: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/1.jpg)
Dijkstra’s Algorithm with two levels of buckets
15.082J & 6.855J & ESD.78JVisualizations
![Page 2: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/2.jpg)
2
Initialize
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Initialize distance labels
0
∞
∞
∞
∞
∞Select the first nonempty lower bucket. Then select an element of the bucket.
∞
23456
Initialize buckets.
0 1 2 3 4 5 6 7 8 9
10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99
1
![Page 3: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/3.jpg)
10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99
0 1 2 3 4 5 6 7 8 9
3
Update
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Scan arcs out of node 1 and update data structures
1
0
∞
∞
∞
∞
∞
∞
234561
8
41
![Page 4: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/4.jpg)
10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99
0 1 2 3 4 5 6 7 8 9
4
Find Min Lower Bucket
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Find min non-empty lower bucket. Select a node in the bucket.
1
0
∞
∞
∞
∞
2
3
456
8
41
2
![Page 5: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/5.jpg)
10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99
0 1 2 3 4 5 6 7 8 9
5
Update
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Scan arcs out of node 2 and update distance labels and buckets.
0
∞
∞
∞
∞
2
3
456
8
41
2
33
54
30
![Page 6: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/6.jpg)
10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99
0 1 2 3 4 5 6 7 8 9
6
Find Min Lower Bucket
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Scan lower bucket for first non-empty bucket. If none exist, then go to scanning upper buckets.
0
∞
∞
3 45
6
8
33
54
30
![Page 7: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/7.jpg)
10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99
0 1 2 3 4 5 6 7 8 9
7
Find Min Upper Bucket
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Scan upper buckets to find the first non-empty bucket. 0
∞
∞
3 45
6
8
33
54
30
![Page 8: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/8.jpg)
0 1 2 3 4 5 6 7 8 9
40-49 50-59 60-69 70-79 80-89 90-99
8
Move contents down
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Adjust bucket numbers of lower buckets and move contents of upper bucket to lower buckets
0
∞
∞
4
6
8
33
54
30
30 31 32 33 34 35 36 37 38 39
30-39
35
![Page 9: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/9.jpg)
40-49 50-59 60-69 70-79 80-89 90-99
30 31 32 33 34 35 36 37 38 39
9
Find Min Lower Bucket
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
Find the first nonempty lower bucket and select a node in the bucket
0
∞
∞
3
4
5 6
8
33
54
30
![Page 10: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/10.jpg)
40-49 50-59 60-69 70-79 80-89 90-99
30 31 32 33 34 35 36 37 38 39
10
Update
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
0
∞
∞
3
4
5 6
8
33
54
30
Scan arcs out of node 5 and update distance labels and buckets.
55
![Page 11: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/11.jpg)
40-49 50-59 60-69 70-79 80-89 90-99
30 31 32 33 34 35 36 37 38 39
11
Find Min Lower Bucket
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
0
3
46
8
33
54
30
55
Find the first nonempty lower bucket and select a node in the bucket
![Page 12: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/12.jpg)
40-49 50-59 60-69 70-79 80-89 90-99
30 31 32 33 34 35 36 37 38 39
12
Update
1
2
3
4
5
6
8
46
22 25
37
41
18
26
25
0
3
46
8
33
54
30
55
Scan arcs out of node 3 and perform updates.
![Page 13: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/13.jpg)
40-49 50-59 60-69 70-79 80-89 90-99
30 31 32 33 34 35 36 37 38 39
13
Find Min Lower Bucket
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
46
8
33
54
30
55
Scan lower buckets looking for a non-empty bucket.
![Page 14: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/14.jpg)
40-49 50-59 60-69 70-79 80-89 90-99
30 31 32 33 34 35 36 37 38 39
14
Find Min Upper Bucket
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
46
8
33
54
30
55
Scan upper buckets looking for a non-empty bucket.
![Page 15: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/15.jpg)
50-59 60-69 70-79 80-89 90-99
30 31 32 33 34 35 36 37 38 39
15
Move contents down
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
8
33
54
30
55
Adjust bucket numbers of lower buckets and move contents of upper bucket to lower buckets.
50 51 52 53 54 55 56 57 58 59
46
![Page 16: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/16.jpg)
60-69 70-79 80-89 90-99
16
Find Min Lower Bucket
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
8
33
54
30
55
Select the min non-empty lower bucket. Select an element from the bucket.
50 51 52 53 54 55 56 57 58 59
4 6
![Page 17: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/17.jpg)
60-69 70-79 80-89 90-99
17
Update
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
8
33
54
30
55
Scan arcs out of node 4 and perform all updates.
50 51 52 53 54 55 56 57 58 59
4 6
![Page 18: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/18.jpg)
60-69 70-79 80-89 90-99
18
Find Min Lower Bucket
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
8
33
54
30
55
Scan lower buckets looking for a non-empty bucket. Select a node of the bucket
50 51 52 53 54 55 56 57 58 59
6
![Page 19: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/19.jpg)
60-69 70-79 80-89 90-99
19
Update
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
8
33
54
30
55
Scan arcs out of node 6, and perform updates
50 51 52 53 54 55 56 57 58 59
6
![Page 20: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/20.jpg)
60-69 70-79 80-89 90-99
20
Termination
1
2 4
5
6
8
46
22 25
37
41
18
26
25
0
8
33
54
30
55
All nodes are permanent. The algorithm terminates with the optimal shortest path tree.
50 51 52 53 54 55 56 57 58 59
![Page 21: Dijkstra’s Algorithm with two levels of buckets](https://reader033.fdocuments.us/reader033/viewer/2022061610/56815aa2550346895dc82884/html5/thumbnails/21.jpg)
MITOpenCourseWarehttp://ocw.mit.edu
15.082J / 6.855J / ESD.78J Network OptimizationFall 2010
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.