MAD101 Assignment PDF
MAD101 Assignment PDF
T F T F
T F F T
F T T T
F T F F
F F T F
F F F F
b/ p q p q p q p q 9/ Determine whether two
p qq (distributive law) propositions are
equivalent.
p T 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 pq 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 these 10/ What is the truth
Quantifiers propositions? (the domain for variable x is values of these
{-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
true.
b/ yxP x, y
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)
• y = 3: P(1, 3), P(2, 3) are true only.
c/ TRUE
• x = 1: P(1, 3) P(3, 1)
• x = 2: P(2, 2) P(2, 2)
• x = 3: P(3, 1) P(1, 3)
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).
a) x consists of three copies of some string.
b) x is an even-length string of 0’s.
x does not contain both a 0 and a 1.
Chapter 2 – sets, sequences, sums
Sets Ex1. Determine whether each of these 15/ Determine whether
statements is true or false. each of these statements
Elements a/ 2 {2,{2}}. is true or false.
b/ 2 {{2},{{2}}}. a/ 2 {{{2}}}.
Empty set c/ {0}. b/ 2 {{2},{2,{2}}}.
d/ {, {}}. c/ {x}.
Subsets e/ ⊆ {0}. d/ {x}.
Solution.
a/ True
b/ False
c/ False
d/ True
e/ True
Cardinality of Ex. What is the cardinality of each of these 16/ What is the
a set sets? cardinality of each of
a/ {a, {a}}. these sets?
b/ {, a, {a, {a}}}. a/ {, {}}.
Solution. b/ { {a, {a}, b} }.
a/ |{a, {a}}| = 2.
b/ |{, a, {a, {a}}}| = 3.
Power set The power set of a set A, denoted by P(A), 17/ Determine whether
is the set of all subsets of A. each of these sets is the
For example, if A = {1, 2}, then the power power set of a set?
set of A is the set P(A) = {, {1}, {2}, {1, a/ .
2}}. b/ {}.
If A contains n elements, P(A) contains 2n c/ {, {a}, {}}.
elements. d/ {, {{1}}, {2}, {{1},
2}}.
Ex1. Determine whether each of these sets
is the power set of a set, where a and b are 18/ How many elements
distinct elements. does each of these sets
a/ {, {a}} have?
b/ {, {a}, {,a}} a/ P({, {a}}) .
c/ {, {a}, {b}, {a, b}} b/ P({a, {a}, {a, {a}}}).
Solution. c/ P(P({})).
a/ {, {a}} is the power set of the set {a}.
b/ {, {a}, {,a}} cannot be a power set of
any set.
c/ {, {a}, {b}, {a, b}} is the power set of
the set {a, b}.
d/
10 10 10
3i 1 3i 1
i 1 i 1 i 1
10
3 i 10
i 1
3 55 10
175
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 = 3
= 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.
(4 ≤ 8 and 9 5) i:= i+1 = 5 However, Josephus and
i=5 another rebel did not
(5 ≤ 8 and 9 6) i:= i+1 = 6 want to be killed this
i=6 way; they determined the
(6 ≤ 8 and 9 8) i:= i+1 = 7 positions where they
i=7 should stand to be the last
two rebels remaining
(7 ≤ 8 and 9 9) // the condition is false
alive.
7 ≤ 9 location = 7.
Devise an algorithm to
determine the alive
Based on the steps above, there are 15
positions if the number of
comparisons (, ) required.
rebels is n and an alive
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.
x2 + 3x + b/ f(x) = log(x3) + 2x.
1 c/ f(x) = (2x3 + x2 log
x2logx + x)/(x+2).
2018 d/ f(x) = 2x + 1.
x3 – 5x2
+3 41/ Find the least integer
Solution. k such that f(x) is O(xk)
function = O(x2) = (x2) = (x2) for each of these
2x + 11 ✓ functions.
x2 + 3x + ✓ ✓ ✓ a/ f(x) = 2x2 + x2log x.
1 b/ f(x) = x3 + (logx)4.
x2logx + ✓ c/ f(x) = (xlogx + 3x)(x2
2018 + 100x + 1).
x3 – 5x2 ✓
+3 42/ Show that 1 + 2 + 3 +
… + n is O(n2).
Ex2. Find the least integer k such that
(√𝑥 8 +𝑥 4 +1 +1)(𝑙𝑜𝑔𝑥+3)
is O(xk).
𝑥 2 +1
Solution.
x8 x4 1 x8 x4
log x 3 log x
and x 2 1 x 2
(√𝑥 8 +𝑥 4 +1 +1)(𝑙𝑜𝑔𝑥+3) x 4 log x
So, x 2 log x
𝑥 2 +1 x 2
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.
a/ 1001 = 13.77 + 0 49/ Suppose a mod 3 = 2
quotient = 77 and remainder = 0. and b mod 6 = 4, find ab
b/ -111 = 11.(-11) + 10 mod 3.
quotient = -11 and remainder = 10.
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
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.
• Suppose for every integer k 0, the
statement is true, that is, "6 divides 63/ Suppose you wish to
k3 - k" use the Principle of
• We have, (k+1)3 - (k+1) = (k3 + 3k2 Mathematical Induction
+ 3k + 1) - (k + 1) = k3 - k + 3(k2 + to prove that
k). 11! + 22! + 33! + … +
As 6 divides k3 - k and 3(k2 + k) is a nn! = (n+1)! – 1,
multiple of 6, we conclude that (k+1)3 - for all n 1.
(k+1) is also a multiple of 6. (a) Write P(1).
By induction, 6 divides n3 - n for all (b) Write P(5).
integers n ≥ 0. (c) Use P(5) to prove
P(6).
Ex2. Suppose you wish to prove that the (d) Write P(k).
following is true for all positive integers n (e) Write P(k + 1).
by using the Principle of Mathematical (f) Use the Principle of
Induction: Mathematical Induction
P(n) = “1 + 3 + 5 + …+ (2n – 1) = n2 ” to prove that P(n) is true
(a) Write P(1) for all n 1.
(b) Write P(12)
(c) Write P(13) 64/ Suppose that the only
(d) Use the fact “P(12) is true” to prove currency were 2-VND
“P(13) is true” bills and 5-VND bills.
(e) Write P(k) Use strong induction to
(f) Write P(k + 1) show that any amount
(g) Use the Principle of Mathematical greater than 3 VND could
Induction to prove that P(n) is true for all be made from a
positive integers n. combination of these
Solution. bills.
a/ “1 = 12”
b/ “1 + 3 + 5 + … + (212 – 1) = 122”
c/ “1 + 3 + 5 + … + (213 – 1) = 132”
d/ We have P(12) is true, or “1 + 3 + 5 + …
+ (212 – 1) = 122” is true.
So, 1 + 3 + 5 + … + (213 – 1)
= 1 + 3 + 5 + … + (212 – 1) + (213 – 1)
= 122 + (2.13 – 1) (due to the truth of
P(12))
= 122 + (2.12 + 1)
= (12 + 1)2
= 132.
Hence, 1 + 3 + 5 + … + (213 – 1) = 132 and
P(13) is true.
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.
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 pairs
symmetric. of positive integers such
• If xRy and yRx x = 2y and y = 2x 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, 3),
symmetric.
(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
e/ 𝑅̅
ordered pairs of positive integers such that
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
c + b = d + a (c, d)R(a, b). a/ reflexive?
Hence, R is symmetric. b/ ir-reflexive?
c/ For all positive integers a, b, c, d, m and c/ symmetric?
n, if (a, b)R(c, d) and (c, d)R(m, n), then d/ anti-symmetric?
a + d = b + c and c + n = d + m e/ asymmetric?
a+d+c+n=b+c+d+m f/ transitive?
a+n=b+m
(a, b)R(m, n).
Therefore, R is transitive.
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
the set {a, b}.
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
by Boolean product of MRMR
0 1 1 0 1 1
M R2 M R M R 0 1 1 0 1 1
1 0 0 1 0 0
1 1 1
1 1 1 .
0 1 1
d/ Let M R R2 be the matrix representing
relation R – R2.
Recall that A – B is the set of elements that
belong to A but not belong to B.
So, the relation R – R2 contains only
ordered pairs (a, b) where (a, b)R but (a,
b)R2.
So, the (i, j)-entry of M R R is 1 the (i, j)-
2
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
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
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.
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 of
1 4 3 0 the longest simple circuit
have an Euler circuit? And what is the 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/
d/
Solution.
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.
120/ Given the tree
Ex2. Given the tree
If J is chosen as the root
of the tree, what is the
If B is chosen as the root of the tree, what is
height of the tree?
the height of the tree?
Solution.
If B is the root of the tree, the levels of
nodes in the tree are shown as below:
Level 0: B
Level 1: E, F, A
Level 2: C, D
Level 3: I, G, H
Level 4: J
Recall that the height of the tree is the
maximum level of the tree. Hence, the
height of the tree is 4.
m-ary trees Ex1. a/ How many edges does a tree with 121a/ How many vertices
full m-ary 10,000 vertices have? does a full 5-ary tree with
trees and b/ How many edges does a full binary tree 100 internal vertices
properties with 1000 internal vertices have? have?
Solution. b/ How many leaves does
a/ number of edges = number of vertices – 1 a full 3-ary tree with 100
= 10000 – 1 = 9999. vertices have?
b/ Keep in mind, in a full m-ary tree we
have n = mi + 1, where n is number of 122/ Suppose a full
nodes and i is the number of internal ternary tree has 16
nodes. leaves.
In this case, n = 21000 + 1 = 2001. a/ How large can the
Number of edges = 2001 – 1 = 2000. height of the tree
possibly be?
Ex2. Suppose a full binary tree has 35 b/ How small can the
nodes. height of the tree
a/ How many leaves does the tree have? possibly be?
b/ How large can the height of the tree
possibly be?
c/ How small can the height of the tree
possibly be?
Solution.
a/ n = mi + 1 and n = i + l
35 = 2i + 1 and 35 = i + l
i = 17 and l = 18.
b/ maximum height of the tree = number of
internal nodes of the tree = 17.
c/ minimum height of the tree = logm(l) =
log2(18) = 5.
Binary search Ex1. 123/ Build a binary
trees Build a binary search tree for the words search tree for the words
banana, peach, apple, pear, coconut, EAGLE, ANT, BAT,
mango, and papaya using alphabetical DUCK, BEAR, PIG,
order. CAT and DOG using
Solution. alphabetical order.
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.
= 1 3
4
=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.