# Introduction to Computers and Applications

Document Sample

```					                   CSSE 210 Foundations of Computer Science
Fall 2009

Counting
5.1 The Basics of Counting
Example: A small software project contains the following employees: 3 software developers, 4 software
testers, and 2 managers.

A couple of questions can be asked…

1. If one member of the project is selected to give a talk, how many different choices are there?

2. If a team is formed consisting of one software developer, one software tester, and one manager, how
many different ways are there to form the team?

sum rule or addition principle: Suppose that tasks T1, T2, …, Tk can be done in n1, n2, …, nk ways,
respectively. If all the tasks are independent of one another, the number of ways to do one of these tasks
is n1 + n2 + … + nk.

product rule or multiplication principle: Suppose a task T can be completed in k successive steps.
Suppose step 1 can be completed in n1 ways, step 2 can be completed in n2 ways, …, and step k can be
completed in nk ways. If the steps are independent of one another, then task T can be completed in
n1n2… nk ways.

A few notes regarding the independent clauses of these rules:

   In the sum rule, the tasks are independent if they represent disjoint sets. For instance, all of the
employees are unique people.

   In the product rule, the steps are independent if your choice for step k does not depend on the choices
for any of the other steps. Referring to the example, the product rule will not work if there were
restrictions such as “software developer Bob cannot be on the same team as manager Alice”.

1
Examples: For each of the following scenarios, determine if the product or sum rule is used.

a. The number of license plates that contain 3 numerical digits (0-9) followed by 3 letters (A-Z).

b. The number of bit strings of length 5.

c. The number of subsets of the set {1, 2, 3, 4, 5}.

d. The number of people in class who are either juniors or sophomores.

Often, a combination of both the product and sum rules are necessary to count all the combinations.

Example: The number of words, consisting of lowercase letters, that are either 3 or 4 letters long.

2
Example: A computer system requires a password be exactly six characters long where each character is
a digit or uppercase letter. Each password must contain at least one digit.

3
5.3 Permutations and Combinations
A deficiency of the product rule is that the choices must be independent. Permutations and combinations
can be used to count the number of possibilities in situations where r items need to be selected from a set
of n items. In this section, we’ll assume that the n items in the set are unique.

Permutations

Example: In horse racing speak, the “win” position is first place, the “place” position is second place, and
the “show” position is third place. How many possibilities are there for win-place-show for a race with
15 horses? Assume there are no ties.

permutation of a set: An ordered arrangement of the set.

r-permutation of a set: An ordered arrangement of r elements of a set.

A common counting problem is to find the number of r-permutations of a set of n elements where 0  r 
n. This is denoted P(n, r). Using the product rule above, we get:

This can also be expressed using factorial notation:

Example: There are 12 people on a baseball team. How many different ways are there to choose the nine
positions?

How many different ways are there to choose the nine positions if Ernie is always the pitcher.

4
Combinations

r-combination of a set: An unordered collection of r element of a set. In other words, an r-combination
is a subset of the set with r elements.

The number of combinations of a set with n elements, denoted C(n, r), is based on the number of
permutations and the number of possible orderings:

Example: On the quiz bowl team with nine members, how many different teams for four people could
compete in the upcoming match?

A useful corollary: C(n, r) = C(n, n – r)

We could have approached the problem from the perspective: "Which five people should not compete in
the upcoming match?"

Example: Assume a CSSE department has seven SE faculty and nine CS faculty.

How many ways are there to select a committee of five members of the department if at least one SE
faculty member must be on the committee?

5
Example: The English alphabet contains 21 consonants and 5 vowels.   How many strings of five
lowercase letters of the English alphabet contain…

a. exactly two vowels?

b. at most two vowels?

c. at least two vowels?

6
5.5 Generalized Permutations and Combinations
Note: Skip the last two subsections involving Indistinguishable Boxes

In our discussion of permutations and combinations so far, we have assumed that r objects in the
arrangement must be distinct. In this section, we will remove that restriction.

Permutations and Combinations with Repetition

Assume the initial set contains n distinct objects. When forming permutations or combinations, any
object may be repeated in an arrangement. There is no restriction to the number of times an object can be
repeated within an arrangement.

Example: What is the number of strings consisting of lowercase letters of length four are there?

Theorem: The number of r-permutations of a set of n objects with repetition allowed is nr.

To understand the number of r-combinations with repetition, consider this example:

Example: There are five kids and three marbles. All three marbles are the same. How many ways are
there to divide the marbles such that no kid receives more than one marble?

Changing the problem to allow repetition – how many ways are there to divide the marbles with no
restriction on the number of marbles each kid receives?

7
This arrangement is a string of four lines and three stars. The question becomes – how many different
arrangements of this string are available?

Theorem: There are C(n + r - 1, r) r-combinations from a set of n elements when repetition of elements
is allowed.

A table summarizing combinations and permutations is on page 375.

Example: If a donut shop has 20 varieties of donuts, how many different combinations of a dozen are
possible? Assume a dozen is 12 donuts and there is at least 12 donuts of each variety available.

CLASS PROBLEM – Work in pairs

If a donut shop has 20 varieties of donuts, how many different combinations of a dozen are possible with
the restriction that no more than seven donuts can be of the same variety?

This now imposes a restriction on how many times an object can be repeated. There is no easy-to-use
formula for such a problem.

8
Indistinguishable vs. Distinguishable Objects and Boxes

Many problems can be reconsidered as distributing objects into boxes. The objects placed into the boxes
can be the same (indistinguishable) or different (distinguishable). We will assume the boxes are different
(distinguishable).

In the marble example, all the marbles (objects) are indistinguishable. The kids are the boxes.

In the donut example, you can think of the donut as the object with each variety of donut being in a box.
The donuts in each box are indistinguishable. Instead of distributing objects into boxes, you are taking
objects out of the boxes. The problem is no different if you are taking items out of boxes or putting them
in the boxes.

The number of ways to distribute r indistinguishable objects into n boxes C(n + r – 1, r).

Example: How many solutions are there to the equation

x1 + x2 + x3 + x4 = 17

where x1, x2, x3, and x4 are nonnegative integers such that …

a. there are no additional restrictions

b. x1 = 2

c. x2 > 3

d. x4 < 5

9
What happened if the objects are distinguishable (different)? Assume there are r objects and n boxes.

A common variation of this problem is solved differently:

Example: There are five kids and twenty different marbles. How many are there to divide the marbles
such that each kid receives 4 marbles?

Example: How many different strings can be made using all the letters of the word REFERRAL?

10
7.5 Inclusion - Exclusion
The sum rule requires the sets to be independent or disjoint. But we can use the inclusion-exclusion
principle to address sets that are not disjoint. In order to find the number of unique elements in A and B,
compute |A  B|.

|A  B| = |A| + |B| – |A  B|

The sum |A| + |B| adds the counts together. This is an overcount since the elements in A  B were
counted twice (once in each set). It is necessary to subtract the number of elements in A  B to get an
accurate count. Note that the sum rule is a special case of this principle where |A  B| = 0.

Example: How many bit strings of length 6 either start with 101 or end with 00?

Example: How many integers between 100 and 999 inclusive are divisible by 3 or 5?

11
The principle can be extended to three sets:

|A  B  C| = |A| + |B| + |C| – |A  B| – |A  C| – |B  C| + |A  B  C|

The general principle of inclusion-exclusion of n sets is:

A1  A2  ... An      A   A A
1in
i
1i j n
i   j          A A A
1i jk n
i   j   k    ... (1)n1 A1  A2  ... An

12
7.1 Using Recurrences for Counting Problems
Note: Look at examples 6-8. The first part of this section was covered earlier in the course.

Example: How many bit strings of 7 bits do not contain the pattern 111 anywhere?

13
More Examples
It is important to get practice in reading problems and determining how to count the number of
combinations are possible in a situation. Many situations will involve using multiple techniques we
covered in this section.

1. One common example involves counting possible poker hands. Poker is played with a standard deck
of 52 cards. The cards can be thought of as the Cartesian product of a set of four suits {Club, Spade,
Diamond, Heart} and a set of 13 values (easily represented as a set of numbers from 1 to 13). A poker
hand consists of five cards.

a. How many possible poker hands are there?

b. How many possible hands contain cards all of the same suit (flush)?

c. How many possible hands contain three cards of one value and two cards of a second value (full
house)?

2. An exam has 12 problems. How many ways can (integer) points be assigned to the problems if the
total of the points is 100 and each problem is worth at least five points.

14
3. In a board game, the squares are numbered from 0 to 99 with each player starting at square 0. Each
turn, a player can move ahead either one or two squares. A player is currently on square 10, how many
different move sequences are possible to get from square 0 to square 10?

4. How many bit strings of length seven contain five consecutive zeros?

15
5. Out of a group of 16 people, how many different arrangements are possible for a committee that
consists of a chair, secretary, and three general members?

6. A coach is trying to field a co-ed softball team of exactly 12 players. Rules require that there must be
more women than men on the team. How many possible ways are there to create a softball team if there
are 15 women and 21 men to choose from?

16

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 26 posted: 12/15/2009 language: English pages: 16