You are on page 1of 22

, .

.
.
.

2
16

3
5

10

4
2

14

1 - 7
14.

2
16

3
5

10

4
2

14

1 - 7.
11.


.
.
( ,
).


(greedy) :
/
.

.
.

1 7
1

2
16

3
5

10

4
2

14
12.
. !


n (n )
(
).
:
n
.
() >= 0
< 0

. 0.

16

3
5

10

4
2

3
14

1
1

0
2

6
4

10
8
11

2
5

5
6
4

9
10

11

(
)

.




.


i d(i)
(distanceFromSource(i))

.
d()
.
i
p(i) (predecessor(i)) .
10

2
16

3
5

10

4
2
1

14
[1] [2] [3] [4] [5] [6] [7]
d 0
6 2 16
- 14
p 1 1 1 1
11

2
16

3
5

10

4
2

14

1
1

[1] [2] [3] [4] [5] [6] [7]


d 0
6 2 16 55- 10
- 14
p 1 1 1 3-3 1
12

2
16

3
5

10

4
2

14

1
1

[1] [2] [3] [4] [5] [6] [7]


d 0 66 2 16
9 5- 10
- 14
p 1 1 51 3-3 1
13

2
16

3
5

10

4
2

14

1
1

[1] [2] [3] [4] [5] [6] [7]


d 0
6 2 9 5- 10
- 14
p 1 1 5 3-3 1
14

2
16

3
5

10

4
2

14

1
1

[1] [2] [3] [4] [5] [6] [7]


d 0
6 2 9 5- 10
- 14
12
p 1 1 5 3-3 41

15

16

3
5

10

4
2

14
1

[1] [2] [3] [4] [5] [6] [7]


d 0
6 2 9 5- 10
- 14
12
11
p 1 1 5 33- 416
16

1
1

2
5

5
6
4

10

7 11

[1] [2] [3] [4] [5] [6] [7]


0 6 2 9 5- 10
- 14
12
11
1 1 5 3- 3- 416

17

18

Dijkstra-

Dijkstra- .
d() , p() - 1D .

L .
d() v L
.
v - d() , p() -

19

Dijkstra-
1. (d[]), (p[]), (v[])
(c)
2.
. 0
3. false
4. ( null)

5.
6.
7.

8.

9. 6-
20


O(n) .
O(out-degree) -
d() , p() - .
O(n) - d() , p() .

.
O(n2 + e) = O(n2).

21


L
d() - min ()
, O((n+e) log n)
. O(n) remove min ,
O(e) (d() - )
.
e O(n2) min
.
,
O(n log n + e) .
22