The Basics of Counting

Textbook
Rosen 8e, Section 6.1
Study day
Saturday, Nov 7
Homework
Written HW 7: 1–17 odd, 21–37 odd, 41, 45–59 odd, 63–73 odd
Progress
Notes not read 0 / 35 problems graded
Work each problem on paper before opening its solution, then mark it Got it or Review. Do the Core problems first if you're short on time.
6.1 #1 Core Product vs sum

There are 18 mathematics majors and 325 computer science majors at a college.

a) In how many ways can two representatives be picked so that one is a mathematics major and the other is a computer science major?
b) In how many ways can one representative be picked who is either a mathematics major or a computer science major?

Show solution
Answer

a) 5850 b) 343

a) Two tasks in sequence (pick the math rep, then the CS rep), so use the product rule: .

b) One choice from one of two disjoint groups, so use the sum rule: .

6.1 #3 Core Product rule

A multiple-choice test contains 10 questions. There are four possible answers for each question.

a) In how many ways can a student answer the questions on the test if the student answers every question?
b) In how many ways can a student answer the questions on the test if the student can leave answers blank?

Show solution
Answer

a) b)

a) 10 questions, 4 choices each: .

b) "Blank" is a fifth option for each question: .

6.1 #5 Core Product rule

Six different airlines fly from New York to Denver and seven fly from Denver to San Francisco. How many different pairs of airlines can you choose on which to book a trip from New York to San Francisco via Denver, when you pick an airline for the flight to Denver and an airline for the continuation flight to San Francisco?

Show solution
Answer

42

Two legs in sequence: .

6.1 #7 Core Product rule

How many different three-letter initials can people have?

Show solution
Answer

Three positions, 26 letters each, repetition allowed: .

6.1 #9 Core Product rule

How many different three-letter initials are there that begin with an A?

Show solution
Answer

The first letter is fixed (1 way); the other two are free: .

6.1 #11 Core Bit strings

How many bit strings of length ten both begin and end with a 1?

Show solution
Answer

Positions 1 and 10 are fixed as 1; the 8 middle bits are free: .

6.1 #13 Core Sum rule

How many bit strings with length not exceeding , where is a positive integer, consist entirely of 1s, not counting the empty string?

Show solution
Answer

For each length there is exactly one all-1s string (). By the sum rule the total is . (The book's answer includes the empty string, which this question excludes.)

6.1 #15 Core Sum rule

How many strings are there of lowercase letters of length four or less, not counting the empty string?

Show solution
Answer

Split by length (sum rule), using the product rule within each length:

(The book lists 475,255, which counts the empty string too.)

6.1 #17 Core Complement

How many strings of five ASCII characters contain the character @ ("at" sign) at least once? (There are 128 different ASCII characters.)

Show solution
Answer

"At least once," so count the complement:

6.1 #21 Core Multiples

How many positive integers between 50 and 100

a) are divisible by 7? Which integers are these?
b) are divisible by 11? Which integers are these?
c) are divisible by both 7 and 11? Which integers are these?

Show solution
Answer

a) 7: 56, 63, 70, 77, 84, 91, 98 b) 5: 55, 66, 77, 88, 99 c) 1: 77

a) : 56, 63, 70, 77, 84, 91, 98.

b) : 55, 66, 77, 88, 99.

c) Divisible by both means divisible by : only 77.

6.1 #23 Core Multiples + inclusion–exclusion

How many positive integers between 100 and 999 inclusive

a) are divisible by 7?
b) are odd?
c) have the same three decimal digits?
d) are not divisible by 4?
e) are divisible by 3 or 4?
f) are not divisible by either 3 or 4?
g) are divisible by 3 but not by 4?
h) are divisible by 3 and 4?

Show solution
Answer

a) 128 b) 450 c) 9 d) 675 e) 450 f) 450 g) 225 h) 75

There are integers. Use multiples of in .

  • Divisible by 3:
  • Divisible by 4:
  • Divisible by 12:

a) .

b) Half of 900: . (Or: first digit 9 ways, middle 10, last 5 odd: .)

c) 111, 222, …, 999: .

d) .

e) Inclusion–exclusion: .

f) Complement of (e): .

g) Divisible by 3 minus divisible by both: .

h) Divisible by both 3 and 4 means divisible by 12: .

6.1 #25 Core Product rule

How many strings of three decimal digits

a) do not contain the same digit three times?
b) begin with an odd digit?
c) have exactly two digits that are 4s?

Show solution
Answer

a) 990 b) 500 c) 27

Strings allow leading zeros, so there are total.

a) Subtract the 10 strings : .

b) First digit odd (5 ways), others free: .

c) Choose which position is not a 4 (3 ways), and that digit is any of the 9 non-4 digits: .

6.1 #27 Core Product rule

A committee is formed consisting of one representative from each of the 50 states in the United States, where the representative from a state is either the governor or one of the two senators from that state. How many ways are there to form this committee?

Show solution
Answer

Each state independently picks 1 of 3 people (governor or one of two senators). Product rule over 50 states: .

