09.12.2012 Views

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

Concrete mathematics : a foundation for computer science

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.

3.3 FLOOR/CEILING RECURRENCES 79<br />

Exercise 25 asks <strong>for</strong> a proof or disproof that K, > n, <strong>for</strong> all n 3 0. The<br />

first few K’s just listed do satisfy the inequality, so there’s a good chance that<br />

it’s true in general. Let’s try an induction proof: The basis n = 0 comes<br />

directly from the defining recurrence. For the induction step, we assume<br />

that the inequality holds <strong>for</strong> all values up through some fixed nonnegative n,<br />

and we try to show that K,+l > n + 1. From the recurrence we know that<br />

K n+l = 1 + minWl,pJ ,3Kln/31 1. The induction hypothesis tells us that<br />

2KL,,/~J 3 2Ln/2J and 3Kln/3~ 3 3 [n/31. However, 2[n/2J can be as small<br />

as n - 1, and 3 Ln/3J can be as small as n - 2. The most we can conclude<br />

from our induction hypothesis is that Kn+l > 1 + (n - 2); this falls far short<br />

of K,+l 3 n + 1.<br />

We now have reason to worry about the truth of K, 3 n, so let’s try to<br />

disprove it. If we can find an n such that either 2Kl,,zl < n or 3Kl,,31 < n,<br />

or in other words such that<br />

we will have K,+j < n + 1. Can this be possible? We’d better not give the<br />

answer away here, because that will spoil exercise 25.<br />

Recurrence relations involving floors and/or ceilings arise often in <strong>computer</strong><br />

<strong>science</strong>, because algorithms based on the important technique of “divide<br />

and conquer” often reduce a problem of size n to the solution of similar problems<br />

of integer sizes that are fractions of n. For example, one way to sort<br />

n records, if n > 1, is to divide them into two approximately equal parts, one<br />

of size [n/21 and the other of size Ln/2]. (Notice, incidentally, that<br />

n = [n/21 + Ln/2J ; (3.17)<br />

this <strong>for</strong>mula comes in handy rather often.) After each part has been sorted<br />

separately (by the same method, applied recursively), we can merge the<br />

records into their final order by doing at most n - 1 further comparisons.<br />

There<strong>for</strong>e the total number of comparisons per<strong>for</strong>med is at most f(n), where<br />

f(1) = 0;<br />

f(n)=f([n/21)+f([n/2J)+n-1, <strong>for</strong> n > 1<br />

A solution to this recurrence appears in exercise 34.<br />

(3.18)<br />

The Josephus problem of Chapter 1 has a similar recurrence, which can<br />

be cast in the <strong>for</strong>m<br />

J(1) = 1;<br />

J(n) = 2J( LnI2J) - (-1)” ,<br />

<strong>for</strong> n > 1.

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

Saved successfully!

Ooh no, something went wrong!