Mad101 Exercises FDSSD
Mad101 Exercises FDSSD
T F T F
T F F T
F T T T
F T F F
F F T F
F F F F
(Keep in mind, p q p q )
c/ It is not rainy but we don’t go to the
movies.
(Keep in mind, p → q p q )
Equivalence Ex1. a/ Write a proposition equivalent to 8/ a/ Write a proposition
p q that uses only p, q, and the equivalent to p → q that
connective . uses only p, q, and the
b/ Write a proposition equivalent to connective .
(
( p → q) p → q . ) b/ Write a proposition
equivalent to
( )
Solution.
( p → q) p → q .
a/ p q p q ( double negation )
c/ Write a proposition
pq pq (see De Morgan's laws) equivalent to (p q)
So, p q ( p q ) . → (p q).
( ) (
b/ ( p → q ) p → q p q p q ) ( ) 9/ Determine whether two
(
p qq ) (distributive law) propositions are
equivalent.
p (F ) a/ p → q and q → p
p. b/ ( p → q r ) and
(Keep in mind, p → q p q ) ( p → q) ( p → r )
c/ p q and q q
Ex2. Determine whether two propositions
are equivalent.
a/ p → q and p → q
b/ ( p → q r ) and ( p → q ) ( p → r )
Solution.
a/ Use a truth table
p q p→q p → q
T T T T
T F F T
F T T F
F F T T
NOT EQUIVALENT.
b/ Starting from the right-hand side,
( p → q) ( p → r ) ( p q) ( p r )
pq pr
(
p p qr) (commutative and associative laws)
pqr (idempotent law)
p (q r ) (associative law)
p → (q r )
➔ EQUIVALENT.
Predicates Ex1. What is the truth values of each of 10/ What is the truth
Quantifiers these propositions? (the domain for variable values of each of these
x is {-3, -2, -1, 0, 1, 2}) propositions? (the domain
a/ x ( x 1 x 2 1) for variable x is the set of
all real numbers.)
b/ x ( x 1 x 2 1)
a/ x ( x 1 x 2 1)
c/ x ( x 1 → x 2 1)
b/ x ( x 1 x 2 1)
Solution.
a/ FALSE (counter example: x = -2) c/ x ( x 1 → x 2 1)
b/ FALSE (counter example: x = 0)
c/ TRUE (no counter example) 11/ Suppose P(x, y) is a
predicate and the universe
Ex2. Suppose P(x, y) is a predicate and the for the variables x and y
universe for the variables x and y is {1, 2, is {1, 2, 3}.
3}. Suppose P(1,3), P(2,1),
Suppose P(1, 3), P(2, 1), P(2, 2), P(2, 3), P(2,2), P(2, 3), P(2, 3),
P(2, 3), P(3, 1), P(3, 2) are true, and P(x, y) P(3, 1), P(3, 2) are true,
is false otherwise. and P(x, y) is false
Determine whether the following otherwise.
statements are true. Determine whether the
a/ xyP ( x, y ) following statements are
b/ yxP ( x, y ) true.
a/ yxP ( x, y )
c/ xy ( P ( x, y ) → P ( y, x ) )
b/
Solution. yx ( P ( x, y ) → P ( y, x ) )
a/ TRUE (we can see P(1, 3), P(2, 2), P(3,
2) are true ➔ for each x in {1, 2, 3}, there
is at least one y in {1, 2, 3}.) 12/ Find a negation of
b/ FALSE (we can see that no y in {1, 2, 3} each of these statements:
for all x in {1, 2, 3}, details are in below: a/ x(P(x) → Q(x))
b/ x(P(x) Q(x))
• y = 1: P(2, 1), P(3, 1) are true only
c/ xy(P(x, y) Q(x,
(true with x = 2, 3, all x in {1, 2, 3}).
y)
• y = 2: P(2, 2), P(3, 2) are true only.
d/ xR(x < 2 → x2 < 4)
2. The goal of this exercise is to translate some assertions about binary strings into
logic notation.
• The domain of discourse is the set of all finite-length binary strings: , 0, 1, 00, 01,
10, 11, 000, 001, . . . . (Here denotes the empty string.)
• Consider a string like 10x1y, if the value of x is 110 and the value of y is 11, then
the value of 10x1y is the binary string 10110111.
• Here are some examples of formulas and their English translations. Names for
these predicates are listed in the third column so that you can reuse them in your
solutions (as I do in the definition of the predicate NO-1S below).
From the table, if an element belongs to A – 21/ Find the sets A and B
B (the corresponding number is 1), then it if A − B ={2, 3, 5, 7}, B
also belongs to A (the corresponding − A = {1, 4}, and A ∩ B
number is also 1). ={8, 6}.
B
functions Ex1. Determine which rules are functions. 25/ Determine which
a/ f: Z → Z; f(x) = 1/(2x-1). rules are functions.
b/ f: Z → R; f(x) = 1/(2x-1). a/ f: Z → Z; f(x) = 1/(x2 -
c/ f: R → R; f(x) = 1/(2x-1). 2).
Solution. b/ f: Z → R; f(x) = 1/(x2-
a/ f: Z → Z; f(x) = 1/(2x-1). 2).
This rule is not a function, because f(2) = c/ f: R → R; f(x) = 1/(x2-
1/3 does not belong to the set Z (the set of 2).
integers).
b/ f: Z → R; f(x) = 1/(2x-1). 26/ Determine whether f
This rule is a function, we determine is a function from the set
exactly one output value for each input of all bit strings to the set
value. of integers if f(S) is the
c/ f: R → R; f(x) = 1/(2x-1). number of 0 bits in S.
This rule is not a function because f(1/2) is
not defined. 27/ Let R be the set {(a,
b) | a - 1 = b or b - 1 = a},
Ex2. Determine whether f is a function where a and b are in {-2, -
from the set of all bit strings to the set of 1, 0, 1, 2}.
integers if f(S) is the position of a 0 bit in a/ List all ordered pairs of
S. R.
Solution. b/ Is R a function?
Consider the string S = “10011” as an input, Explain your answer.
f(S) = the position of a 0 bit in S ➔
f(10011) can be 2 or 3 ➔ f is NOT a
function.
One-to-one Ex1. a/ Determine whether the function 28a/ Determine whether
from N = {0, 1, 2, …} to N is one-to-one. the function f(n) = (n +
Onto a/ f(n) = (n – 1)2. 1)2 from N = {0, 1, 2, …}
b/ Determine whether the function from Z = to N is one-to-one.
Bijection {…, -2, -1, 0, 1, 2, …} to N = {0, 1, 2, …} b/ Determine whether the
is one-to-one. function from Z = {…, -2,
Inverse −2n if n < 0 -1, 0, 1, 2, …} to N = {0,
f ( n) =
functions (f-1) 2n+1 if n 0 1, 2, …} is one-to-one.
n if n < 02
Invertible
Solution. f ( n) =
a/ f(2) = f(0) = 1 ➔ f is not one-to-one. 2n if n 0
b/
• If n, m are different negative integers 29/ Let f be the function
➔ f(n) f(m) because f(n) = -2n - in exercise 26/. Is f one-
2m = f(m). to-one?
• If n, m are different non-negative
a3 = -2a2 = -2(-4) = 8
b/ a0 = 2, a1 = -1
a2 = a1 – a0 = -1 – 2 = -3
a3 = a2 – a1 = -3 – (-1) = -2
c/ a0 = 5
a1 = a 0 = 5
a2 = a 1 = 5
a3 = a 2 = 5
Special sums Special sum: 37/ Find the value of each
n
n ( n + 1) of these (double) sums.
i = 1 + 2 + 3 + ... + n = 20
i =1 2 a/ k
Ex1. Find the value of each of these sums. k =10
10 7
a/ i b/ ( 2k − 1)
k =1
i =1
10 3 2
b/ 3 c/ ( 2i − j )
i =1 j = 0
i=1
10 3 2
c/ ( i + 3)
i =1
d/ j
i =1 j = 0
10 10 20
d/ ( 3i + 1)
i =1
e/ ( i j )
i =1 j =1
Solution.
10
10 (10 + 1)
a/ i =
i =1 2
= 55
10
b/ 3 = 3 + 3 + ... + 3 = 3 10 = 30
i=1
10 10 10
c/ ( i + 3) = i + 3 = 55 + 30 = 85
i =1 i =1 i =1
d/
10 10 10
( 3i + 1) = ( 3i ) + 1
i =1 i =1 i =1
10
= 3 i + 10
i =1
= 3 55 + 10
= 175
3 4
b/ i
i =1 j =1
20 30
c/ ( i j )
i =1 j =1
Solution.
a/
2 3
( i + j ) =
i = 0 j =1
( 0 + 1) + ( 0 + 2 ) + ( 0 + 3) // i = 0
+ (1 + 1) + (1 + 2 ) + (1 + 3) // i = 1
+ ( 2 + 1) + ( 2 + 2 ) + ( 2 + 3) //i = 2
= 27
b/
3 4
i =
i =1 j =1
1 + 1 + 1 + 1 // i = 1
+ 2 + 2 + 2 + 2 // i = 2
+ 3 + 3 + 3 + 3 // i = 3
= 24
20 30
c/ ( i j ) =
i =1 j =1
30
j
j =1
// i = 1
30
+ ( 2 j ) // i = 2
j =1
30
+ ( 3 j ) // i = 3
j =1
...
30
+ ( 20 j ) // i = 20
j =1
30
= (1 + 2 + 3 + ... + 20 ) j
j =1
20 ( 20 + 1) 30 ( 30 + 1)
=
2 2
= 97650.
Chapter 3 – Algorithms & Integers
Algorithms Ex1. List all the steps used to search for 9 38/ List all the steps used
in the sequence 2, 3, 4, 5, 6, 8, 9, 11 using a to search for 8 in the
linear search. How many comparisons sequence 3, 5, 6, 8, 9, 11,
required to search for 9 in the sequence? 13, 14 using a binary
Solution. search. How many
Below is the linear search algorithm in comparisons required to
pseudocode search for 8 in the
procedure linear search(x: integer, a1, a2,..., sequence?
an: distinct integers)
i := 1 39/ Josephus problem.
while (i ≤ n and x = ai ) This problem is based on
i := i + 1 an account by the
if i ≤ n then location := i historian Flavius
else location := 0 Josephus, who was part
return location{location is the subscript of of a band of 41 Jewish
the term that equals x, or is 0 if x is not rebels trapped in a cave
found} by the Romans during the
All the steps used to search for 9 using a Jewish Roman war of the
linear search: first century. The rebels
i=1 preferred suicide to
(1 ≤ 8 and 9 2) ➔ i:=i+1 = 2 capture; they decided to
i=2 form a circle and to
(2 ≤ 8 and 9 3) ➔ i:= i+1 = 3 repeatedly count off
i=3 around the circle, killing
(3 ≤ 8 and 9 4) ➔ i:= i+1 = 4 every third rebel left
i=4 alive. However, Josephus
(4 ≤ 8 and 9 5) ➔ i:= i+1 = 5 and another rebel did not
i=5 want to be killed this
(5 ≤ 8 and 9 6) ➔ i:= i+1 = 6 way; they determined the
i=6 positions where they
(6 ≤ 8 and 9 8) ➔ i:= i+1 = 7 should stand to be the last
i=7 two rebels remaining
alive.
(7 ≤ 8 and 9 9) // the condition is false
Devise an algorithm to
7 ≤ 9 ➔ location = 7.
determine the alive
positions if the number of
Based on the steps above, there are 15
rebels is n and an alive
comparisons (, ) required.
rebel will be killed after
counting to k (k < n).
Big-O Ex1. In the table below, check ✓if the fact 40/ Determine whether
Big-Omega is true and check otherwise. each of these functions is
Big-theta function = O(x2) = (x2) = (x2) O(x2).
2x + 11 a/ f(x) = 3x + 7.
Ex2. How much time does an algorithm 44/ How much time does
take to solve a problem of size n if this an algorithm take to solve
algorithm uses 2n2 + 2n operations, each a problem of size n if this
requiring 10−9 seconds, with these values of algorithm uses 2n2 + 2n
n? operations, each requiring
a/ 10 10−9 seconds, with these
b/ 50 values of n?
Solution. a/ 30.
a/ n = 10 ➔ the algorithm uses 2.102 + 210 b/ 100.
operations, each requiring 10−9 seconds
➔ need (2.102 + 210).10-9 = 0.000001224
seconds.
b/ n = 50 ➔ the algorithm uses 2.502 + 250
operations, each requiring 10−9 seconds ➔
need (2.502 + 250). 10-9 = 1125900 seconds.
Divide Ex1. Show that if a | b and b | c, then a | c, 45/ Show that if a | b and
Divisor where a, b, c are integers. b | a, then a = b or a = −b,
Division Solution. where a, b are integers.
Quotient a | b ➔ kZ (b = ka)
Remainder b | c ➔ mZ (c = mb) 46/ Prove or disprove that
mod and div c = m(ka) = (mk)a, where mk is an if a | bc, then a | b or a | c,
integer where a, b, and c are
a | c. positive integers and a
0.
Ex2. Prove or disprove that if ab | c, where
a, b, and c are positive integers, then a | c 47/ What are the quotient
and b | c. and remainder when
Solution. a/ −1 is divided by 3?
ab | c ➔ kZ (c = kab) b/ 3 is divided by 13?
c = (kb)a and c = (ka)b, where ka, kb c/ −123 is divided by 19?
are integers
a | c and b | c. 48/ Evaluate these
quantities.
Ex3. What are the quotient and remainder a/ −17 mod 2.
when b/ 144 mod 7.
a/ 1001 is divided by 13? c/ −101 div 13.
b/ −111 is divided by 11? d/ 199 div 19.
Solution.
5 modulo 17.
c/ 17 | (-29 – 5) ➔ -29 is congruent to 5
modulo 17.
d/ 17 (-122 – 5) ➔ -122 is not congruent
to 5 modulo 17.
Encryption Ex1. Suppose pseudo-random numbers are 52/ Suppose pseudo-
Decryption produced by using: random numbers are
xn+1 = (3xn + 11) mod 13. produced by using:
Hashing If x3 = 5, find x2 and x4. xn+1 = (2xn + 7)
functions Solution. mod 9.
• x4 = (3x3 + 11) mod 13 a/ If x 0 = 1, find x2 and x3.
Pseudo = (3.5 + 11) mod 13 = 0 b/ If x3 = 3, find x2 and
random • x3 = (3x2 + 11) mod 13 x4 .
numbers So, 5 = (3x2 + 11) mod 13
a/ 104578690
b/ 432222187
Solution.
a/ h(104578690) = 104578690 mod 101 =
58.
The memory location 58 is assigned
to the customer with the Social
Security number 104578690.
b/ h(501338753) = 501338753 mod 101 =
3.
So, the memory location 3 is assigned to the
customer with the Social Security number
501338753.
Prime, Ex1. Which positive integers less than 30 55/ Which positive
relatively are relatively prime to 30? integers less than 18 are
prime Solution. relatively prime to 18?
Recall that two positive integers a and b are
Gcd, lcm called relatively prime if and only if their 56/ Find these values of
greatest common divisor is 1. the Euler φ-function.
So, positive integers less than 30 are a/ φ(4).
relatively prime to 30 are: 1, 7, 11, 13, 17, b/ φ(5).
19, 23, 29. c/ φ(11).
Ex2. The value of the Euler φ-function at 57/ If the product of two
the positive integer n, φ(n), is defined to be integers is 3072 and their
the number of positive integers less than or least common multiple
equal to n that are relatively prime to n. is 384, what is their
Find these values of the Euler φ-function. greatest common
a/ φ(6) divisor?
b/ φ(7)
Solution.
a/ n = 6: positive integers less than or equal
to 6 that are relatively prime to 6 are: 1, 5
φ(6) = 2
b/ n = 7: positive integers less than or equal
to 6 that are relatively prime to 6 are: 1, 2,
3, 4, 5, 6
φ(7) = 6
Solution.
If a and b are positive integers, then
ab = gcd(a, b).lcm(a, b).
7 8 2 11
So, 2 3 5 7 = gcd(a, b).lcm(a, b) =
23345.lcm(a, b) ➔ lcm(a, b) =
273852711/23345 = 24345(711)
Euclidean Ex. Use the Euclidean algorithm to find 58/ Use the Euclidean
algorithm a/ gcd(8, 28) algorithm to find
b/ gcd(100, 101). a/ gcd(12, 18).
Solution. b/ gcd(111, 201).
a/ 28 mod 8 = 4 ➔ gcd(8, 28) = gcd(4, 8)
8 mod 4 = 0 ➔ gcd(4, 8) = gcd(0, 4) = 4.
b/ 101 mod 100 = 1 ➔ gcd(100, 101) =
gcd(1, 100)
100 mod 1 = 0 ➔ gcd(1, 100) = gcd(0, 1) =
1.
Integer Ex1. Convert 96 to 59/ Convert 69 to
representation a/ a binary expansion. a/ a binary expansion.
Decimal b/ a base 5 expansion. b/ a base 6 expansion.
Binary c/ a base 13 expansion. c/ a base 9 expansion.
Octal Solution.
Hexadecimal a/ 96 = (1100000)2 60/ Convert each of the
Expansions b/ following expansions to
• 96 = 19.5 + 1 decimal expansion.
Base b • 19 = 3.5 + 4 a/ (401)5
expansions • 3 = 0.5 + 3 b/ (12B7)13
96 = 19.5 + 1 = (3.5 + 4).5 + 1
96 = 3.52 + 4.51 + 1.50
96 = (341)5
c/
• 96 = 7.13 + 5
• 7 = 0.13 + 7
96 = 7.131 + 5.130
96 = (75)13
1/ UPCs. Retail products are identified by their Universal Product Codes (UPCs). The
most common form of a UPC has 12 decimal digits: the first digit identifies the product
category, the next five digits identify the manufacturer, the following five identify the
particular product, and the last digit is a check digit. The check digit is determined by the
congruence
3x1 + x2 + 3x3 + x4 + 3x5 + x6 + 3x7 + x8 + 3x9 + x10 + 3x11 + x12 ≡ 0 (mod 10).
For example, if the first 11 digits of a UPC are 79357343104, then the check digit is x12 =
2.
In fact, let x12 be check digit, we have
3 · 7 + 9 + 3 · 3 + 5 + 3 · 7 + 3 + 3 · 4 + 3 + 3 · 1 + 0 + 3 · 4 + x12 ≡ 0 (mod 10)
Simplifying, we have 98 + x12 ≡ 0 (mod 10) ➔ x12 = 2.
a/ Find the check digit for the USPS money orders that have identification number that
start with these ten digits 7555618873 and 6966133421.
b/ Determine whether 74051489623 and 88382013445 are valid USPS money order
identification number.
2/ Parity Check Bits. Digital information is represented by bit string, split into blocks of
a specified size. Before each block is stored or transmitted, an extra bit, called a parity
check bit, can be appended to each block. The parity check bit xn+1 for the bit string
x1x2...xn is defined by xn+1 = x1 + x2 +···+ xn mod 2.
(It follows that xn+1 is 0 if there are an even number of 1 bits in the block of n bits and it
is 1 if there are an odd number of 1 bits in the block of n bits). When we examine a string
that includes a parity check bit, we know that there is an error in it if the parity check bit
is wrong. However, when the parity check bit is correct, there still may be an error. For
example, if we receive in a transmission the bit string 11010110, we find that 1 + 1 + 0 +
1 + 0 + 1 + 1 ≡ 1 (mod 2), so the parity check is incorrect. So, we reject the string.
Suppose you received these bit strings over a communications link, where the last bit is a
parity check bit. In which string are you sure there is an error?
a/ 00100111111
b/ 10101010101
Chapter 4 – Induction & Recursion
Mathematical Ex1. Prove the statement "6 divides n3 - n 61/ Prove that 2 divides
induction for all integers n ≥ 0", using mathematical n2 + n whenever n is a
induction method. positive integer.
Strong Solution.
induction Basis step. The statement is true for n = 0, 62/ Prove that 2n < n! if n
since 6 divides 0. is an integer greater than
Inductive step. 3.
e/ “1 + 3 + … + (2k – 1) = k2”
f/ “1 + 3 + … + [2(k + 1) – 1] = (k + 1)2”
g/
• BASIC STEP.
“1 = 12” ➔ P(1) is true.
• INDUCTIVE STEP.
Suppose for each positive integer k, P(k) is
true, that is,
“1 + 3 + … + (2k – 1) = k2” is true.
Then, 1 + 3 + … + (2k – 1) + [2(k + 1) – 1]
= k2 + [(2(k + 1) – 1)] (due to the truth of
P(k))
= k2 + 2k + 1
= (k + 1)2
Hence, 1 + 3 + 5 + … + [2(k+1) – 1] = (k
+ 1)2 and P(k + 1) is true.
By induction, P(n) is true for all positive
integers n.
BASIS STEP.
If n = 0: sum(m, n) := m = m + 0 = m + n =
Sm(n).
INDUCTIVE STEP.
Suppose for every integer k 0, sum(m, k)
returns m + k.
We need to show that sum(m, k + 1) returns
m + k + 1.
In fact, from the algorithm, k + 1 > 0 and
sum(m, k + 1): = sum(m, k) + 1 and then
returns m + k + 1.
(by the assumption, sum(m, k) returns m +
k).
Applications.
1. Determine whether each of the following bit strings belongs to the set S
recursively defined by:
• BASIS STEP: 0 S
• RECURSIVE STEP: 1w S or 0w S if w S
a/ (the empty string)
b/ 0
c/ 110
d/ 10110
2. Let S be set of all bit strings of any length. Define the number #0(s) recursively
by:
• Basis step: #0(s) = 0, where is the empty string.
• Recursive step:
#0 (𝑠) 𝑖𝑓 𝑥 ≠ 0
#0 (𝑥𝑠) = { .
1 + #0 (𝑠) 𝑖𝑓 𝑥 = 0
a) Find #0 (111)
b) Find #0 (010)
c) What can we say about s if #0 (𝑠) = 0?
d) If s and w are two bit strings, show that #0 (𝑠𝑤) = #0 (𝑠) + #0 (𝑤 ).
Chapter 5 – Counting
Product rule & Ex1. Find the number of strings of length 7 71/ There are three
sum rule of letters of the alphabet, with no repeated available flights from
letters, that begin with a vowel. Hanoi to Bangkok and,
Counting Solution. regardless of which of
functions • Keep in mind a row of seven blanks: these flights is taken,
- - - - - - -. there are five available
Counting one- • There are five ways in which the first flights from Bangkok to
to-one letter in the string can be a vowel. Manila. In how many
functions • Once the vowel is placed in the first ways can a person fly
• a1 = 2a0 = 2.
• a2 = 2a1 = 4
$1-coin, $1-bill
$1-bill, $1-coin
$1-coin, $1-coin
$1-bill, $1-bill
• a3 = 2a2 = 2.4 = 8
• a4 = 2a3 = 16.
c/ a5 = 2a4 + a0 = 32 + 1 = 33
a6 = 2a5 + a1 = 66 + 2 = 68
a7 = 2a6 + a2 = 136 + 4 = 140.
1/ Messages are transmitted over a communications channel using two signals. The
transmittal of one signal requires 1 microsecond, and the transmittal of the other signal
requires 2 microseconds.
a/ Find a recurrence relation for the number of different messages consisting of
sequences of these two signals, where each signal in the message is immediately followed
by the next signal, that can be sent in n microseconds.
b/ What are the initial conditions?
c/ How many different messages can be sent in 10 microseconds using these two signals?
2/ Suppose inflation continues at five percent annually. (That is, an item that costs $1.00
now will cost $1.05 next year). Let an = the value (that is, the purchasing power) of one
dollar after n years.
a/ Find a recurrence relation for an.
b/ What is the value of $1000 after 10 years?
c/ What is the value of $1000 after 50 years?
d/ If inflation were to continue at ten percent annually, find the value of $1000 after 50
years.
Chapter 8 - Relations
Binary relation Ex1. List the ordered pairs in the relation R 82/ List the ordered pairs
from A ={0, 1, 2, 3, 4} to B ={0, 1, 2, 3}, in the relation R from A
Properties of where (a, b) ∈ R if and only if ={0, 1, 2, 3, 4} to B ={0,
relations a/ a + b = 4. 1, 2, 3}, where (a, b) ∈ R
b/ a | b. if and only if
Combination Solution. a/ a > b.
of relations a/ R = {(1, 3); (2, 2); (3, 1); (4, 0)} b/ a – b = 1.
b/ R = {(1, 1); (1, 2); (1, 3); (1, 0); (2, 0); (2, c/ a = 2b.
Composite 2); (3, 0); (3, 3)}.
relation 83/ Determine whether
Ex2. Determine whether the relation R on the relation R on the set
the set of all real numbers is reflexive, of all real numbers is
symmetric, antisymmetric, and/or reflexive, symmetric,
transitive, where (x, y)R if and only if antisymmetric, and/or
a/ (x, y)R x = 2y. transitive, where (x,
b/ x = 1. y)R if and only if
Solution. a/ xy = 0.
a/ x = 2y. b/ x = y + 1 or x = y – 1.
• (1, 1)R (because 1 2.1) ➔ R is c/ x y (mod 5).
not reflexive.
• 2 = 2.1 ➔ (2, 1)R but (1, 2)R 84/ Let R be the relation
(because 1 2.2) ➔ R is not on the set of ordered
symmetric. pairs of positive integers
• If xRy and yRx ➔ x = 2y and y = 2x such that
➔ x = y (= 0) ➔ R is antisymmetric. (a, b)R(c, d) ad = bc.
• (4, 2)R and (2, 1)R but (4, 1)R Show that
➔ R is not transitive. a/ R is reflexive.
b/ (x, y)R x = 1. b/ R is symmetric.
• (2, 2) R ➔ R is not reflexive. c/ R is transitive.
• (1, 2) R but (2, 1) R ➔ R is not
85/ Let R = {(1, 2), (1,
symmetric.
3), (2, 3), (3, 1)}, and S =
• If (x, y)R and (y, x)R, then x = 1
{(2, 1), (3, 1), (3, 2)} be
and y = 1 ➔ x = y.
relations on the set {1, 2,
Hence, R is antisymmetric.
3}. Find
• If (x, y)R and (y, z)R, then x = 1 a/ R – S.
and y = 1 ➔ (x, z)R. b/ R S.
Hence, R is transitive.
c/ R S.
d/ R S.
Ex3. Let R be the relation on the set of
ordered pairs of positive integers such that e/ 𝑅̅
f/ S-1.
(a, b)R(c, d) a + d = b + c.
Show that g/ SR.
a/ R is reflexive.
b/ R is symmetric. 86/ List the 16 different
c/ R is transitive. relations on the set {0,
Solution. 1}.
a/ For every positive integer a, (a, a) R (a, a)
because a + a = a + a. 87/ Which of the 16
relations on {0, 1}, are
b/ (a, b)R(c, d) a + d = b + c
Counting Ex1. How many different relations on {a, 88/ a/ How many
relations b} contain the pair (a, b)? different relations are
Solution. there on the set {a, b, c}?
Every relation on the set {a, b} is a subset b/ How many different
of the Cartesian product {a, b} {a, b}. relations on the set {a, b,
On other hand, {a, b} {a, b} = {(a, a); (a, c} do not contain (a, a)?
b); (b, a); (b, b)}, which has 24 subsets. c/ How many different ir-
There are 24 = 16 relations. reflexive relations are
there on the set {a, b, c}?
Ex2. How many different reflexive
relations are there on the set {a, b}?
Solution.
Every relation on the set {a, b} is a subset
of the Cartesian product {a, b} {a, b}.
And a reflexive relations on the set {a, b}
is a set containing both (a, a); and (b, b). By
the product rule, there are 1.1.2.2 such
subsets.
Therefore, there are 4 reflexive relations on
MR.
M R is the transpose of MR.
−1
0 0 1
MR = (MR ) = M R = 1 1 0
T
−1
1 1 0
b/ Let MR and M R be the matrices
representing relations R and R .
Recall that (i, j) R (i, j) R, or
equivalently,
(i, j)-entry = 1 in M R (i, j)-entry = 0 in
MR.
1 0 0
M R = 1 0 0 .
0 1 1
c/ Let M R 2 be the matrix representing the
relation R2.
The matrix of R2 (= RR) can be computed
is 0.
0 0 0
Therefore, M R − R 2 = 0 0 0 .
1 0 0
e/ Let M R R be the matrix representing the
2
relation RR2.
Recall that RR2 contains only ordered
pairs (a, b) that belong to exactly one of (R
– R2) and (R2 – R).
So, (i, j)-entry of M R R is 1 (i, j)-entry of
2
NOT BOTH).
0 1 1
Therefore, M R R 2 = 0 1 1 .
0 0 0
b/ Is R symmetric?
c/ Is R antisymmetric?
Solution.
a/ Recall that a relation R on a set A is
reflexive if and only if
aA, (a, a)R.
Or equivalently, in the matrix MR, the
(row i, column i)-entry is 1 for every value
of i.
We can see (3, 3)-entry of MR is 0 ➔ (3, 3)
R ➔ R is not reflexive.
b/ Recall that a relation R on a set A is
symmetric if and only if
ab, (a, b)R → (b, a) R.
Based on this definition, R is symmetric if
and only if the matrix MR is symmetric, that
is, the (i, j)-entry of MR equals to the (j, i)-
entry of MR.
Since MR is not symmetric ((1, 2)-entry of
MR is 1 and (2, 1)-entry of MR is 0), we can
conclude that R is not symmetric.
c/ Recall that the relation R is
antisymmetric if and only if (a, b) R and
(b, a) R imply that a = b. Consequently,
the matrix of an antisymmetric relation has
the property that if mij = 1 with i j, then
mji = 0. Or, in other words, either mij = 0 or
mji = 0 when i j .
So, it is easy to see that R is not
antisymmetric (m23 = m32 = 1).
Equivalence Ex1. Let R be the relation on the set of real 93/ Which of these
relations numbers such that relations on {0, 1, 2, 3}
aRb if and only if a − b is an integer. are equivalence
Partitions & Show that R is an equivalence relation. relations? What are the
equivalence Solution. equivalence classes of
classes • Because a − a = 0 is an integer for all that equivalence relation?
real numbers a, aRa for all real a/ R = {(0, 0), (1, 1), (2,
numbers a. Hence, R is reflexive. 2), (3, 3)}.
• Now suppose that aRb. Then a −b is b/ S = {(0, 0), (1, 1), (1,
an integer, so b − a is also an integer. 2), (2, 1), (2, 2), (3, 3)}.
Hence, bRa. It follows that R is c/ T = {(0, 0), (1, 1), (1,
symmetric. 3), (2, 2), (2, 3), (3, 1),
Solution.
- R is reflexive (there are loops at
every vertex).
- R is symmetric (there is an edge from
v1 to v2 whenever there is an edge
from v2 to v1).
- R is transitive (if there is an edge
from v1 to v2 and an edge from v2 to
v3, then there is an edge from v1 to
v3).
So, R is an equivalence relation.
105/ The
complementary graph
G of a simple graph G
has the same vertices as
G. Two vertices are
b/ Recall that a graph cannot have an odd adjacent in G if and only
number of vertices that have odd degrees. if they are not adjacent in
So, no graph having the degree sequence 5, G.
4, 3, 2, 1 (3 vertices that have odd degrees). a/ If G is a simple graph
c/ Suppose there is such a simple graph with 9 vertices and G has
with vertices a, b, c, d, e, f, g, h where 11 edges, how many
deg(a) = 7, deg(b) = 6, deg(c) = 5, deg(d) = edges does G have?
4, deg(e) = 4, deg(f) = 3, deg(g) = 1 and b/ If the degree sequence
deg(h) = 1. of the simple graph G is
• First, vertex a must be adjacent to 7 4, 2, 2, 1, 1, what is the
other vertices. Hence, vertex a is degree sequence of G?
adjacent to both g and h. Draw the graphs G and G.
• Next, there are 6 vertices that are
adjacent to b. From 7 remaining
vertices beside b, at least one of g
and h is adjacent to b. In this
situation, at least one of g and h must
have degree 2 or larger. It is a
contradiction with the fact deg(g) =
deg(h) = 1.
So, there is no such a simple graph.
Solution.
By the definition, the complementary
graph G is given below:
Solution.
From the matrix, the corresponding graph is
bipartite.
In fact, the set of vertices can be divided
into two parts {v1, v4} and {v2, v3}, where
v1 (row 1) and v4 (row 4) are not adjacent;
and v2 and v3 are not adjacent.
Connected Ex1. Find all cut vertices of the given 108/ Find all cut vertices
graphs graph. and all cut edges (or
bridges) of the given
Cut vertex graph.
Cut edge
Solution.
If vertex B is removed, the graph becomes
Solution.
The given graph is connected and a
removing a cut edge (or bridge) makes a
disconnected graph.
For example, if BC is removed, the graph
becomes a disconnected graph as below
0 1 0 0 1 1 has
1 0 1 0 0 1
0 1 0 1 0 1
b/
0 0 1 0 1 1
1 0 0 1 0 1
1 1 1 1 1 0
as its adjacency matrix.
0 0 1 1 1 Is this graph bipartite?
0 0 1 1 1
c/ 1 1 0 0 0
1 1 0 0 0
1 1 0 0 0
Solution.
We will show that two graphs are not
isomorphic by using a special path the one
graph has but another graph has not.
In fact, the left-hand side graph (G) has one
path making a “triangle” (e.g. u1-u2-u3)
while the graph H has no the same property.
So, two graphs are not isomorphic.
Ex2. How many paths of length 3 between 113/ How many paths of
A and B does the graph have? length 2 between a and b
does each of these graph
have?
a/
Solution.
The adjacency matrix of the graph is b/
0 1 1 1
1 0 1 0
M =
1 1 0 0
1 0 0 0
To find the number of paths of length 3
between A and B, we can multiply the (1,
2)-entry of the matrix M3.
First, we will compute M2.
0 1 1 1 0 1 1 1
1 0 1 0 1 0 1 0
M2 =
1 1 0 0 1 1 0 0
1 0 0 0 1 0 0 0
3 1 1 0
1 2 1 1
=
1 1 0 1
0 1 1 0
Next, to find the (1, 2)-entry of M3, we
multiply the first row of M2 by the second
column of M. The result is 4.
Euler Ex1. For which values of n do these graphs 114/ For which values of
paths/circuits have an Euler circuit? n do these graphs have an
a/ Kn. Euler circuit?
Hamilton b/ Cn. a/ Wn.
paths/circuits Solution. b/ Qn.
Recall that a connected graph has an Euler
circuit if and only if every vertex of this 115/ For which values of
graph has even degree. m and n does the
a/ Every vertex of Kn has degree n – 1. So, complete bipartite
Kn has an Euler circuit if and only if n is an graph Km,n have an
odd integer and n > 1. a/ Euler circuit?
b/ Every vertex of Cn has degree 2. So, Cn b/ Euler path?
has an Euler circuit for every integer n > 2.
116/ For which values of
Ex2. Does the undirected graph represented m and n does the
by the adjacency matrix complete bipartite graph
1 2 1 1 Km,n have a Hamilton
2 0 0 4 circuit?
1 0 2 3
117/ What is the length
1 4 3 0 of the longest simple
have an Euler circuit? And what is the circuit in the graph W7?
length of an Euler circuit in this graph?
Solution. 118/ Find a Hamilton
The graph is connected and its degree circuit in the graph or
sequence is 8, 8, 6, 6. So, it has an Euler explain that it does not
circuit. The length of an Euler circuit have.
equals to the number of edges the graph has,
which is (8 + 8 + 6 + 6)/2 = 14 by the
handshaking theorem.
Solution.
Suppose the graph has a Hamilton circuit,
call it (H). If a vertex has degree 2, then (H)
must pass through both two edges incident
with this vertex. So, (H) passes through the
edges a-b, a-e, f-e, f-g, c-b and c-g exactly
once.
Because b (g) has degree 3, (H) cannot pass
through all edges incident with b (g).
Hence, (H) cannot pass through d-b two
edges and d-g. It follows that (H) cannot
pass through d. It is a contradiction.
Applications.
1/ Use Dijkstra’s algorithm to find a least expensive route in terms of total dollars using
the roads in the graph between Camden and Atlantic City.
2/ Solve the traveling salesman problem for this graph by finding the total weight of all
Hamilton circuits and determining a circuit with minimum total weight.
3/ The following is a floor plan of a house. Is it possible to enter the house in room A,
travel through every interior doorway of the house exactly once, and exit out of room
E? If so, how can this be done?
Chapter 10 – Trees
Tree - Ex1. Which of these graphs are trees? 119/ Which of these
Definition a/ graphs are trees?
a/
Leaf
Internal nodes
b/
Child
b/
Parent
Height
c/
c/
Solution. d/
a/ The graph is disconnected. So, it is not a
tree.
b/ The graph is connected, but it has a
simple circuit (see a triangle). So, it is not a
tree.
c/ This graph is a tree because it is a
connected graph with no simple circuit.
c/ orange.
Solution.
a/ Staring from the root of the tree to
locate/insert the word pear:
banana < pear ➔ go to the right
peach < pear ➔ go to the right
pear = pear ➔ locating/inserting
successfully.
3 comparisons.
b/ banana = banana ➔ strop locating after
one comparison.
c/ banana < orange ➔ go to the right
peach > orange ➔ go to the left
coconut < orange ➔ go to the right
mango < orange ➔ go to the right
papaya > orange ➔ go to the left
left child of papaya is null ➔ fail to locate
the word orange.
We fail to locate orange by
comparing it successively to banana,
peach, coconut, mango, and papaya.
Once we determine that orange
should be in the left subtree of
papaya, and find no vertices there,
we know that orange is not in the
tree. Thus 5 comparisons were used.
Prefix codes Ex1. Which of these codes are prefix 126/ Which of these
codes? codes are prefix codes?
Huffman code a/ a: 11, e: 00, t : 10, s: 010. a/ a: 101, e: 11, t : 001, s:
b/ a: 01, e: 101, t : 110, s: 1101. 011, n: 010
Solution. b/ a: 010, e: 11, t : 011, s:
a/ This code scheme is a prefix code. 1011, n: 1001, i: 10101
b/ From the code scheme, we can see that t
is encoded by 110 which is also the first 127/ Construct the binary
part of the string 1101 used for s. So, this tree with prefix codes
code scheme is not a prefix code. representing these coding
schemes.
Ex2. What are the codes for a, e, i, k, o, p, a/ a: 11, e:0, t : 101, s:
and u if the coding scheme is represented by 100.
this tree? b/ a:1, e: 01, t : 001, s:
0001, n: 00001.
=4
b/ This is a postfix notation
62/5+52−∗
= 62 /5+52−∗
3
= 35 + 52-*
8
=8 52 - *
3
=83*
= 24.
b/ prefix notation:
–+xy2*y–5x
c/ postfix notation:
xy+2y 5x-*-
Applications.
1/ a/ Use Huffman coding to encode these symbols with frequencies a: 0.4, b: 0.2, c: 0.2,
d: 0.1, e: 0.1 in two different ways by breaking ties in the algorithm differently. First,
among the trees of minimum weight select two trees with the largest number of vertices
to combine at each stage of the algorithm. Second, among the trees of minimum weight
select two trees with the smallest number of vertices at each stage.
b/ Compute the average number of bits required to encode a symbol with each code and
compute the variances of this number of bits for each code. Which tie-breaking procedure
produced the smaller variance in the number of bits required to encode a symbol?
2/ Suppose that m is a positive integer with m ≥ 2. An m-ary Huffman code for a set of
N symbols can be constructed analogously to the construction of a binary Huffman
code. At the initial step, ((N − 1) mod (m − 1)) + 1 trees consisting of a single vertex with
least weights are combined into a rooted tree with these vertices as leaves. At each
subsequent step, the m trees of least weight are combined into an m-ary tree.
Using the symbols 0, 1, and 2 use ternary (m = 3) Huffman coding to encode these letters
with the given frequencies: A: 0.25, E: 0.30, N: 0.10, R: 0.05, T: 0.12, Z: 0.18.
3/ Use a decision tree to give the best way to find the lighter counterfeit coin among 24
coins.
4/ The tournament sort is a sorting algorithm that works by building an ordered binary
tree. We represent the elements to be sorted by vertices that will become the leaves. We
build up the tree one level at a time as we would construct the tree representing the
winners of matches in a tournament. Working left to right, we compare pairs of
consecutive elements, adding a parent vertex labeled with the larger of the two elements
under comparison. We make similar comparisons between labels of vertices at each level
until we reach the root of the tree that is labeled with the largest element. The tree
constructed by the tournament sort of 22, 8, 14, 17, 3, 9, 27, 11 is illustrated in part (a) of
the figure. Once the largest element has been determined, the leaf with this label is
relabeled by −∞, which is defined to be less than every element. The labels of all vertices
on the path from this vertex up to the root of the tree are recalculated, as shown in part (b)
of the figure. This produces the second largest element. This process continues until the
entire list has been sorted.
Use the tournament sort to sort the list 17, 4, 1, 5, 13, 10, 14, 6.