Midterm1Prac

Midterm1Prac - Solutions to Practice Problems for Midterm 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Peng Du University of California, San Diego 1 Exercise 3.11 Suppose e = ( u,v ), we only need to delete e in G and check whether there is a path from u to v by DFS or BFS. The algorithm runs in time O ( | E | ). 2 Exercise 3.22 For each s V , we use DFS or BFS to check whether all vertices can be reachable from s . The algorithm takes O ( | V || E | ) time. 3 Exercise 4.5 See the solution for homework four. 4 Exercise 4.8 See the solution for homework four. 5 Exercise 4.19 Let l 0 = { l e + c u : e = ( u,v ) E } and dist = dijkstra ( G,l 0 ,s ). We have cost [ w ] = dist [ w ] + c w for each w V . The algorithm has the same time com- plexity as dijkstra algorithm. 6 Exercise 4.20 Let d 1 = dijkstra ( G,l,s ) and d 2 = dijkstra ( G,l,t ). For each e 0 = ( u,v ) E 0 , we define d e 0 = min( d 1 [ t ] ,d 1 [ u ] + d 2 [ v ] + l e 0 ,d 1 [ v ] + d 2 [ u ] + l e 0 ), which is the shortest driving distance from s to t after adding road e 0 . Therefore, the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

Midterm1Prac - Solutions to Practice Problems for Midterm 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online