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.

84 INTEGER FUNCTIONS<br />

more than one line’s worth of text. If 37 lines of text are being divided into<br />

five columns, we would there<strong>for</strong>e prefer the arrangement on the right:<br />

8 8 8 5 8 8 7 7 7<br />

Furthermore we want to distribute the lines of text columnwise-first deciding<br />

how many lines go into the first column and then moving on to the second,<br />

the third, and so on-because that’s the way people read. Distributing row<br />

by row would give us the correct number of lines in each column, but the<br />

ordering would be wrong. (We would get something like the arrangement on<br />

the right, but column 1 would contain lines 1, 6, 11, . . . , 36, instead of lines<br />

1, 2, 3, . . ' ) 8 as desired.)<br />

A row-by-row distribution strategy can’t be used, but it does tell us how<br />

many lines to put in each column. If n is not a multiple of m, the rowby-row<br />

procedure makes it clear that the long columns should each contain<br />

[n/ml lines, and the short columns should each contain Ln/mJ. There will<br />

be exactly n mod m long columns (and, as it turns out, there will be exactly<br />

n mumble m short ones).<br />

Let’s generalize the terminology and talk about ‘things’ and ‘groups’<br />

instead of ‘lines’ and ‘columns’. We have just decided that the first group<br />

should contain [n/ml things; there<strong>for</strong>e the following sequential distribution<br />

scheme ought to work: To distribute n things into m groups, when m > 0,<br />

put [n/ml things into one group, then use the same procedure recursively to<br />

put the remaining n’ = n- [n/ml things into m’ = m- 1 additional groups.<br />

For example, if n = 314 and m = 6, the distribution goes like this:<br />

remaining things remaining groups [things/groups]<br />

314 6 53<br />

261 5 53<br />

208 4 52<br />

156 3 52<br />

104 2 52<br />

52 1 52<br />

It works. We get groups of approximately the same size, even though the<br />

divisor keeps changing.<br />

Why does it work? In general we can suppose that n = qm + r, where<br />

q = Ln/mJ and r = n mod m. The process is simple if r = 0: We put<br />

[n/ml = q things into the first group and replace n by n’ = n - q, leaving

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

Saved successfully!

Ooh no, something went wrong!