next up previous
Next: About this document

 COS 341, December 3, 1997

Handout Number 22

Diameters, Guess and Verify

Diameters

Let G be a graph on n vertices tex2html_wrap_inline177 . Let d(i,j) denote the distance between vertices i,j in G (ie, the length of the shortest path from i to j in G). By convention, d(i,i)=0 for all i. It is easy to see that the triangle inequalities are satisfied, ie, tex2html_wrap_inline195 for all i,j,k. The diameter tex2html_wrap_inline199 is defined as tex2html_wrap_inline201 . Clearly, tex2html_wrap_inline203 .

Given an input G, we will give an algorithm that determines tex2html_wrap_inline199 in time tex2html_wrap_inline209 where s(n) is the time needed to compute the boolean matrix product of two tex2html_wrap_inline213 boolean matrices.

Let tex2html_wrap_inline215 denote the boolean matrix such that tex2html_wrap_inline217 iff either i=j or tex2html_wrap_inline221 is an edge in G; all other entries are 0. Thus, tex2html_wrap_inline217 iff tex2html_wrap_inline229 . The following generalization of the above statement is the key observation needed to develop our algorithm.

Lemma For all integers tex2html_wrap_inline231 , tex2html_wrap_inline233 iff tex2html_wrap_inline235 .

Proof We prove by induction on t. The base case t=1 is true by an observation made in the paragraph before the Lemmma. For the inductive step, let t>1, and assume that the Lemma is true for all lesser values.

Observe that

eqnarray61

We now establish the case for t. First one direction. Assume tex2html_wrap_inline233 . By (1) there exists a vertex k such that tex2html_wrap_inline249 . By the induction hypothesis applied to t-1 and 1, this vertex k satisfies tex2html_wrap_inline257 and tex2html_wrap_inline259 . This implies then tex2html_wrap_inline261 .

Second, in the opposite direction, assume that tex2html_wrap_inline235 . Let k be a vertex such that tex2html_wrap_inline257 and tex2html_wrap_inline259 ; we can take k to be j if i=j, and otherwise the last vertex before reaching j on the shortest path from i to j. By the induction hypothesis, tex2html_wrap_inline283 and tex2html_wrap_inline285 . It follows then from (1) that tex2html_wrap_inline233 . This completes the inductive step in the proof of the Lemma.

Let D denote the boolean matrix with all its entries equal to 1. The Lemma implies that tex2html_wrap_inline293 for all tex2html_wrap_inline295 . It also implies that tex2html_wrap_inline297 (entrywise) for all m. Thus, to determine tex2html_wrap_inline199 , it suffices to find the smallest t such that tex2html_wrap_inline293 . Recall that tex2html_wrap_inline203 and thus the range of this t is between 1 and n-1.

To do this, first compute all the powers tex2html_wrap_inline315 , where tex2html_wrap_inline317 is the first time the matrix power tex2html_wrap_inline319 becomes D. The running time spent in this round is tex2html_wrap_inline323 . We have now determined that tex2html_wrap_inline199 is in the range tex2html_wrap_inline327 . The range is thus halved in this round.

In the second round, we compute all the powers tex2html_wrap_inline329 , where tex2html_wrap_inline331 is the first time the matrix power tex2html_wrap_inline333 becomes D. The running time spent in this round is tex2html_wrap_inline337 . We have now determined that tex2html_wrap_inline199 is in the range tex2html_wrap_inline341 . The search range is thus halved in this round.

We can similarly carry out the 3rd round, 4th round, until the range is reduced to zero. The total running time is tex2html_wrap_inline343 which is tex2html_wrap_inline345 , since tex2html_wrap_inline347 and each tex2html_wrap_inline349 .

We remark that in fact tex2html_wrap_inline351 is the binary representation of the integer tex2html_wrap_inline353 .

In Homework Set 8, you will be asked to modify the above search process and improve the running time to tex2html_wrap_inline355 .

Guess and Verify

In this approach, when confronted with a recurrence relation, we guess an upper bound (or lower bound) expression for the function. Then verify by induction. The following example comes from the analysis of the running time T(n) of a backtracking algorithm for listing all the maximal independent sets of n-vertex input graphs:

eqnarray109

We prove by induction that, for all tex2html_wrap_inline363 ,

equation112

where tex2html_wrap_inline365 are the Fibonacci numbers.

Before proceeding with the proof, we compute the values of T(n) and tex2html_wrap_inline365 for tex2html_wrap_inline371 . It turns out that the T(n)'s are 1,1,4,8,16,29, 51; the tex2html_wrap_inline377 are 1,1,2,3,5,8,13.

For the base n=0, 1, (3) is clearly true since T(0)=T(1)=1 by definition. For the inductive step, let n>1 and assume that (3) is valid for all lesser values. We establish (3) for n.

If tex2html_wrap_inline389 , then (3) is true by using the values we have computed for tex2html_wrap_inline391 . We can thus assume that n > 6. Using the recurrence (2) and the induction hypothesis (3) for n-1 and n-2, we have

eqnarray114

This completes the inductive proof of (3).

How did we come to the lucky guess (3)? Here is the rationale. First observe that, if the +n term is missing in the recurrence (2), then tex2html_wrap_inline365 would be the solution. Since +n is such a small additional term compared with the tex2html_wrap_inline405 terms, a reasonable guess is

equation122

for some constant, say, c=10. However, if you try to verify (4) by induction using the recurrence (2), you cannot carry out the inductive step, ie, you get

eqnarray124

which does not complete the inductive step.

What we lacked is an additional term in T(n) such that they can absorb the +n term. A natural choice is to guess

equation129

However, the inductive step still falls a little short, since we get only

eqnarray131

Thus, we want to make the additional term a little more negative. Also, we need to choose c carefully so that the negative new term does not kill the validity of the base case.

Let us make the guess in the general form

equation136

for some c,d >1, and see what parameters can make the inductive proof work.

Take the inductive step first. We have

eqnarray138

To make the inductive step work, we need the condition tex2html_wrap_inline417 , ie,

equation143

This means that, if d>1 is chosen, then the inductive step can be carried out if tex2html_wrap_inline421 .

But the inductive step (and the base case n=0,1) needs to be done when n < 3d/(d-1). This can be accomplished by brute force, that is, by choosing the parameter c to be large enough. In fact, all we need is that equation (5) be satisfied for all n < 3d/(d-1). Equivalently, we need

equation145

If d=2 (hence 3d/(d-1)=6), it is sufficient to choose c to be at least as big as

displaymath171

which is less than 5.




next up previous
Next: About this document

Andrew Yao
Tue Dec 2 13:43:36 EST 1997