ADVANCED ALGORITHMS 2 LECTURE 10 ANNOUNCEMENTS Homework 2 due - - PowerPoint PPT Presentation

advanced algorithms
SMART_READER_LITE
LIVE PREVIEW

ADVANCED ALGORITHMS 2 LECTURE 10 ANNOUNCEMENTS Homework 2 due - - PowerPoint PPT Presentation

1 LECTURE 10: SHORTEST PATH ADVANCED ALGORITHMS 2 LECTURE 10 ANNOUNCEMENTS Homework 2 due next Friday Contacting the TAs: utah-algo-ta@googlegroups.com Notes for this class: http://jeffe.cs.illinois.edu/teaching/algorithms/


slide-1
SLIDE 1

ADVANCED ALGORITHMS

LECTURE 10: SHORTEST PATH

1

slide-2
SLIDE 2

LECTURE 10

ANNOUNCEMENTS

▸ Homework 2 due next Friday ▸ Contacting the TAs: utah-algo-ta@googlegroups.com ▸ Notes for this class: http://jeffe.cs.illinois.edu/teaching/algorithms/

notes/21-sssp.pdf

2

slide-3
SLIDE 3

LECTURE 10

LAST CLASS

3

▸ Local search and gradient descent ▸ Shortest path problem

if 2 approx formatching

slide-4
SLIDE 4

LECTURE 10

GRAPH ALGORITHMS

4

slide-5
SLIDE 5

LECTURE 10

SHORTEST PATH PROBLEM

5

Shortest path: given a (possibly directed) graph G = (V, E), and two vertices u, v, find the length of the shortest path from u to v

▸ What if the graph is not weighted? — breadth first search ▸ Negative weight edges?

all lengths 1

01mm

Problem is not

Fell if

u

grapmhtfsdes.ve

slide-6
SLIDE 6

LECTURE 10

BFS + DISTANCE UPDATES?

6

▸ Maintain array dist[w] for all vertices w ▸ Initialize using BFS ▸ For each edge ij, if dist[j] < dist[i] + length(i,j), update dist[j] ▸ Repeat until the dist[] values stop changing

OU

O W

List

Ew

i

  • j

dhe w

w

slide-7
SLIDE 7

LECTURE 10

OBSERVATIONS

7

▸ At every point of the algorithm, dist[w] is an upper bound on true

shortest path length d(u, w)

▸ dist[w] is monotone

Claim: when the algorithm terminates, dist[w] = d(u, w) for all w

true because dist w

is the lengthof sp to w found

so far

slide-8
SLIDE 8

LECTURE 10

PROOF

8 Suppose we did k iterations of the algorithm. Is there something nice to be said about dist[w] values?

Ow

  • f

it

t

  • Consider all

vertices w for a

which shortest path from

Ito

u

w

has lingulatek

a

ti

i

slide-9
SLIDE 9

LECTURE 10

PROOF (CONTINUED)

9

Prone claim byinduction

k

is

trivial

Suppose it holds for

k

now

connider htt

IrmasutEf for

all vertices

w

s't

hops in shortestpath Ek

O

we found the path

Consider any

w

s t

shortest pathfrom u has

htt

hops

go

ee

affirmedIttihad

w

THE

correctvalue ftp.estfwI

slide-10
SLIDE 10

Optimum

path from

a

to w has

hops

Ek

Reach

Optimal sub structure

property of

shortest paths

slide-11
SLIDE 11

LECTURE 10

RUNNING TIME BOUND (SHIMBEL’S ALGORITHM)

10

Bellman

forT

algorithm

Previous

claim

aftern iterations

we havefoundthortest

paths

toll

w

iterations In

Time

for each iteration

0cm

Overall runtime

Ofm n It

also works when some edgewts are

we

slide-12
SLIDE 12

LECTURE 10

BETTER THAN M*N?

11

▸ Remember, this is an algorithm that also works when there are

negative edges

▸ Can we use positivity in a nicer way?

slide-13
SLIDE 13

▸ Can we “fix” BFS? ▸ Recall: main idea of BFS — find all vertices at certain distance from u ▸ Problem: in BFS, vertex at distance 2 is nbr of vertex at distance 1

LECTURE 10

MAIN IDEA — DIJKSTRA’S ALGORITHM

12

1958

Dijkstra

u

x

m

  • 9K
slide-14
SLIDE 14

LECTURE 10

EXTENDING BFS

13

W

WI

Kes

win

Intuitiveidas

Grow a ball of a certainradiusaround

u

Add one vertex at

a time

Iqqjo

formalitalgorithmi

start

with

vertex

n

Add

vertex

that has

min distancetofu

Add

vertex

l

st

u

via

u E

it

i

E

tou

via E EE't

slide-15
SLIDE 15

LECTURE 10

PRIORITY QUEUE

14

Want

a data structure that

maintains 6h dist w

pair distfw

is

defined

quicklyobtain the

w thathas minimum

t.be dstme

distf

value

to

a

via the sitar

quickly

the

disowns

Oflog

n

Read

in

notes

Offmtn login

fm 7 nlognl

slide-16
SLIDE 16

LECTURE 10

CORRECTNESS

15

Claim

whenever

we add

a vertex to the set

ball

we

are

maintaining the distt

value is

indeed

the

shortest distance

to

n

i

slide-17
SLIDE 17

LECTURE 10

RUNNING TIME

16

slide-18
SLIDE 18

LECTURE 10

RUNNING TIME

17

slide-19
SLIDE 19

LECTURE 10

SHORTEST PATHS — SUMMARY

18

▸ Shimbel/Bellman-Ford algorithm — can handle negative weights, but

is slower

▸ Dijkstra’s algorithm — (m+n) log n ▸ Don’t know if log n is necessary!