• Tidak ada hasil yang ditemukan

Design and Analysis of Computer Algorithm Additional Note

N/A
N/A
Protected

Academic year: 2018

Membagikan "Design and Analysis of Computer Algorithm Additional Note"

Copied!
26
0
0

Teks penuh

(1)

Design and Analysis of Computer Algorithm

1

Design and Analysis of

Computer Algorithm

Additional Note

Pradondet Nilagupta

Department of Computer Engineering

(2)

Design and Analysis of Computer Algorithm

March 17, 2009

2

(3)

Design and Analysis of Computer Algorithm

March 17, 2009

3

Single Source Shortest Path

Given a (un)weighted, directed graph G = {V, E}, in

which each edge has a non-negative cost (weight)

Problem: Determine the cost of the shortest path from

the source vertex to every other vertex V

The

length

of a path is the sum of the costs of the

edges on the path

Why not find path to just one particular destination?

(4)

Design and Analysis of Computer Algorithm

March 17, 2009

4

Dijkstra’s Algorithm

Maintain a set S of vertices whose shortest distance from

the source is already known

Initially S contains only source vertex

At each step, we add to S a remaining vertex w whose

distance from the source is as short as possible

Assuming all edges have non-negative costs, we can

always find a shortest path from the source to v that

passes only through vertices in S (

special path

)

At every step we use an array to record the length of the

shortest special path to each vertex

(5)

Design and Analysis of Computer Algorithm

March 17, 2009

8

An Example

inf

2

7

5

4

1

4

3

4

1

2

inf

a

d

5

inf

b

f

s

inf

0

7

e

c

(6)

Design and Analysis of Computer Algorithm

March 17, 2009

9

2

7

5

4

1

4

3

4

1

2

2

inf

a

d

5

5

b

f

s

inf

0

7

e

c

(7)

Design and Analysis of Computer Algorithm

March 17, 2009

10

2

7

5

4

1

4

3

4

1

2

2

9

a

d

5

4

b

f

s

inf

0

7

e

c

(8)

Design and Analysis of Computer Algorithm

March 17, 2009

11

2

7

5

4

1

4

3

4

1

2

2

8

a

d

5

4

b

f

s

inf

0

7

e

c

(9)

Design and Analysis of Computer Algorithm

March 17, 2009

12

2

7

5

4

1

4

3

4

1

2

2

8

a

d

5

4

b

f

s

inf

0

7

e

c

(10)

Design and Analysis of Computer Algorithm

March 17, 2009

13

2

7

5

4

1

4

3

4

1

2

2

8

a

d

5

4

b

f

s

14

0

7

e

c

(11)

Design and Analysis of Computer Algorithm

March 17, 2009

14

2

7

5

4

1

4

3

4

1

2

2

8

a

d

5

4

b

f

s

7

13

0

e

c

(12)

Design and Analysis of Computer Algorithm

March 17, 2009

15

2

7

5

4

1

4

3

4

1

2

2

8

a

d

5

4

b

f

s

7

13

0

e

c

(13)

Design and Analysis of Computer Algorithm

March 17, 2009

16

Shortest Path Tree

The unique simple path from

s

to

v

in the tree is a shortest

path from

s

to

v

.

2

8

a

d

f

e

c

b

s

3

5

2

2

4

4

13

0

4

(14)

Design and Analysis of Computer Algorithm

March 17, 2009

17

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

23

(15)

Design and Analysis of Computer Algorithm

March 17, 2009

18

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

23

(16)

Design and Analysis of Computer Algorithm

March 17, 2009

19

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

23

(17)

Design and Analysis of Computer Algorithm

March 17, 2009

20

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

23

(18)

Design and Analysis of Computer Algorithm

March 17, 2009

21

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

23

(19)

Design and Analysis of Computer Algorithm

March 17, 2009

22

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

23

(20)

Design and Analysis of Computer Algorithm

March 17, 2009

23

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

23

(21)

Design and Analysis of Computer Algorithm

March 17, 2009

24

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

(22)

Design and Analysis of Computer Algorithm

March 17, 2009

25

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

(23)

Design and Analysis of Computer Algorithm

March 17, 2009

26

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

(24)

Design and Analysis of Computer Algorithm

March 17, 2009

27

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

(25)

Design and Analysis of Computer Algorithm

March 17, 2009

28

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

end of for-loop Until | B | == | V |.

4

(26)

Design and Analysis of Computer Algorithm

March 17, 2009

29

for each vV,

k [v ] ← infinity; n[v] ← (v,v); k[ source ] ← 0;

Build a heap for all values in the array k. S← {}, T ← {}.

Repeat

Find the vertex v with minimum value in heap using extract_min. Insert v into S.

Insert n[v] into T

For each u such that (v,u)∈ E,

if k[v] plus the weight of (v,u) is less than k[u], then reduce k[u] to k[v] + weight_of ( (v,u) ), and n[u] ← (v , u).

Referensi

Dokumen terkait

Universitas Negeri

[r]

Inisiator penerapan Syariat tidak datang dari kelompok Islam main- stream di Kota Tasikmalaya, seperti Muhammadiyah, NU, dan Persis, tapi justru datang dari kelompok-kelompok Islam

Perusahaan merupakan distributor resmi dari produk yang sudah dikenal kualitasnya,.Hal ini dianggap sebagai kekuatan karena pelanggan akan memiliki kepercayaan yang lebih

Sofyan, Syahril, Materi Kuliah Teknik Pembuatan Akta 3, 2015 Subekti, Hukum Pembuktian, Pradnya Paramitha, Jakarta, 2005. Sumardjono, Maria S.W., Kebijakan Pertanahan

1) Memerintah semua penghuni gedung supaya tetap tenang dan mengumumkan bahwa ada kejadian di lantai...Gedung... 2) Mengkoordinir evaluasi karyawan melalui komandan –

Pada penelitian tersebut pengalaman masa lampau pada sebuah perusahaan dioperasionalkan oleh dua variabel, yaitu tingkat kepuasan dari pembelian lampau dengan mengacu pada

[r]