200 likes | 306 Views
Follow along with an example from AMO to understand the Radix Heap Algorithm through detailed steps and visualization of the process. Learn how to initialize, insert, select, update, redistribute, and reinsert nodes efficiently.
E N D
15.082 and 6.855J February 25, 2003 Radix Heap Animation
5 2 4 15 2 13 0 1 6 20 0 8 9 3 5 An Example from AMO (with a small change) Initialize distance labels Initialize buckets and their ranges. Insert nodes into buckets. 2 3 47 8 15 16 31 3263 2 0 1 3 4 5 1 6
Select 5 Select the node with minimum distance label 2 4 15 2 13 0 1 1 6 20 0 8 9 3 5 2 3 47 8 15 16 31 3263 2 0 1 3 4 5 1 6
0 Update 13 15 5 Scan arcs out of node 1 and update distance labels. 2 4 15 2 13 1 1 6 20 0 8 9 3 5 0 20 2 3 47 8 15 16 31 3263 2 0 1 3 4 2 5 5 3 4 6
Select 13 15 5 Select the node with minimum distance label 2 4 15 2 13 0 1 1 6 Node 3 has label 0, which is minimum. 20 0 8 9 3 3 5 0 20 2 3 47 8 15 16 31 3263 0 1 2 5 6 3 4
Update 13 15 5 Scan arcs out of node 3 and update distance labels. 2 4 15 2 13 0 1 1 6 20 0 8 9 3 3 5 0 20 9 2 3 47 8 15 16 31 3263 0 1 2 5 6 3 4 5
Select: part 1 13 15 5 Find the first non-empty bucket, by scanning buckets from left to right. 2 4 15 2 13 0 1 1 6 20 0 8 9 3 3 5 0 20 9 2 3 47 8 15 16 31 3263 0 1 2 6 4 5
Select: part 2 13 15 5 Determine the minimum distance value in the bucket, by scanning all nodes in the bucket. 2 4 15 2 13 0 1 1 6 20 0 8 9 3 3 5 d(5) = 9, which is minimum. 0 20 9 2 3 47 8 15 16 31 3263 0 1 2 6 4 5
Select: part 3 13 15 5 Redistribute the range of bucket 5 into the first 4 buckets, starting with value 9. Bucket widths stay the same, except that some may be smaller. 2 4 15 2 13 0 1 1 6 20 0 8 9 3 3 5 0 20 9 11 12 1315 2 3 47 8 15 16 31 3263 0 9 1 10 2 6 4 5
Select: part 4 13 15 5 Reinsert nodes in the correct bucket. Determine the bucket by scanning left. 2 4 15 2 13 0 1 1 6 20 0 8 9 At this point the leftmost bucket is non-empty 3 3 5 0 20 9 2 3 11 12 1315 8 15 16 31 3263 0 9 10 1 2 6 2 5 4 4 5
Select: part 5 13 15 5 Select a node in the leftmost bucket. 2 4 15 2 13 0 1 1 6 20 0 8 9 3 3 5 5 0 20 9 2 3 11 12 1315 8 15 16 31 3263 0 9 10 1 6 2 5 4
Update 13 15 5 Scan arcs out of node 5 and update distance labels. 2 4 15 2 13 0 17 1 1 6 Reinsert nodes in correct buckets by scanning left. 20 0 8 9 3 3 5 5 0 20 9 2 3 11 12 1315 8 15 16 31 3263 0 9 1 10 6 2 6 4
Select: parts 1 and 2 13 15 5 Find the minimum non-empty bucket. 2 4 15 2 13 0 17 1 1 6 Find the minimum distance label in the bucket 20 0 8 9 3 3 5 5 0 20 9 11 12 2 3 1315 8 15 16 31 3263 0 9 1 10 2 6 4
Select: parts 3 and 4 13 15 5 Redistribute bucket ranges in the minimum bucket 2 4 15 2 13 0 17 1 1 6 Reinsert nodes in correct buckets. 20 0 8 9 3 3 5 5 0 20 9 2 3 11 12 15 1315 8 15 16 31 3263 0 13 9 14 1 10 2 2 4 6 4
Select: part 5 13 15 5 Select a node from the leftmost bucket. 2 2 4 15 2 13 0 17 1 1 6 20 0 8 9 3 3 5 5 0 20 9 15 11 12 2 3 1315 8 15 16 31 3263 0 9 13 1 10 14 2 4 6
Update 13 15 5 Scan the arc out of node 2. 2 2 4 15 2 13 0 17 1 1 6 20 0 8 9 3 3 5 5 0 20 9 15 2 3 11 12 1315 8 15 16 31 3263 0 9 13 1 14 10 4 6
Select, Modified rule 1 13 15 5 Find the minimum non-empty bucket 2 2 4 4 15 2 13 0 17 If the bucket has a width of 1, select any node in the bucket. 1 1 6 20 0 8 9 3 3 5 5 0 20 9 15 11 12 2 3 1315 8 15 16 31 3263 0 13 9 10 14 1 4 6
Update 13 15 5 Scan the arc out of node 4 2 2 4 4 15 2 13 0 17 1 1 6 20 0 8 9 3 3 5 5 0 20 9 15 2 3 11 12 1315 8 15 16 31 3263 0 9 13 1 14 10 6
Select: modified rule 2 13 15 5 Find the minimum non-empty bucket 2 2 4 4 15 2 13 If the bucket has a single node, then select the node. 0 17 1 1 6 6 20 0 Modified rules and heuristics often help in practice, but must be used carefully. 8 9 3 3 5 5 0 20 9 11 12 15 2 3 1315 8 15 16 31 3263 0 9 13 10 14 1 6
The algorithm ends 13 15 5 There are no arcs to update. 2 2 4 4 15 2 13 0 17 1 1 6 6 There are no nodes that need to be permanently labeled. 20 0 8 9 3 3 5 5 0 20 9 15 11 12 2 3 1315 8 15 16 31 3263 0 9 13 1 14 10