22.11.2014 Views

The Weighted All-Pairs-Shortest-Path-Length Problem on Two ...

The Weighted All-Pairs-Shortest-Path-Length Problem on Two ...

The Weighted All-Pairs-Shortest-Path-Length Problem on Two ...

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.

<str<strong>on</strong>g>The</str<strong>on</strong>g> 25th Workshop <strong>on</strong> Combinatorial Mathematics and Computati<strong>on</strong> <str<strong>on</strong>g>The</str<strong>on</strong>g>ory<br />

v = lt(G(q)) and v = rt(G(q)); and let v =<br />

i<br />

lt(G(f)) and<br />

v j<br />

be performed.<br />

k<br />

= rt(G(f)). <str<strong>on</strong>g>The</str<strong>on</strong>g> following codes will<br />

recursively compute L[s, t], and L[t, s], for ,<br />

v t<br />

∈ V(G(q));<br />

recursively compute L[s, t], and L[t, s], for ,<br />

v t<br />

∈ V(G(f));<br />

L[i, j] = L[i, k] + L[k, j];<br />

L[j, i] = L[j, k] + L[k, i];<br />

for each pair of vertices v ≠ v such that v ∈<br />

V(G(q)) – { v , v } and v ∈ V(G(f)) – { v ,<br />

v j<br />

}<br />

i<br />

k<br />

/* If <strong>on</strong>e of V(G(q)) – { v , v } and V(G(f)) –<br />

{ v , v } is empty, then we just skip this loop. */<br />

k<br />

j<br />

L[a, b] = L[a, k] + L[k, b];<br />

L[b, a] = L[b, k] + L[k, a];<br />

endfor<br />

vi<br />

∈ V(G(f)) – { vk<br />

, v<br />

j<br />

}<br />

v v<br />

for each pair of vertices and v such that<br />

a<br />

i<br />

b<br />

k<br />

b<br />

b<br />

k<br />

v s<br />

v s<br />

a<br />

k<br />

vb<br />

/* If V(G(f)) – {<br />

k<br />

,<br />

j<br />

} is empty, then we just<br />

skip this loop. */<br />

L[i, b] = L[i, k] + L[k, b];<br />

L[b, i] = L[b, k] + L[k, i];<br />

endfor<br />

for each pair of vertices v and v such that<br />

∈ V(G(q)) – { vi<br />

, vk<br />

}<br />

/* If V(G(q)) – { vi<br />

, vk<br />

} is empty, then we just<br />

skip this loop. */<br />

L[a, j] = L[a, k] + L[k, j];<br />

L[j, a] = L[j, k] + L[k, a];<br />

endfor<br />

a<br />

j<br />

va<br />

Case 3. z is a P-node<br />

Let q and f be the left child and the right child of z,<br />

respectively, i.e., G(z) = G(q) + G(f). In this case,<br />

lt(G(q)) = lt(G(f)) = vi<br />

and rt(G(q)) = lt(G(f)) = v<br />

j<br />

.<br />

<str<strong>on</strong>g>The</str<strong>on</strong>g> following codes will be performed.<br />

recursively compute L[s, t], and L[t, s], for ,<br />

v t<br />

∈ V(G(q));<br />

L<br />

1<br />

[i, j] = L[i, j];<br />

[j, i] = L[j, i];<br />

L 1<br />

recursively compute L[s, t], and L[t, s], for ,<br />

v t<br />

∈ V(G(f));<br />

L<br />

2<br />

[i, j] = L[i, j];<br />

L 2<br />

[j, i] = L[j, i];<br />

v s<br />

v s<br />

L[i, j] = min{ L1<br />

[i, j], L2<br />

[i, j]};<br />

L[j, i] = min{ [j, i], L [j, i]};<br />

L1<br />

2<br />

2<br />

Lemma 5: Phase I can be d<strong>on</strong>e in O( n ) time.<br />

Proof: To complete Phase I, each pair of vertices<br />

v j<br />

and is examined c<strong>on</strong>stant times and each node of<br />

T(r) is also examined c<strong>on</strong>stant times. This implies<br />

2<br />

that Phase I can be d<strong>on</strong>e in O( n ) time. <br />

3.2 Phase II<br />

It is easy to see that LPNA(u), for each P-node u,<br />

can be obtained by the post-order traversal <strong>on</strong> T and<br />

the time-complexity is linear. Based <strong>on</strong> the<br />

reas<strong>on</strong>ing and the results of so far, Phase II can be<br />

achieved by breadth-first traversal <strong>on</strong> T from the<br />

root r. For each n<strong>on</strong>-top P-node u, assume that f =<br />

LPNA(u) and the terminals of G(u) and G(f) are<br />

< vi<br />

, v<br />

j<br />

> and < vs<br />

, vt<br />

>, respectively. <str<strong>on</strong>g>The</str<strong>on</strong>g><br />

following code will be performed.<br />

if (u ∈ left_descendants(f))<br />

OL[i, j] = L[i, s] + [s, t] + L[t, j];<br />

L 2<br />

L 2<br />

OL[j, i] = L[j, t] + [t, s] + L[s, i];<br />

else /* u ∈ right_descendants(f). */<br />

OL[i, j] = L[i, s] + [s, t] + L[t, j];<br />

OL[j, i] = L[j, t] +<br />

endif<br />

L 1<br />

[t, s] + L[s, i];<br />

L 1<br />

<str<strong>on</strong>g>The</str<strong>on</strong>g> following lemma can be verified easily.<br />

2<br />

Lemma 6: Phase II can be d<strong>on</strong>e in O( n )-time.<br />

3.3 Phase III<br />

This phase will be achieved by depth-first<br />

traversal <strong>on</strong> T from the root r. For each P-node u, let<br />

q and f be the left child and the right child of u,<br />

respectively, i.e., G(u) = G(q) + G(f). In this case,<br />

lt(G(q)) = lt(G(f)) = vi<br />

and rt(G(q)) = lt(G(f)) = v<br />

j<br />

.<br />

<str<strong>on</strong>g>The</str<strong>on</strong>g> following codes will be performed.<br />

for each pair { va<br />

, vb<br />

} ∈ pair_set(u)<br />

docase<br />

case va<br />

, vb<br />

∈ V(G(q))<br />

L[a, b] = min{L[a, b],<br />

L[a, i] + L 2<br />

[i, j] + L[j, b],<br />

L[a, j] + L 2<br />

[j, i] + L[i, b],<br />

L[a, i] + OL[i, j] + L[j, b],<br />

L[a, j] + OL[j, i] + L[i, b]};<br />

L[b, a] = min{L[a, b], L[b, i] + L 2<br />

[i, j]<br />

v i<br />

-359-

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

Saved successfully!

Ooh no, something went wrong!