Shortest Path in Directed Graphs: Dijkstra's Algorithm, Slides of Computer Science

The concept of shortest paths in directed graphs, focusing on dijkstra's algorithm. It covers the basics of directed graphs, shortest path networks, and the existence and properties of shortest paths. The document also provides an overview of dijkstra's algorithm, its proof of correctness, and related topics such as priority queues and heaps.

Typology: Slides

2012/2013

Uploaded on 03/21/2013

dharmaveer
dharmaveer 🇮🇳

4.5

(4)

54 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Greed: Shortest Path
s
3
t
2
6
7
4
5
23
18
2
9
14
15 5
30
20
44
16
11
6
19
6
2
1
3
8
2
6
7
4
5
Directed Graph
Directed graph: G = (V, E) .
V = set of vertices or nodes.
E V ×V = set of edges or arcs.
n = |V|, m = |E|.
Directed path: s - 2 - 3 - 5 - t.
simple
Directed cycle: 5 - 4 - 3 - 5.
3
Networks
communication
Network
telephone exchanges,
computers, satellites
Nodes Arcs
cables, fiber optics,
microwave relays
Flow
voice, video,
packets
circuits gates, registers,
processors wires current
mechanical joints rods, beams, springs heat, energy
hydraulic reservoirs, pumping
stations, lakes pipelines fluid, oil
financial stocks, currency transactions money
transportation airports, rail yards,
street intersections highways, railbeds,
airway routes
freight,
vehicles,
passengers
4
Shortest Path Network
Shortest path network: (V, E, s, t, c) .
Directed graph (V, E).
Source s V, sink t V.
Arc costs c(v, w).
Cost of path = sum of arc costs in path. Cost of path s -2 -3 -5 -t
= 9 + 23 + 2 + 16
= 48.
s
3
t
2
6
7
4
5
23
18
2
9
14
15 5
30
20
44
16
11
6
19
6
Docsity.com
pf3

Partial preview of the text

Download Shortest Path in Directed Graphs: Dijkstra's Algorithm and more Slides Computer Science in PDF only on Docsity!

Greed: Shortest Path

s

3

t

2

6

7

4

5

(^2318)

2

9

14 15

5

30 20

44

11 16

6

19

6

1

3

8

2

6

7

4

5

Directed Graph

Directed graph: G = (V, E).

n^

V = set of vertices or nodes. n^

E

V

×

V = set of edges or arcs.

n^

n = |V|, m = |E|. n^

Directed path: s - 2 - 3 - 5 - t.

-^

simple

n^

Directed cycle: 5 - 4 - 3 - 5.

3

Networks

communication

Network

telephone exchanges,computers, satellites

Nodes

Arcs

cables, fiber optics,microwave relays

Flow

voice, video,packets

circuits

gates, registers,processors

wires

current

mechanical

joints

rods, beams, springs

heat, energy

hydraulic

reservoirs, pumpingstations, lakes

pipelines

fluid, oil

financial

stocks, currency

transactions

money

transportation

airports, rail yards,street intersections

highways, railbeds,airway routes

freight,vehicles,passengers

Shortest Path Network

Shortest path network: (V, E, s, t, c).

n^

Directed graph (V, E). n^

Source s

V, sink t

V.

n^

Arc costs c(v, w). n^

Cost of path = sum of arc costs in path.

Cost of path s - 2 - 3 - 5 - t

s

3

t

2

6

7

4

5

(^2318)

2

9

14 15

5

30 20

44

11 16

6

19

6

Docsity.com

5

Shortest Path

Shortest path problem. (CLR 25.1-25.2)

n^

Shortest path network (V, E, s, t, c). n^

Find shortest directed path from s to t.

Assumptions.

n^

Network contains directed path from s to every other node. n^

Network does not contain a negative cost cycle.

Application.

n^

Online directions.

3 4

5

-6 7

Shortest Path: Existence

Existence. If some path from s to v contains a negative cost cycle,there does not exist a shortest path. Otherwise, there exists a shortests-v that is simple.

If negative cycle, can produce arbitrarily negative path bytraversing cycle enough times.

If no negative cycle, can remove cycles without increasing cost.

s

v

C c(C) < 0

7

Shortest Path: Properties

Optimal substructure property. All sub-paths of shortest paths areshortest paths.

n^

Let P

1

be x-y sub-path of shortest s-v path P.

n^

Let P

2

be any x-y path.

n^

c(P

c(P

), otherwise P 2

not shortest s-v path.

Triangle inequality.

n^

Let d*(v, w) be the length of the shortest path from v to w. n^

Then, d*(v, w)

d(v, x) + d(x, w)

v

w

x

s

v

P

2 P

1

y

x

Dijkstra’s Algorithm

Upon termination.

n^

π

(v) = distance of shortest s-v path.

n^

pred(v) gives shortest path.

for each v

V

π

(v)

pred(v)

nil

π

(s)

S

φ

init(Q)for each v

V

insert(v, Q)

while (Q

φ

v = delete-min(Q)S

S

{v}

for each w s.t (v,w)

E

if

π

(w) >

π

(v) + c(v,w)

π

(w)

← π

(v) + c(v,w)

pred(w)

v

Dijkstra’s Algorithm

decrease-key

Docsity.com