6.1 #29 Core Sum + product

How many license plates can be made using either two uppercase English letters followed by four digits or two digits followed by four uppercase English letters?

Show solution
Answer

Two disjoint formats (a plate can't be both), so add:

6.1 #31 Core Sum + product

How many license plates can be made using either two or three uppercase English letters followed by either two or three digits?

Show solution
Answer

Choose the letter part (2 or 3 letters) then the digit part (2 or 3 digits). Each part is a sum; the two parts multiply:

(Or add the four cases LL-DD, LL-DDD, LLL-DD, LLL-DDD. Same result.)

6.1 #33 Core Product rule + complement

How many strings of eight English letters are there (5 vowels, 21 consonants)

a) that contain no vowels, if letters can be repeated?
b) that contain no vowels, if letters cannot be repeated?
c) that start with a vowel, if letters can be repeated?
d) that start with a vowel, if letters cannot be repeated?
e) that contain at least one vowel, if letters can be repeated?
f) that contain exactly one vowel, if letters can be repeated?
g) that start with X and contain at least one vowel, if letters can be repeated?
h) that start and end with X and contain at least one vowel, if letters can be repeated?

Show solution
Answer

a) b) c) d) e) f) g) h)

a)

b)

c)

d)

e) Complement:

f) Choose the vowel's position (8), the vowel (5), and 7 consonants:

g) X is fixed (and X is a consonant), so the vowel must be among the other 7:

h) Six free middle letters, at least one vowel:

On an exam with no calculator, leaving answers in the forms above is fine.

6.1 #35 Core One-to-one functions

How many one-to-one functions are there from a set with five elements to sets with the following number of elements? a) 4 b) 5 c) 6 d) 7

Show solution
Answer

a) 0 b) 120 c) 720 d) 2520

One-to-one from an -set to an -set: , or if .

a) , so no one-to-one function exists: (pigeonhole!).
b)
c)
d)

6.1 #37 Core Counting functions

How many functions are there from the set , where is a positive integer, to the set

a) that are one-to-one?
b) that assign 0 to both 1 and ?
c) that assign 1 to exactly one of the positive integers less than ?

Show solution
Answer

a) 2 if , 0 if b) for (1 if ) c)

a) One-to-one needs . For : or , so 2. For : 2. For : 0.

b) is forced; the other inputs are free: (for ). If there is just function.

c) Among , choose which one gets 1: ways (the rest get 0). Then is free: 2 ways. Total .

6.1 #41 Core Bit strings

A palindrome is a string whose reversal is identical to the string. How many bit strings of length are palindromes?

Show solution
Answer

A palindrome is determined by its first half; the second half is forced to mirror it.

  • even: choose the first bits: .
  • odd: choose the first bits (including the middle): .

Both cases: .

6.1 #45 Core Division rule

At a large university, 434 freshmen, 883 sophomores, and 43 juniors are enrolled in an introductory algorithms course. How many sections of this course need to be scheduled to accommodate all these students if each section contains 34 students?

Show solution
Answer

40

students, and sections.

6.1 #47 Core Circular arrangements

How many ways are there to seat six people around a circular table where two seatings are considered the same when everyone has the same two neighbors without regard to whether they are right or left neighbors?

Show solution
Answer

60

ordered seatings. Each circular seating is counted 6 times (rotations) and another 2 times (mirror image, since left/right doesn't matter). Division rule:

6.1 #49 Core Arrangements

In how many ways can a photographer at a wedding arrange six people in a row, including the bride and groom, if

a) the bride must be next to the groom?
b) the bride is not next to the groom?
c) the bride is positioned somewhere to the left of the groom?

Show solution
Answer

a) 240 b) 480 c) 360

a) Glue bride and groom into one block: 5 units to arrange (), and the block can be BG or GB (): .

b) Complement: .

c) By symmetry, in exactly half of all arrangements the bride is left of the groom: .

6.1 #51 Core Inclusion–exclusion

How many bit strings of length 10 either begin with three 0s or end with two 0s?

Show solution
Answer

352

  • Begin with 000:
  • End with 00:
  • Both: (5 fixed bits)
6.1 #53 Challenge Complement + recursion

How many bit strings of length eight contain either three consecutive 0s or four consecutive 1s?

Show solution
Answer

147

Count the complement: strings with no and no . Such a string is made of alternating runs, where 0-runs have length 1–2 and 1-runs have length 1–3.

Let = number of valid strings of length ending in 0, and = number ending in 1. The last run of 0s has length 1 or 2 and is preceded by a valid string ending in 1 (or nothing). Similarly for 1s:

with (the empty string can precede the first run) and negative indices .

1 2 3 4 5 6 7 8
1 2 3 6 10 17 30 52
1 2 4 6 11 19 33 57

Valid strings of length 8: . So the answer is .

(Check : , since only is excluded. ✓)

6.1 #55 Core Inclusion–exclusion

How many positive integers not exceeding 100 are divisible either by 4 or by 6?

Show solution
Answer

33

.

