20
1 15.082 and 6.855J February 25, 2003 Radix Heap Animation

15.082 and 6.855J February 25, 2003

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: 15.082 and 6.855J  February 25, 2003

1

15.082 and 6.855J February 25, 2003

Radix Heap Animation

Page 2: 15.082 and 6.855J  February 25, 2003

2

An Example from AMO (with a small change)

1

0 1 2

3

47

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Initialize distance labels

Insert nodes into buckets.

Initialize buckets and their ranges.

0

23456

Page 3: 15.082 and 6.855J  February 25, 2003

3

Select

1

0 1 2

3

47

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Select the node with minimum distance label

0

23456

1

Page 4: 15.082 and 6.855J  February 25, 2003

4

Update

3

0 1 2

3

47

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Scan arcs out of node 1 and update distance labels.

0

23456

1

13

2

0

15

4

20

5

Page 5: 15.082 and 6.855J  February 25, 2003

5

Select

3

0 1 2

3

47

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Select the node with minimum distance label 0

6

1

24

5

Node 3 has label 0, which is minimum.

13

0

15

20

3

Page 6: 15.082 and 6.855J  February 25, 2003

6

Update

3

0 1 2

3

47

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Scan arcs out of node 3 and update distance labels.

0

6

1

24

5

13

0

15

20

3

9

5

Page 7: 15.082 and 6.855J  February 25, 2003

7

Select: part 1

0 1 2

3

47

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Find the first non-empty bucket, by scanning buckets from left to right.

0

6

1

24

13

0

15

20

3

9

5

Page 8: 15.082 and 6.855J  February 25, 2003

8

Select: part 2

0 1 2

3

47

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Determine the minimum distance value in the bucket, by scanning all nodes in the bucket.

0

6

1

24

13

0

15

20

3

9

5

d(5) = 9, which is minimum.

Page 9: 15.082 and 6.855J  February 25, 2003

9

Select: part 3

0 1 2

3

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

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.

0

6

1

24

13

0

15

20

3

9

5

9 10 11 12

471315

Page 10: 15.082 and 6.855J  February 25, 2003

10

Select: part 4

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Reinsert nodes in the correct bucket.

Determine the bucket by scanning left.

0

6

1

24

13

0

15

20

3

9

5

9 10 11 12

425

At this point the leftmost bucket is non-empty

Page 11: 15.082 and 6.855J  February 25, 2003

11

Select: part 5

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Select a node in the leftmost bucket.

0

6

1

13

0

15

20

3

9

9 10 11 12

425

5

Page 12: 15.082 and 6.855J  February 25, 2003

12

Update

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Scan arcs out of node 5 and update distance labels. 0

6

1

13

0

15

20

3

9

9 10 11 12

42

5

17

6

Reinsert nodes in correct buckets by scanning left.

Page 13: 15.082 and 6.855J  February 25, 2003

13

Select: parts 1 and 2

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Find the minimum non-empty bucket.

01

13

0

15

20

3

9

9 10 11 12

42

5

17

6

Find the minimum distance label in the bucket

Page 14: 15.082 and 6.855J  February 25, 2003

14

Select: parts 3 and 4

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Redistribute bucket ranges in the minimum bucket 0

1

13

0

15

20

3

9

9 10 11 12

42

5

17

6

Reinsert nodes in correct buckets.

13 14 15

2 4

Page 15: 15.082 and 6.855J  February 25, 2003

15

Select: part 5

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Select a node from the leftmost bucket.

01

13

0

15

20

3

9

9 10 11 12

5

17

6

13 14 15

2 4

2

Page 16: 15.082 and 6.855J  February 25, 2003

16

Update

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Scan the arc out of node 2.

01

13

0

15

20

3

9

9 10 11 12

5

17

6

13 14 15

4

2

Page 17: 15.082 and 6.855J  February 25, 2003

17

Select, Modified rule 1

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Find the minimum non-empty bucket

01

13

0

15

20

3

9

9 10 11 12

5

17

6

13 14 15

4

2

If the bucket has a width of 1, select any node in the bucket.

4

Page 18: 15.082 and 6.855J  February 25, 2003

18

Update

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Scan the arc out of node 4

01

13

0

15

20

3

9

9 10 11 12

5

17

6

13 14 15

2 4

Page 19: 15.082 and 6.855J  February 25, 2003

19

Select: modified rule 2

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

Find the minimum non-empty bucket

01

13

0

15

20

3

9

9 10 11 12

5

17

6

13 14 15

2 4

If the bucket has a single node, then select the node.

6

Modified rules and heuristics often help in practice, but must be used carefully.

Page 20: 15.082 and 6.855J  February 25, 2003

20

The algorithm ends

0 1 2

3

1315

8 15

16 31

3263

1

2 4

53

6

13

5

2

8

15

20

9

0

There are no arcs to update.

01

13

0

15

20

3

9

9 10 11 12

5

17

13 14 15

2 4

There are no nodes that need to be permanently labeled.

6