Part I: MATHEMATICAL PRELIMINARIES

CHAPTER 1

Counting

c01uf001

Walter Crane (1814–1915), The Song of Sixpence: “The Queen was in the parlor, eating bread and honey.”

This chapter reviews the basic counting techniques that will be used throughout the book. An excellent reference for this material is [Rosen 2003].

1.1 THE SUM AND PRODUCT RULES

SUM RULE

If the first of two tasks can be performed in any of n1 ways and the second in any of n2 ways, and if these tasks cannot be performed at the same time, then there are n1 + n2 ways of performing either task.

Example 1.1.

The formula |N1N2| = n1 + n2 is valid if

a) Sets N1 and N2 contain n1 = |N1| and n2 = |N2| elements, respectively.

b) The sets have no elements in common c01ue001.

GENERALIZED SUM RULE

If the ith of m tasks 1 ≤ im can be performed in any of ni ways, and if these cannot be performed at the same time, then there are n1 + n2 + ··· + nm ways of performing any of the m tasks.

Example 1.2.

The formula c01ue002 is valid if

a) m sets N1, N2, ··· , Nm contain n1 = |N1|, n2 = |N2|, ··· , nm = |Nm| elements, respectively.

b) No pair of (distinct) sets Ni and Nj (1 ≤ i < jm) has an element in common (pairwise disjoint sets) .

If the m sets N1

Get Hashing in Computer Science: Fifty Years of Slicing and Dicing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.