Mid II Lecture
Mid II Lecture
Mid II Lecture
Credit Hours: 3 + 0 = 3
Prerequisite: CSE103 Structured Programming
Instructor:
Md. Mozammel Huq Azad Khan, PhD
Professor, CSE Dept., East West University
Midterm II
Link: http://bit.ly/2Nn8BLk
Md. Mozammel Huq Azad Khan, Professor, CSE, EWU Page 2
Chapter 2
Basic Structures: Sets, Functions, Sequences, and Sums
Definition 2:
The objects in a set are called the elements, or members, of the set.
We write a A to denote that a is an element of the set A.
The notation a A denotes that a is not a member of the set A.
Example 1: The set V of all vowels in the English alphabet can be written as V = {a, e, i, o, u}.
Example 2: The set O of odd positive integers less than 10 can be expressed by O = {1, 3, 5, 7, 9}.
Example 3: {a, 2, Fred, New Jersey} is the set containing the four elements a, 2, Fred, and New Jersey.
Example 4: The set of positive integers less than 100 can be denoted by {1, 2, 3, , 99}.
The set O of all odd positive integers less that 10 can be written as
O = {xx is an odd positive integer less than 10}
Definition 3: Two sets are equal if and only if they have the same elements. That is, if A and B are sets, then A
and B are equal if and only if x(x A x B). We write A = B if A and B are equal sets.
Example 7: Draw a Venn diagram that represents V, the set of vowels in the English alphabet.
Solution:
Universal set U is the set of the 26 letters of the English alphabet.
U
a e
u V i
o
Definition 4: The set A is said to be a subset of B if and only if every element of A is also an element of B. We
use the notation A B to indicate that A is a subset of the set B.
We see that A B if and only if x(x A x B) is true.
Example 8:
The set of all odd positive integers less than 10 is a subset of the set of all positive integers less than 10.
The set of rational numbers is a subset of the set of real numbers.
B
A
Definition 5: Let S be a set. If there are exactly n distinct elements in S where n is a nonnegative integer, we
say that S is a finite set and that n is the cardinality of S. The cardinality of S is denoted by S.
Example 9: Let A be the set of odd positive integers less than 10, that is, A = {1, 3, 5, 7, 9}. Then A = 5.
Example 10: Let S be the set of letters in the English alphabet. Then S = 26.
Definition 7: Given a set S, the power set of S is the set of all subsets of the set S. The power set of S is denoted
by P(S).
Example 13: What is the power set of the set {0, 1, 2}?
Solution:
P({0, 1, 2})
= {, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}
Example 14: What is the power set of the empty set? What is the power set of the set {}?
Solution:
P() = {}.
P({}) = {, {}}
Definition 8: The ordered n-tuple (a1, a2, , an) is the ordered collection that has a1 as its first element, a2 as
its second element, , and an as its nth element.
We say that two ordered n-tuples are equal if and only if each corresponding pair of their elements is equal.
In other words, (a1, a2, , an) = (b1, b2, , bn) if and only if ai = bi, for i = 1, 2, , n.
The ordered pairs (a, b) and (c, d) are equal if and only if a = c and b = d.
Definition 9: Let A and B be sets. The Cartesian product of A and B, denoted by A B, is the set of all ordered
pairs (a, b) where a A and b B.
Hence, A B = {(a, b) a A b B}.
Solution:
A B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}
A subset R of the Cartesian product A B is called a relation from the set A to the set B.
The elements of R are ordered pairs, where the first element belongs to A and the second to B.
For example,
R = {(a, 0), (a, 1), (a, 3), (b, 1), (b, 2), (c, 0), (c, 3)}
is a relation from the set {a, b, c} to the set {0, 1, 2, 3}.
The Cartesian product A B and B A are not equal, unless A = or B = (so that A B = ) or unless
A = B.
Example 17: Show that the Cartesian product B A is not equal to the Cartesian product A B, where
A = {1, 2} and B = {a, b, c}.
Solution:
B A = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1). (c, 2)}
A B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}
Therefore, B A A B.
Md. Mozammel Huq Azad Khan, Professor, CSE, EWU Page 12
Example 18: What is the Cartesian product A B C, where A = {0, 1}, B = {1, 2}, and C = {0, 1, 2}?
Solution:
AB
= {0, 1} {1, 2}
= {(0, 1), (0, 2), (1, 1), (1, 2)}
(A B) C
= {(0, 1), (0, 2), (1, 1), (1, 2)} {0, 1, 2}
= {(0, 1, 0), (0, 1, 1), (0, 1, 2),
(0, 2, 0), (0, 2, 1), (0, 2, 2),
(1, 1, 0), (1, 1, 1), (1, 1, 2),
(1, 2, 0), (1, 2, 1), (1, 2, 2)}
Definition 1: Let A and B be sets. The union of the sets A and B, denoted by A B, is the set that contains
those elements that are either in A or in B, or in both.
A B = {x x A x B}.
A B
A B is shaded
Figure 1 Venn Diagram Representing the Union of A and B.
Example 1: {1, 3, 5} {1, 2, 3} = {1, 2, 3, 5}
A B
A B is shaded
Figure 2 Venn Diagram Representing the Intersection of A and B.
Example 3: {1, 3, 5} {1, 2, 3} = {1, 3}
Definition 3: Two sets are called disjoint if their intersection is the empty set.
Example 5: Let A = {1, 3, 5, 7, 9} and B = {2, 4, 6, 8, 10}. Since A B = , A and B are disjoint.
U
B
A
A B is shaded.
Figure 3 Venn Diagram for the Difference of A and B.
Example 6:
{1, 3, 5} {1, 2, 3} = {5}
{1, 2, 3} {1, 3, 5} = {2}
𝐴 is shaded.
Figure 4 Venn Diagram for the Complement of the Set A.
Example 8: Let A = {a, e, i, o, u} (where the universal set is the set of letters of the English alpohabet).
Then 𝐴 = {b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, y, z}
Example 9: Let A be the set of positive integers greater than 10 (with universal set the set of all positive
integers).
Then 𝐴 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.
A B C contains those elements that are in at least one of the sets A, B, and C.
A B C contains those elements that are in all of sets A, B, and C.
U U
A B B
A
C C
Solution:
A B = {0, 2, 4, 6, 8} {0, 1, 2, 3, 4} = {0, 1, 2, 3, 4, 6, 8}
(A B) C = {0, 1, 2, 3, 4, 6, 8} {0, 3, 6, 9} = {0, 1, 2, 3, 4, 6, 8, 9}
Example 18: Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, and the ordering of elements of U has the elements in
increasing order. What bit strings represent the subset A of all odd integers in U, the subset B of all even
integers in U, and the subset C of integers not exceeding 5 in U?
Solution:
U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
A = {1, 3, 5, 7, 9}
B = {2, 4, 6, 8, 10}
C = {1, 2, 3, 4, 5}
Bit strings
U = 11 1111 1111
A = 10 1010 1010
B = 01 0101 0101
C = 11 1110 0000
Md. Mozammel Huq Azad Khan, Professor, CSE, EWU Page 19
Example 19: The universal set is U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. The given set is A = {1, 3, 5, 7, 9}. What is
the bit string for 𝐴 ?
Solution:
U = 11 1111 1111
A = 10 1010 1010
𝐴 = 01 0101 0101 (Bit-wise complement)
Solution:
U = 11 1111 1111
Union:
A= 11 1110 0000
B= 10 1010 1010
-----------------------------
A B = 11 1110 1010 (bit-wise OR)
The corresponding set is A B = {1, 2, 3, 4, 5, 7, 9}
Intersection:
A= 11 1110 0000
B= 10 1010 1010
-----------------------------
A B = 10 1010 0000 (bit-wise AND)
The corresponding set is A B = {1, 3, 5}
Solution:
U = 11 1111 1111
Difference:
A= 11 1110 0000
B= 10 1010 1010
𝐵= 01 0101 0101
A= 11 1110 0000
𝐵= 01 0101 0101
------------------------------------------
AB = 01 0100 0000 (Bit-wise AND)
The corresponding set is AB = {2, 4}
Definition 1:
Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A.
We write f(a) = b if b is the unique element of B assigned by the function f to the element a of A.
If f is a function from A to B, we write f : A B.
Adams A
Chou B
Goodfriend C
Rodriguez D
Stevens F
f
a b f (a )
A f B
Figure 2: The function f maps A to B.
G(Adams) = A.
Solution:
This relation defines the function f, where
f(Abdul) = 22
f(Brenda) = 24
f(Carla) = 21
f(Desire) = 22
f(Eddie) = 24
f(Felicia) = 22.
Definition 3: Let f1 and f2 be functions from A to R. Then f1 + f2 and f1 f2 are also functions from A to R defined
by
(f1 + f2)(x) = f1(x) + f2(x),
(f1 f2)(x) = f1(x) f2(x).
Example 6: Let f1 and f2 be functions from R to R such that f1(x) = x2 and f2(x) = x – x2. What are the functions
f1 + f2 and f1 f2?
Solution:
(f1 + f2)(x) = f1(x) + f2(x) = x2 + (x – x2) = x
(f1 f2)(x) = f1(x)f2(x) = x2 (x – x2) = x3 – x4
Definition 5: A function f is said to be one-to-one, or injective, if and only if f(a) = f(b) implies that a = b for
all a and b in the domain of f.
Example 8: Determine whether the function f from {a, b, c, d} to {1, 2, 3, 4, 5} with f(a) = 4, f(b) = 5, f(c) = 1,
and f(d) = 3 is one-to-one.
Solution:
The function f is one-to-one, since f takes on different values at the four elements of its domain.
a 1
b 2
c 3
d 4
Solution:
The function f(x) = x2 is not one-to-one, since f(1) = f(1) = 1, but 1 1.
Example 10: Determine whether the function f(x) = x + 1 from the set of real numbers to itself is one-to-one.
Solution:
The function f(x) = x + 1 is one-to-one, since x + 1 y + 1 when x y.
Example 11: Let f be the function from {a, b, c, d} to {1, 2, 3} defined by f(a) = 3, f(b) = 2, f(c) = 1, and
f(d) = 3. Is f an onto function?
Solution:
Since all three elements of the codomain are images of elements in the domain, f is onto.
a 1
b 2
c 3
Solution:
The function f is not onto since there is no integer x with x2 = 1, for example.
Example 13: Is the function f(x) = x + 1 from the set of integers to the set of integers onto?
Solution:
This function is onto, since for every integer y there is an integer x such that f(x) = y.
Example 14: Let f be the function from {a, b, c, d} to {1, 2, 3, 4} with f(a) = 4, f(b) = 2, f(c) = 1, and f(d) = 3.
Is f a bijective function?
Solution:
f(a) = 4
f(b) = 2
f(c) = 1
f(d) = 3
Each element of the domain maps to unique element of the codomain. So, the function f is one-to-one.
All elements of the codomain are mapped. So, the function f is onto.
As the function f is both one-to-one and onto function, it is a bijective function.
b 2 b 2 b 2
c 3 c 3 c 3
4 d d 4
one - to - one, onto, one - to - one,
not onto not one - to - one and onto
a 1 a 1
b 2 b 2
c 3 c 3
d 4 4
Neither one - to - one, Not a function
nor onto
Definition 9: Let f be a bijective function from the set A to the set B. The inverse function of f is the function
that assigns to an element b belonging to B the unique element a in A such that f(a) = b. The inverse function of
f is denoted by f1. Hence, f1(b) = a when f(a) = b.
f 1 (b)
A f 1 B
f
Figure 6 The Function f1 is the Inverse of Function f.
Example 16: Let f be the function from {a, b, c} to {1, 2, 3} such that f(a) = 2, f(b) = 3, and f(c) = 1. Is f
invertible, and if it is, what is its inverse?
Solution:
f(a) = 2
f(b) = 3
f(c) = 1
Solution:
The function f is a bijective function and is invertible.
Example 18: Let f be the function from R to R with f(x) = x2. Is f invertible?
Solution:
Since f(2) = f(2) = 4, f is not one-to-one. So, f is not a bijective function. Hence, f is not invertible.
Solution:
If f(x) = f(y), then x2 = y2, so x2 – y2 = (x + y)(x – y) =0.
This means that x + y = 0 or x – y = 0, so x = y or x = y. Because both x and y are nonnegative, we must have x
= y. so, f(x) = x2 is one-to-one.
Furthermore, f(x) = x2 is onto when the codomain is the set of all nonnegative real numbers, because each
nonnegative real number has a square root. That is, if y is a nonnegative real number, there exists a nonnegative
real number x such that x = y, which means that x2 = y.
Because the function f(x) = x2 from the set of nonnegative real numbers to the set of nonnegative real numbers
is one-to-one and onto, it is a bijective function and is invertible.
To find (f ○ g)(a) we first apply the function g to a to obtain g(a) and then we apply the function f to the result
of g(a) to obtain (f ○ g)(a) = f(g(a)).
The composition f ○ g cannot be defined unless the range of g is a subset of the domain of f.
( f g )(a)
g (a) f ( g (a))
a g g (a) f f ( g (a))
f g
Solution:
g(a) = b
g(b) = c
g(c) = a
f(a) = 3
f(b) = 2
f(c) = 1
Solution:
(f ○ g)(x) = f(g(x)) = f(3x + 2) = 2(3x + 2) + 3 = 6x + 7
(g ○ f)(x) = g(f(x)) = g(2x + 3) = 3(2x + 3) + 2 = 6x + 11
We use two steps to define a function with the set of nonnegative integers as its domain:
Solution:
f(0) = 3
f(1) = 2f(0) + 3 = 2 3 + 3 = 9
f(2) = 2f(1) + 3 = 2 9 + 3 = 21
f(3) = 2f(2) + 3 = 2 21 + 3 = 45
f(4) = 2f(3) + 3 = 2 45 + 3 = 93
Md. Mozammel Huq Azad Khan, Professor, CSE, EWU Page 42
Example 2: Give an recursive definition of the factorial function F(n) = n!.
Solution:
F(0) = 1
F(n + 1) = (n + 1) F(n)
F(5) = 5F(4)
= 5 4F(3)
= 5 4 3F(2)
= 5 4 3 2F(1)
= 5 4 3 2 1F(0)
=543211
= 120
Example 3: Give a recursive definition of an, where a is a nonzero real number and n is a nonnegative integer.
Solution:
a0 = 1
an+1 = aan for n = 1, 2, 3
Solution:
f0 = 0
f1 = 1
f2 = f1 + f0 = 1 + 0 = 1
f3 = f2 + f1 = 1 + 1 = 2
f4 = f3 + f2 = 2 + 1 = 3
f5 = f4 + f3 = 3 + 2 = 5
f6 = f5 + f4 = 5 + 3 = 8
A binary relation from A to B is a set R of ordered pairs where the first element of each ordered pair comes from
A and the second element comes from B.
Relations can be represented graphically, as shown in Figure 1, using arrows to represent ordered pairs. Another
way to represent this relation is to use a table, which is also done in Figure 1.
0
R a b
a 0 X X
1 1X
b 2 X
2
A function f from a set A to a set B assigns exactly one element of B to each element of A. The graph of f is the
set of ordered pairs (a, b) such that b = f(a). Since the graph of f is a subset of AB, it is a relation from A to B.
Moreover, the graph of a function has the property that every element of A is the first element of exactly one
ordered pair of the graph.
Example 4: Let A be the set {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b)a divides b}?
Solution:
R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}
1 1 1 2 3 4
1
2 2 2
3
3 3 4
4 4
R1 = {(a, b)a b}
R2 = {(a, b)a > b}
R3 = {(a, b)a = b or a = b}
R4 = {(a, b)a = b}
R5 = {(a, b)a = b + 1}
R6 = {(a, b)a + b 3}
Which of these relations contain each of the pairs (1, 1), (1, 2), (2, 1), (1, 1), and (2, 2)?
Solution:
(1, 1) is in R1, R3, R4, R6
(1, 2) is in R1, R6
(2, 1) is in R2, R5, R6
(1, 1) is in R2, R3, R6
(2, 2) is in R1, R3, R4
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}
R2 = {(1, 1), (1, 2), (2, 1)}
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
R6 = {(3, 4)}
Solution:
The following relations are reflexive:
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
R1 = {(a, b)a b}
R2 = {(a, b)a > b}
R3 = {(a, b)a = b or a = b}
R4 = {(a, b)a = b}
R5 = {(a, b)a = b + 1}
R6 = {(a, b)a + b 3}
Solution:
The following relations are reflexive:
Solution:
Since a a whenever a is a positive integer, the “divides” relation is reflexive.
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}
R2 = {(1, 1), (1, 2), (2, 1)}
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
R6 = {(3, 4)}
Solution:
The following relations are symmetric, because in each case (b, a) belongs to the relation whenever (a, b) does:
The following relations are antisymmetric, because for each of these relations there is no pair of elements a and
b with a b such that both (a, b) and (b, a) belong to the relation.
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
R6 = {(3, 4)}
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}
R2 = {(1, 1), (1, 2), (2, 1)}
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
R6 = {(3, 4)}
Solution:
The following relations are not antisymmetric, because there is a pair (a, b) with a b so that (a, b) and (b, a)
are both in the relation:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}
R2 = {(1, 1), (1, 2), (2, 1)}
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}
R1 = {(a, b)a b}
R2 = {(a, b)a > b}
R3 = {(a, b)a = b or a = b}
R4 = {(a, b)a = b}
R5 = {(a, b)a = b + 1}
R6 = {(a, b)a + b 3}
Solution:
The following relations are symmetric:
Solution:
This relation is not symmetric since 12, but .
It is antisymmetric, for if a and b are positive integers with ab and ba, then a = b.
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}
R2 = {(1, 1), (1, 2), (2, 1)}
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
R6 = {(3, 4)}
Solution:
The following relation is transitive:
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
[(3, 2) and (2, 1) (3, 1)
(4, 2) and (2, 1) (4, 1)
(4, 3) and (3, 1) (4, 1)
(4,3) and (3, 2) (4, 2)]
Md. Mozammel Huq Azad Khan, Professor, CSE, EWU Page 58
Example 13 (contd.):
The following relation is transitive:
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
[(1, 1) and (1, 2) (1, 2)
(1, 1) and (1, 3) (1, 3)
(1, 1) and (1, 4) (1, 4)
(1, 2) and (2, 2) (1, 2)
(1, 2) and (2, 3) (1, 3)
(1, 2) and (2, 4) (1, 4)
(1, 3) and (3, 3) (1, 3)
(1, 3) and (3, 4) (1, 4)
(1, 4) and (4, 4) (1, 4)
(2, 2) and (2, 3) (2, 3)
(2, 2) and (2, 4) (2, 4)
(2, 3) and (3, 3) (2, 3)
(2, 3) and (2, 4) (2, 4)
(2, 4) and (4, 4) (2, 4)
(3, 3) and (3, 4) (3, 4)
(3, 4) and (4, 4) (3, 4)]
R6 = {(3, 4)}
[There is no pair like (4, a) which would imply the existence of the pair (3, a)]
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}
[There are pairs (3, 4) and (4, 1) but not (3, 1)]
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}
[There are pairs (4, 1) and (1, 2) but not (4, 2)]
R1 = {(a, b)a b}
R2 = {(a, b)a > b}
R3 = {(a, b)a = b or a = b}
R4 = {(a, b)a = b}
R5 = {(a, b)a = b + 1}
R6 = {(a, b)a + b 3}
Solution:
The following relations are transitive:
Solution:
If a divides b, then b = ak
If b divides c, then c = bl
Then c = a(kl), therefore, a divides c
Hence, the “divides” relation is transitive.
Example 1: A new company with just two employees, Sahin and Parvin, rents a floor of a building with 12
offices. How many ways are there to assign different offices to these two employees?
Solution:
An office can be assigned to Sahin in 12 ways.
After assigning an office to Sahin, an office can be assigned to Parvin in 11 different ways.
Therefore, by the product rule, there are 12 11 = 132 ways to assign offices to these two employees.
Solution:
A letter can be assigned in 26 different ways
An integer can be assigned in 100 different ways
The different ways that a chair can be labeled is 26 100 = 2600
Therefore, the largest number of chairs that can be labeled differently is 2600
Example 4: How many different bit strings are there of length seven?
Solution:
Each of the seven bits can be chosen in two ways
Therefore, there are a total of 2 2 2 2 2 2 2 = 27 = 128 different bit strings of length seven.
k := 0
for i1 := 1 to n1
for i2 := 1 to n2
.
.
.
for im := 1 to nm
k := k + 1
Solution:
The initial value of k is zero
Each time the nested loop is traversed, 1 is added to k
The nested loop is traversed n1n2nm times
Therefore, the final value of k is n1n2nm
Example 11: Suppose that either a member of the mathematics faculty or a student who is mathematics major
is chosen as a representative to a university committee. How many different choices are there for this
representative if there are 37 members of the mathematics faculty and 83 mathematics majors?
Solution:
Choosing a member of the mathematics faculty can be done in 37 ways.
Choosing mathematics major can be done in 83 ways.
There are 37 + 83 = 120 possible ways to pick this representative.
Example 12: A student can choose a computer project from one of three lists. The three lists contain 23, 15,
and 19 possible projects, respectively. How many possible projects are there to choose from?
Solution:
The student can choose a project from the first list in 23 ways, from the second list in 15 ways, and from the
third list in 19 ways.
Hence, there are 23 + 15 + 19 = 57 projects to choose from.
k := 0
for i1 := 1 to n1
k := k + 1
for i2 := 1 to n2
k := k + 1
.
.
.
for im := 1 to nm
k := k + 1
Solution:
The initial value of k is zero.
This block of code is made up of m different loops. Each time a loop is traversed, 1 is added to k.
The final value of k is n1 + n2 + + nm.
Example 14: In a version of the computer language BASIC, the name of a variable is a string of one or two
alphanumeric characters, where uppercase and lowercase letters are not distinguished. Moreover, a variable
name must begin with a letter and must be different from the five strings of two characters that are reserved for
programming use. How many different variables names are there in this version of BASIC?
Solution:
Let V equal the number of different variable names in this version of BASIC.
V = V1 + V2 = 26 + 931 = 957
Solution:
Let P be the total number of possible passwords, and P6, P7, and P8 denote the number of possible passwords of
length 6, 7, and 8, respectively.
Similarly,
P7 = 367 – 267 = 78,367,164,096 – 8,031,810,176 = 70,332,353,920
When two tasks can be done at the same time, we cannot use the sum rule to count the number of ways to do
one of the two tasks. Adding the number of ways to do each task leads to an overcount, since the ways to do
both tasks are counted twice. To correctly count the number of ways to do one of the two tasks, we add the
number of ways to do each of the two tasks and then subtract the number of ways to do both tasks. This
technique is called the principle of inclusion-exclusion.
Example 17: How many bit strings of length eight either starts with a 1 bit or end with the two bits 00?
Solution:
Constructing a bit string of length eight beginning with a 1 bit can be done in 27 = 128 ways.
Constructing a bit string of length eight ending with the two bits 00 can be done in 26 = 64 ways.
Constructing a bit string of length eight that begins with a 1 and ends with 00 can be done in 25 = 32 ways.
Consequently, the number of bit strings of length eight that begin with a 1 or end with a 00 equals
128 + 64 – 32 = 160.
Counting problems can be solved using tree diagrams. To use trees in counting, we use a branch to represent
each possible choice. We represent the possible outcomes by the leaves.
Example 19: How many bit string of length four do not have two consecutive 1s?
Solution:
1st bit 1 0
2nd bit 0 1 0
3rd bit 1 0 0 1 0
4th bit
0 1 0 1 0 0 1 0
1001
0101
0001
1010
1000
0100
0010
0000
The tree diagram displays all bit strings of length four without two consecutive 1s. We see that there are eight
bit strings of length four without two consecutive 1s.
Proof.
Suppose that none of the k boxes contains more than one object. Then the total number of objects would be at
most k. This is a contradiction, since there are at least k + 1 objects.
Example 1: Among any group of 367 people, there must be at least two with the same birthday, because there
are only 366 possible birthdays.
Example 2: In any group of 27 English words, there must be at least two that begin with the same letter, since
there are 26 letters in the English alphabet.
Example 3: How many students must be in a class to guarantee that at least two students receive the same
score on the final exam, if the exam is graded on a scale from 0 to 100?
Solution:
There are 101 possible scores on the final. The pigeonhole principle shows that among any 102 students there
must be at least 2 students with the same score.
Md. Mozammel Huq Azad Khan, Professor, CSE, EWU Page 73
The Generalized Pigeonhole principle
Proof:
Suppose that none of the boxes contain more than N/k 1 objects. Then, the total number of objects is at most
N N
k 1 k 1 1 N
k k
This is a contradiction, since there are a total of N objects.
When we have N objects, the generalized pigeonhole principle tells us that there must be at least r objects in
one of the boxes as long as
N/k r
N/k + 1 > r
N/k > (r – 1)
N > k(r – 1)
N = k(r – 1) + 1 is the smallest integer satisfying the condition
Example 5: Among 100 people there are at least 100/12 = 9 who were born in the same month.
Solution:
Let
N = minimum number of students to satisfy the condition
k = 5 = total number of grades
r = 6 = minimum number of students receiving the same grade
N = k(r – 1) + 1 = 5 (6 – 1) + 1 = 26