Professional Documents
Culture Documents
Discrete Structure: Week Instructor Muhammad Waqas
Discrete Structure: Week Instructor Muhammad Waqas
4
Pigeonhole principle
• If more than k pigeons fly into k pigeonholes, then at least one hole will
have more than one pigeon.
• Pigeonhole principle: if more than k items are placed into k bins, then at
least one bin contains more than one item.
• Simple, and obvious!!
• To apply it, may not be easy sometimes. Need to be clever in identifying
pigeons and pigeonholes.
5
Example
• How many people must be in a room to guarantee that two people
have last names that begin with the same initial?
• 27 since we have 26 letters
• How many times must a single die be rolled in order to guarantee
getting the same value twice?
•7
6
Another example
• Prove that if four numbers are chosen from the set {1, 2, 3, 4, 5, 6}, at
least one pair must add up to 7.
Proof: There are 3 pairs of numbers from the set that add up to 7, i.e.,
(1, 6), (2, 5), (3, 4)
Apply pigeonhole principle: bins are the pairs, and the numbers are
the items.
7
Finite and Infinite Sets
• A set with a definite number of elements is a finite set.
• In a finite set, we can always designate one element as the first member, s1, another
element as the second member, s2 and so on. If there are k elements in the set we can
list them as
• s1, s2, …, sk
• A set that is not finite is called a infinite set.
Example
• The sets {a,b,c} and the set of computers of a particular brand in the world are finite,
but the set of integers and the set of points on a line are infinite.
8
Cont…
• A few additional subsets of R, called intervals.
• They are given below, where a < b:
• closed interval [a,b] = {x R l a ≤ x ≤ b}
• closed-open interval [a,b) = {x R l a ≤ x < b}
• open-closed interval (a,b] = {x R l a < x ≤ b}
• open interval (a,b) = {x R l a < x < b}
9
Cont…
• A bracket at an endpoint indicates it is included in the set, whereas a
parenthesis indicates it is excluded.
Example
• The set {x R l x a} is denoted by [a, ∞) using the infinity symbol
[a , ∞). Likewise, the set {x R l x ≤ a} is denoted by (-∞, a].
10
Cont…
• If a set is infinite, we may still be able to select a first element s1, a
second element s2 and so on:
s1, s2, …
• Such an infinite set is said to be denumerable.
• Both finite and denumerable sets are countable.
• Countable does not mean we can give a total number, but means that
we can say, “here is the first one” and “here is the second one” and so
on.
11
Countable and Uncountable sets
• We know from the previous topic that the sets N and Z have the same
cardinality but the cardinalities of the sets N and R are different. Thus,
we need to distinguish between two types of infinite sets.
• Sets such as N or Z are called countable because we can list their
elements:
• To define the concept more formally, consider a set A. The set A is
called countably infinite if |A|=|N|, that is, if there is a bijection
N→A.
Countable and Uncountable sets
• Respectively, the set A is called uncountable, if A is infinite but |A|≠|
N|, that is, there exists no bijection between the set of natural
numbers N and the infinite set A.
• A set is called countable, if it is finite or countably infinite.
• Thus the sets Z, O, {a,b,c,d} are countable, but the
sets R, (0,1), (1,∞) are uncountable.
Countable and Uncountable sets
• The cardinality of the set of natural numbers is
denoted ℵ0 (pronounced aleph null):|N|=ℵ0.
• Hence, any countably infinite set has cardinality ℵ0.
• Any subset of a countable set is countable.
• Any infinite subset of a countably infinite set is countably infinite.
• Let A and B be countable sets. Then their union A∪B is also
countable.
Countable sets: examples
• The set of positive integer numbers are countable.
• To prove it, we need to give a counting scheme, in this case,
1, 2, 3, 4, ….
• The set of positive rational numbers are countable
15
Uncountable sets
• There are also some sets that are uncountable.
• The set is so large, and there is no way to count out the elements.
• One example: The set of real numbers between 0 and 1 is
uncountable.
16
Formal Language
Alphabet
• A finite set ∑ of symbols is an alphabet. (∑ is the uppercase Greek letter
sigma.)
• A word (or string) over ∑ is a finite arrangement of symbols from ∑.
• For instance, the only alphabet understood by a computer is the binary
alphabet {0,1 }; every word is a finite and unique arrangement of O's and l's.
• Every zip code is a word over the alphabet {0,... ,9}. Sets such as {a, b, c, ab, bc}
are not considered alphabets since the string ab.
17
Cont…
Length of a Word
• The length of a word w, denoted by ||w||, is the number of symbols
in it.
• A word of length zero is the empty word (or the null word), denoted
by the lowercase Greek letter 𝜆 (lambda); It contains no symbols.
• For example, ll ab ll = 2, ll aabba ll = 5, and II 𝜆 ll = 0. The set of words
over an alphabet ∑ is denoted by ∑*. In particular, if ∑ denotes the
English alphabet, then ∑ * consists of all words, both meaningful and
meaningless.
• Consequently, the English language is a subset of ∑*.
18
Cont…
Language
• A language over an alphabet ∑ is a subset of ∑*. The following two
examples illustrate this definition.
Example
• The set of zip codes is a finite language over the alphabet ∑ = {0,..., 9}.
19
Cont…
Example
• Let ∑ = {a, b}. Then ∑* = {𝜆, a, b, aa, ab, ba, bb, aaa, aab, aba, abb,
baa,... }, an infinite set.
• Notice that {aa, ab, ba, bb} is a finite language over ∑, whereas {a, aa,
aba, bab, aaaa, abba,... } is an infinite language.
• Words can be combined to create new words.
20
Cont…
• The concatenation of two words x and y over an alphabet, denoted by
xy, is obtained by appending the word y at the end of x. Thus if x =
x1... xm and y = y1...yn, so xy = x1 . . .xmy1 . . .yn.
• For example, let ∑ be the English alphabet, x = CAN, and y = ADA; then
xy = CANADA. Notice that concatenation is not a commutative
operation; that is, xy ≠ yx. It is, however, associative; that is, x(yz) =
(xy)z = xyz.
21
Cont…
• Two interesting properties are satisfied by the concatenation
operation:
• The concatenation of any word x with 𝜆 is itself; that is, 𝜆x = x = x𝜆 for
every x ∑*.
• Let x,y ∑*. Then llxyll = llxll + llyll.
• For example, let ∑ = { a,b }, x = aba, and y = bbaab. Then xy =
ababbaab and llxyll = 8 = 3 + 5 = IIxll + Ilyll.
22
Recursively Defined Sets
• A new way of defining sets is using recursion.
• Notice that the set of numbers S = {2, 22, 24,...} has three interesting
characteristics:
• (1) 2 S.
• (2) If xS, then 2xS.
• (3) Every element of S is obtained by a finite number of applications
of properties 1 and 2 only.
23
Cont…
• A recursive definition of a set S consists of three clauses: (1) The basis
clause explicitly lists at least one primitive element in S, ensuring that S is
nonempty. (2) The recursive clause establishes a systematic recipe to
generate new elements from known elements. (3) The terminal clause
guarantees that the first two clauses are the only ways the elements of S
can be obtained. The terminal clause is generally omitted for
convenience.
24
Cont…
Example
• Let S be the set defined recursively as follows. (1) 2 S. (2) If x S,
then x2 S.
• Describe the set by the listing method.
• SOLUTION:
• 2 S, by the basis clause.
• Choose x = 2. Then by the recursive clause, 4 S.
• Now choose x = 4 and apply the recursive clause again, so 16 S. Continuing
like this, we get S = {2, 4, 16,256, 65536,... }.
25
Cont…
Example
• Notice that the language L = {a, aa, ba, aaa, aba, baa, bba,... } consists
of words over the alphabet ∑ = {a, b} that end in the letter a. It can be
defined recursively as follows.
a L.
If x L, then ax, bx L.
For instance, the word aba can be constructed as follows: a L. Choosing x =
a, bx = ba L.
Now choose x = ba. Then ax = aba L.
26
Cont…
• The tree diagram illustrates systematically how to derive the words in L.
27
Summary
• Sets are extremely important for Computer Science.
• A set is simply an unordered list of objects.
• Set operations: union, intersection, difference.
• To prove set equalities
• Applying existing identities
• Using mutual inclusion
• Pigeonhole principle
• Recursion of set
28
End of the Lecture
29