23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2:<br />

Initialize VisitedVertices to {start}.<br />

3:<br />

If start=goal, return path <strong>and</strong> exit. Otherwise, cont<strong>in</strong>ue.<br />

4:<br />

F<strong>in</strong>d the edge (start,v) of m<strong>in</strong>imum weight such that v is adjacent to start<br />

<strong>and</strong> v is not <strong>in</strong> VisitedVertices.<br />

5:<br />

Add v to path.<br />

6:<br />

Add v to VisitedVertices.<br />

7:<br />

Set start equal to v <strong>and</strong> go to step 3.<br />

Does this greedy strategy always f<strong>in</strong>d a shortest path from start to goal? Either<br />

expla<strong>in</strong> <strong>in</strong>tuitively why it works, or give a counter example.<br />

C-13.18<br />

Show that if all the weights <strong>in</strong> a connected weighted graph G are dist<strong>in</strong>ct, then<br />

there is exactly one m<strong>in</strong>imum spann<strong>in</strong>g tree for G.<br />

C-13.19<br />

Design an efficient algorithm for f<strong>in</strong>d<strong>in</strong>g a longest directed path from a vertex s<br />

to a vertex t of an acyclic weighted digraph . Specify the graph<br />

representation used <strong>and</strong> any auxiliary data structures used. Also, analyze the<br />

time complexity of your algorithm.<br />

C-13.20<br />

Consider a diagram of a telephone network, which is a graph G whose vertices<br />

represent switch<strong>in</strong>g centers, <strong>and</strong> whose edges represent communication l<strong>in</strong>es<br />

jo<strong>in</strong><strong>in</strong>g pairs of centers. Edges are marked by their b<strong>and</strong>width, <strong>and</strong> the<br />

b<strong>and</strong>width of a path is the b<strong>and</strong>width of its lowest b<strong>and</strong>width edge. Give an<br />

algorithm that, given a diagram <strong>and</strong> two switch<strong>in</strong>g centers a <strong>and</strong> b, outputs the<br />

maximum b<strong>and</strong>width of a path between a <strong>and</strong> b.<br />

876

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!