• No results found

CS711008Z Algorithm Design and Analysis

N/A
N/A
Protected

Academic year: 2022

Share "CS711008Z Algorithm Design and Analysis"

Copied!
128
0
0

Loading.... (view fulltext now)

Full text

(1)

CS711008Z Algorithm Design and Analysis

Lecture 7. Binary heap, binomial heap, and Fibonacci heap 1

Dongbo Bu

Institute of Computing Technology Chinese Academy of Sciences, Beijing, China

(2)

. . . . .. . .. .. . .. . . . . . .

Outline

Introduction to priority queue

Various implementations of priority queue:

Linked list: a list having n items is too long to support efficient ExtractMin and Insert operations simultaneously;

Binary heap: using atreerather than a linked list;

Binomial heap: allowingmultiple trees rather thana single treeto support efficient Union operation

Fibonacci heap: implement DecreaseKey via simply cutting an edgerather thanexchanging nodes, and control a “bushy” tree shape via allowingat most one child losing for any node.

(3)

Priority queue

(4)

. . . . .. . .. .. . .. . . . . . .

Priority queue: motivation

Motivation: It is usually a case to extract the minimum from a set S of n numbers, dynamically.

Here, the word “dynamically” means that on S, we might perform Insertion, Deletion and DecreaseKey operations.

The question is how to organize the data to efficiently support these operations.

(5)

Priority queue

Priority queue is anabstract data type similar to stack or queue, but each element has a priority associated with its name.

A min-oriented priority queue must support the following core operations:

1 H=MakeHeap(): to create a new heap H;

2 Insert(H, x): to insert into H an element x together with its priority

3 ExtractMin(H): to extract the element with the highest priority;

4 DecreaseKey(H, x, k): to decrease the priority of element x;

5 Union(H1, H2): return a new heap containing all elements of heaps H1 and H2, and destroy the input heaps

(6)

. . . . .. . .. .. . .. . . . . . .

Priority queue is very useful

Priority queue has extensive applications, such as:

Dijkstra’s shortest path algorithm Prim’s MST algorithm

Huffman coding A searching algorithm HeapSort

...

(7)

An example: Dijkstra’s algorithm

(8)

. . . . .. . .. .. . .. . . . . . .

Dijkstra’s algorithm [1959]

Dijkstra(G, s)

1: key(s) = 0; //key(u) stores an upper bound of the shortest-path weight from s to u;

2: P Q.Insert (s);

3: S ={s}; // Let S be the set of explored nodes;

4: for all node v ̸= s do 5: key(v) = +∞;

6: P Q.Insert (v); // n times 7: end for

8: while S ̸= V do

9: v = P Q.ExtractMin();// n times 10: S = S∪ {v};

11: for each w /∈ S and < v, w >∈ E do 12: if key(v) + d(v, w) < key(w) then

13: P Q.DecreaseKey(w, key(v) + d(v, w));// m times 14: end if

15: end for 16: end while

Here P Q denotes a min-priority queue.

(9)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(10)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(11)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s

DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(12)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(13)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(14)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a

DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(15)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(16)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(17)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b

DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(18)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(19)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

(20)

. . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . .

. .

. . . . .

Dijkstra’s algorithm: an example

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44 S ={}

P Q ={s(0), a(∞), b(∞), c(∞), d(∞), e(∞), f(∞), t(∞)}

0 ∞

∞ ∞

ExtractMin returns s DecreaseKey(a, 9) DecreaseKey(b, 14) DecreaseKey(c, 15)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

∞ ∞

∞ S ={s}

P Q ={a(9), b(14), c(15), d(∞), e(∞), f(∞), t(∞)}

ExtractMin returns a DecreaseKey(d, 33)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

33

∞ ∞

∞ S ={s, a}

P Q ={b(14), c(15), d(33), e(∞), f(∞), t(∞)}

ExtractMin returns b DecreaseKey(d, 32) DecreaseKey(e, 44)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

44 ∞

∞ S ={s, a, b}

P Q ={c(15), d(32), e(44), f(∞), t(∞)}

ExtractMin returns c

DecreaseKey(e, 35) DecreaseKey(t, 59)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

35 ∞

59 S ={s, a, b, c}

P Q ={d(32), e(35), t(59), f(∞)}

ExtractMin returns d DecreaseKey(t, 51) DecreaseKey(e, 34)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34 ∞

51 S ={s, a, b, c, d}

P Q ={e(34), t(51), f(∞)}

ExtractMin returns e DecreaseKey(f, 45)

DecreaseKey(t, 50)

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e}

P Q ={f(45), t(50)}

ExtractMin returns f

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f}

P Q ={t(50)}

s a

b

c

d

e

f

t 9

14 15

24 18

30 20

2

11

16 6 19

44

0 9

14

15

32

34

45

50 S ={s, a, b, c, d, e, f, t}

P Q ={}

References

Related documents

The particular approach to this production proposal will be determined in individual tutorials with the course tutor but could include set, costume, lighting and sound design ideas,

Paul Weber thanks Chris Featherstone, assistant secretary, for her help soliciting nominations and with procedures for the Band Boosters Board of Directors Election. Paul and

The beetles found at the Lebanese, Spanish, French and Myanmar amber sites had not participated in the resin production that resulted in early and mid-Cretaceous ambers..

depression, EBPs for providing multidisciplinary mental health outreach services, collaborative and integrated mental and physical health care, and antidepressant medications

Lump or sensation in throat Food sticking Bloating Belching Diarrhea Constipation Rectal bleeding Black or tarry stools Hidden blood in stool Excessive rectal gas/flatus Loss

These variables included population density, number of drop-off sites, annual tons of municipal solid waste (MSW) sent to landfills and processing facilities, percentage of

a) In heavy civil/utility Construction prime contracts, there was disparity for all M/WBE groups except African American-owned firms, for whom there was no Construction