SFWR ENG 2DM3 Discrete Mathematics and Logic

Transcription

SFWR ENG 2DM3 Discrete Mathematics and Logic
SFWR ENG 2DM3
Discrete Mathematics and Logic
Solution Set 1
10 Questions
1. (Page 55, Exercise 36) Find a counterexample, if possible, to these universally quantified statements,
where the domain for all variables consists of all real numbers.
a) ∀x(x2 6= x)
b) ∀x(x2 6= 2)
c) ∀x(|x| > 0)
Solution:
a) 1√
b) 2
c) 0
2. (Page 67, Exercise 20) Express each of these statements using predicates, quantifiers, logical connectives, and mathematical operators where the domain consists of all integers.
a) The product of two negative integers is positive.
b) The average of two positive integers is positive.
c) The difference of two negative integers is not necessarily negative.
d) The absolute value of the sum of two integers does not exceed the sum of the absolute values of
these integers.
Solution:
a) ∀x∀y((x < 0 ∧ y < 0) → xy > 0)
b) ∀x∀y((x > 0 ∧ y > 0) → x+y
2 > 0)
c) ¬∀x∀y((x < 0 ∧ y < 0) → x − y < 0)
d) ∀x∀y(|x + y| ≤ |x| + |y|)
3. (Page 80, Exercise 30) Show the hypotheses “Allen is a bad boy or Hillary is a good girl” and “Allen
is a good boy or David is happy” imply the conclusion “Hillary is a good girl or David is happy”.
Solution:
Let p be the proposition “Allen is a good boy”, q be “Hillary is a good girl”, and r be “David is happy”.
We want to show (¬p ∨ q) ∧ (p ∨ r) → q ∨ r.
p
F
F
F
F
T
T
T
T
q
F
F
T
T
F
F
T
T
r
F
T
F
T
F
T
F
T
(¬p ∨ q) ∧ (p ∨ r)
F
T
F
T
F
F
T
T
q∨r
F
T
T
T
F
T
T
T
(¬p ∨ q) ∧ (p ∨ r) → q ∨ r
T
T
T
T
T
T
T
T
1
4. (Page 91, Exercise 32) Show that these statements about the real number x are equivalent: (i) x is
rational, (ii) x2 is rational, (iii) 3x − 1 is rational.
Solution:
(i) → (ii): Since x is rational x = pq , where p, q are integers with q 6= 0.
two integers it is rational.
(ii) → (iii): Similarly,
(iii) → (i): 3x − 1 =
x
2
p
q,
= pq , x =
3x =
p
q
2p
q ,
+1=
so then 3x − 1 =
p+q
q ,
x=
p+q
3q ,
6p
q
−1 =
6p−q
q ,
x
2
=
p
2q ,
as
x
2
is the ratio of
which is a ratio of two integers.
which is rational.
5. (Page 109, Exercise 38) Prove or disprove that if you have an 8-gallon jug of water and two empty jugs
with capacities of 5 gallons and 3 gallons, respectively, then you can measure 4 gallons by successively
pouring some of or all of the water in a jug into another jug.
Solution:
Let q = [q1 , q2 , q3 ] be the quantities of water in each jug, where q1 is the 8-gallon, q2 is the 5-gallon
and q3 is the 3-gallon. We will do a constructive proof, showing the sequence of steps.
[8, 0, 0], [3, 5, 0], [3, 2, 3], [6, 2, 0], [6, 0, 2], [1, 5, 2], [1, 4, 3]
6. (Page 126, Exercise 20) What is the cardinality of each of these sets?
a) ∅
b) {∅}
c) {∅, {∅}}
d) {∅, {∅}, {∅, {∅}}}
Solution:
a) 0
b) 1
c) 2
d) 3
7. (Page 155, Exercise 76) Let x be a real number. Show that b3xc = bxc + bx + 13 c + bx + 23 c.
Solution:
Let x = n + where n is an integer and 0 ≤ < 1.
Case 1: 0 ≤ < 13
b3xc = b3(n + )c = 3n
bxc + bx + 31 c + bx + 23 c = bn + c + bn + + 13 c + bn + + 32 c = n + n + n = 3n
Case 2: 31 ≤ < 23
b3(n + )c = 3n + 1
bn + c + bn + + 13 c + bn + + 23 c = n + n + n + 1 = 3n + 1
Case 3: 32 ≤ < 1
b3(n + )c = 3n + 2
bn + c + bn + + 13 c + bn + + 23 c = n + n + 1 + n + 1 = 3n + 2
8. Prove that
n
P
i2i = (n − 1)2n+1 + 2.
i=1
2
Solution:
n
n
P
P
let S =
i2i . We have 2S =
i2i+1 and thus
i=1
i=1
S = 2S − S =
n
X
i2i+1 −
i=1
n
X
i2i
i=1
That is :
S = n2n+1 − (2 + 22 + . . . + 2n ) = n2n+1 −
n
X
2i
i=1
That is :
S = n2n+1 + 1 −
n
X
2i = n2n+1 + 1 − (2n+1 − 1) = (n − 1)2n+1 + 2
i=0
9. (Page 217, exercise 26) Give a big-O estimate for each of these functions.
a) (n3 + n2 log n)(log n + 1) + (17 log n + 19)(n3 + 2)
b) (2n + n2 )(n3 + 3n )
c) (nn + n2n + 5n )(n! + 5n )
Solution:
a) (n3 + n2 log n)(log n + 1) = O(n3 log n), (17 log n + 19)(n3 + 2) = O(n3 log n), (n3 + n2 log n)(log n +
1) + (17 log n + 19)(n3 + 2) = O(n3 log n)
b) (2n + n2 ) = O(2n ), (n3 + 3n ) = O(3n ), (2n + n2 )(n3 + 3n ) = O(2n 3n )
c) (nn + n2n + 5n ) = O(nn ), (n! + 5n ) = O(nn ), (nn + n2n + 5n )(n! + 5n ) = O(n2n )
10. (Page 229, exercise 4) Give a big-O estimate for the number of operations, where an operation is an
addition or a multiplication, used in this segment of an algorithm (ignoring comparisons used to test
the conditions in the while loop).
i := 1
t := 0
while i ≤ n do
t := t + i
i = 2i
end while
Solution:
There are two operations per while loop iteration. The number of iterations, x, is the largest integer
which satisfies the inequality 2x−1 ≤ n, which is x = blog(n)c + 1. So the number of operations is
2(blog(x)c + 1) = O(log n)
3

Similar documents