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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

c.<br />

Now suppose that<br />

is weighted <strong>and</strong> assume the follow<strong>in</strong>g:<br />

1:<br />

for 1 ≤ i ≤ n,M(i,i)=0.<br />

2:<br />

for 1 ≤ i,j ≤ n, M(i, j) = weight(i, j) if (i, j) is <strong>in</strong> E.<br />

3:<br />

for 1 ≤ i, j ≤ n, M(i, j) = ∞ if (i, j) is not <strong>in</strong> E.<br />

Also, let M 2 be def<strong>in</strong>ed, for 1 ≤ i,j ≤ n, as follows:<br />

M 2 (i, j) = m<strong>in</strong>{M(i, 1) +M(1,j),... ,M(i,n) +M(n,j)}.<br />

If M 2 (i, j) = k, what may we conclude about the relationship between vertices i<br />

<strong>and</strong> j?<br />

C-13.27<br />

A graph G is bipartite if its vertices can be partitioned <strong>in</strong>to two sets X <strong>and</strong> Y<br />

such that every edge <strong>in</strong> G has one end vertex <strong>in</strong> X <strong>and</strong> the other <strong>in</strong> Y. Design<br />

<strong>and</strong> analyze an efficient algorithm for determ<strong>in</strong><strong>in</strong>g if an undirected graph G is<br />

bipartite (without know<strong>in</strong>g the sets X <strong>and</strong> Y <strong>in</strong> advance).<br />

C-13.28<br />

An old MST method, called Baruvka's algorithm, works as follows on a graph<br />

G hav<strong>in</strong>g n vertices <strong>and</strong> m edges with dist<strong>in</strong>ct weights:<br />

Let Tbe a subgraph of G <strong>in</strong>itially conta<strong>in</strong><strong>in</strong>g just the vertices <strong>in</strong> V.<br />

while T has fewer than n − 1 edges do<br />

for each connected component Q of T do<br />

F<strong>in</strong>d the lowest-weight edge (v, u) <strong>in</strong> E with v <strong>in</strong> Ci <strong>and</strong> u not <strong>in</strong> Ci.<br />

Add (v, u) to T (unless it is already <strong>in</strong> T).<br />

return T<br />

Argue why this algorithm is correct <strong>and</strong> why it runs <strong>in</strong> O(mlogn) time.<br />

879

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

Saved successfully!

Ooh no, something went wrong!