(Both 4 and 6 means divisible by , not 24.)

6.1 #57 Core Sum rule + complement

A password must have at least 8 but no more than 12 characters, where each character is a lowercase letter, an uppercase letter, a digit, or one of the six special characters ∗, >, <, !, +, =.

a) How many different passwords are available?
b) How many of these passwords contain at least one occurrence of at least one of the six special characters?
c) How long does it take a hacker to try every possible password, at one nanosecond per password?

Show solution
Answer

a) b) c) about 314,000 years

Character set: .

a) Sum over lengths: .

b) For each length, all minus those with no special character ( choices): .

c) ns s. A year is about s, so this is about , roughly 314,000 years.

6.1 #59 Extra Sum rule (geometric series)

The name of a variable in JAVA is a string of between 1 and 65,535 characters, inclusive, where each character can be an uppercase or a lowercase letter, a dollar sign, an underscore, or a digit, except that the first character must not be a digit. Determine the number of different variable names in JAVA.

Show solution
Answer

Characters: ; the first character has options.

Names of length : . Sum over :

(The book's answer key prints the exponent as 65,536, which would include length 65,536. The question allows at most 65,535.)

6.1 #63 Core Sum rule

A wired equivalent privacy (WEP) key for a WiFi network is a string of either 10, 26, or 58 hexadecimal digits. How many different WEP keys are there?

Show solution
Answer

16 hex digits; three disjoint lengths, so add: .

6.1 #65 Core Inclusion–exclusion

Use the principle of inclusion–exclusion to find the number of positive integers less than 1,000,000 that are not divisible by either 4 or by 6.

Show solution
Answer

666,667

Integers .

  • Divisible by 4:
  • Divisible by 6:
  • Divisible by 12:

Divisible by 4 or 6: .
Neither: .

6.1 #67 Core Complement

How many ways are there to arrange the letters a, b, c, and d such that a is not followed immediately by b?

Show solution
Answer

18

Total . Arrangements with "ab" adjacent: glue ab into a block, giving 3 units and . Answer: .

6.1 #69 Core Tree diagram

Use a tree diagram to determine the number of subsets of with the property that the sum of the elements in the subset is less than 28.

Show solution
Answer

17

Branch on including or excluding each element in order, and prune once the sum reaches 28.

  • Size 0: (1)
  • Size 1: (5)
  • Size 2: (7). = 31 is too big, and so is anything else with 24.
  • Size 3: , , , (4)
  • Size 4: , too big (0)

Total: .

6.1 #71 Core Tree diagram / sum rule

A running shoe comes in women's sizes 6, 7, 8, 9 (colors: white, red, black) and men's sizes 8, 9, 10, 11, 12 (colors: white, black).

a) Use a tree diagram to determine how many different shoes a store must stock to have one pair of each size and color for both men and women.
b) Answer the question in part (a) using counting rules.

Show solution
Answer

22

a) Tree: gender → size → color. Women: 4 size branches, each with 3 color leaves (12). Men: 5 size branches, each with 2 color leaves (10). Total leaves: 22.

b) Sum rule over gender, product rule within: .

6.1 #73 Core Clever counting

Determine the minimum and the maximum number of matches that can be played in a double-elimination tournament with players, where after each game between two players, the winner goes on and the loser goes on if and only if this is not a second loss.

Show solution
Answer

Minimum , maximum .

Count losses instead of matches: every match produces exactly one loss.

  • Every player except the champion is eliminated, i.e. gets exactly 2 losses: losses.
  • The champion has either 0 or 1 losses.

So the number of matches is (champion undefeated) or (champion lost once).

Custom (from lecture) Core Product rule Not from HW

Let and .

a) How many relations are there from to ? (A relation is any subset of .)
b) How many functions are there?
c) If and , compute both numbers.

Show solution
Answer

a) b) c) 64 relations, 8 functions

a) . A relation is a subset of , and a set of size has subsets: each ordered pair is either in or out.

b) Each of the elements of chooses an image among elements: .

c) relations and functions. Every function is a relation, but most relations aren't functions.

Custom (6.1 #22h style) Core Cases Not from HW

How many positive integers less than 1000 have distinct digits and are even?

Show solution
Answer

373

Split by number of digits (sum rule). Within each, split on whether the last digit is 0, since that changes the restriction on the first digit.

1 digit: 2, 4, 6, 8: 4.

2 digits (first digit 1–9, last digit even, digits distinct):

  • last = 0: first has 9 choices: 9
  • last ∈ {2,4,6,8} (4 ways): first is 1–9 but not the last digit: 8 ways:

Total 41.

3 digits:

  • last = 0: first 9 ways, middle 8 ways (not first, not 0):
  • last ∈ {2,4,6,8} (4 ways): first 8 ways (nonzero, ≠ last), middle 8 ways (≠ first, ≠ last; 0 allowed):

Total 328.

Answer: .

Why split on the last digit?

If you choose the last digit first, how many options the first digit has depends on whether the last digit was 0. When a step's count depends on an earlier choice, split into cases.