6.1 The Basics of Counting
Ex: 1-23, except 17
- How to count one-to-one functions (hw37)
- Product rule (and)
- Sum rule (or)
Homework
p417: 1, 6, 10, 12, 17, 28, 32a-f, 34, 37a-b,48, 49, 55, 56
1. 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?
Solution
By product rule, there are ways to pick up such two representatives.
b) In how many ways can one representative be picked who is either a mathematics major or a computer science major?
Solution
By sum rule, there are ways to pick up such representative.
6. There are four major auto routes from Boston to Detroit and six from Detroit to Los Angeles. How many major auto routes are there from Boston to Los Angeles via Detroit?
Solution
By product rule, there are routes from Boston to LA via Detroitt.
10. How many bit strings are there of length eight?
Solution
For each bit, there are 2 choices ( or ). By product rule, there are of such bit strings.
12. How many bit strings are there of length six or less, not counting the empty string?
Solution
Let the length of such bit string be .
1. For each bit, there are choices( or ). By product rule, there are of such bit strings.
2. when , there are of such bit strings; , there are of such bit strings, etcetera.
3. By sum rule, there are total of such bit strings.
17. How many strings of five ASCII characters contain the character @ ("at" sign) at least once? [Note: There are 128 different ASCII characters.
Solution
1. The number of strings of five ASCII characters is .
2. The number of strings of five ASCII characters that do not contain @ is .
3. By exclusion, the number of strings of five ASCII characters contain @ at least once is .
28. How many license plates can be made using either three digits followed by three uppercase English letters or three uppercase English letters followed by three digits?
Solution
1. When plates use three digits followd by three uppcase English letters, each of the first three characters has choices, and each of the last three characters has choices. By product rule, there are total ways of combinations.
2. When plates use three uppercase English letters followd by three digits, each of the first three characters has choices, and each of the last three characters has choices. By product rule, there are total ways of combinations.
3. By sum rule, there are total ways of combinations.
32. How many strings of eight uppercase English letters are there?
a) if letters can be repeated?
Solution
a. There are choices for each character. By product rule, there are total such strings.
b) if no letter can be repeated?
Solution
There are choices for the first character; there are choices for the 2nd character; there are choices for the 3rd character, ..., and there are for the 8th character. By product rule, there are total such strings.
c) that start with X, if letters can be repeated?
Solution
There are only choice for the first character, and there are choices for each of the rest characters. By product rule, there are total such strings.
d) that start with X, if no letter can be repeated?
Solution
There are only choice for the 1st character; there are choices for the 2nd character; there are choices for the 3rd character,..., there are choices for the 8th character. By product rule, there are total such strings.
e) that start and end with X, if letters can be repeated?
Solution
There are choice for both the lst and last characters, and there are choices for each of the rest 6 characters. By product rule, there are total such strings.
f) that start with the letters BO (in that order), if letters can be repeated?
Solution
There are choice for both the 1st and 2nd characters, and there are choices for each of the rest 6 characters. By product rule, there are total such strings.
34. How many different functions are there from a set with elements to sets with the following numbers of elements?
a) 2 b) 3 c) 4 d) 5
Solution
Let the length of set I be , and the length of set II be ( in this case), and the total number of different functions from set I to set II is .
There are ways to map each element of set I to set II. By production rule, there are total ways of such mappings, namely .
a. b. c. d.
37. How many functions are there from the set , where is a positive integer, to the set
a) that are one-to-one?
Solution
Let the 1-to-1 function be
case 1: if , there is no 1-to-1 functions.
case 2: if , there are 1-to-1 functions. These functions are
case 3: if , there are 1-to-1 functions. These functions are
b) that assign 0 to both 1 and n?
Solution
There are ways to map each element , that is not nor , in set I, to set II. There are only way to map element and to set II (). By production rule, there are total functions from set I to set II.
48.How many bit strings of length seven either begin with two 0s or end with three 1s?
Solution
1. The number of bit strings that begin with two 0s is .
2. The number of bit strings that end with three 1s is .
3. The number of bit strings that begin with two 0s and end with three 1s is .
4. By inclusion and exclusion, the number of such string is .
49. How many bit strings of length 10 either begin with three 0s or end with two 0s?
Solution
1. The number of bit strings that begin with three 0s is .
2. The number of bit strings that end with two 1s is .
3. The number of bit strings that begin with three 0s and end with two 1s is .
4. By inclusion and exclusion, the number of such string is .
55. Suppose that a password for a computer system must have at least 8, but no more than 12, characters, where each character in the password is a lowercase English letter, an uppercase English letter, a digit, or one of the six special characters ∗, >, <, !, +, and =.
a) How many different passwords are available for this computer system?
Solution
Let the length of the password be an integer
There are choices for each character. By product rule, the number of different passwords with length of is . By sum rule, the total number of such passwords is .
b) How many of these passwords contain at least one occurrence of at least one of the six special characters?
Solution
Let the total number of passwords in part a) be , the number of password that does not contain any of the six special characters be , and the number of passwords contain at least one occurence of at least one of the six special characters be .
1. By exclusion, .
2. According to part a), . Similarly, .
3.
c) Using your answer to part (a), determine how long it takes a hacker to try every possible password, assuming that it takes one nanosecond for a hacker to check each possible password.
Solution
The time is
56. The name of a variable in the C programming language is a string that can contain uppercase letters, lowercase letters, digits, or underscores. Further, the first character in the string must be a letter, either uppercase or lowercase, or an underscore. If the name of a variable is determined by its first eight characters, how many different variables can be named in C? (Note that the name of a variable may contain fewer than eight characters.)
Solution
Let the length of the variable name be an positive integer .
1. There are choices for the 1st character, and there are choices for the rest of each character.
2. By product rule, there are total such different variables with length of .
3. By sum rule, there are total different variables can be named in C.