0% found this document useful (0 votes)
1K views57 pages

MAD101 Exercise

The document describes a tool for drawing and evaluating truth tables. It allows the user to enter propositional statements and logical connectives to build truth tables, and then displays the resulting truth values. The tool supports up to five variables or propositions. It provides a simple interface for teaching the basics of propositional logic and truth tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views57 pages

MAD101 Exercise

The document describes a tool for drawing and evaluating truth tables. It allows the user to enter propositional statements and logical connectives to build truth tables, and then displays the resulting truth values. The tool supports up to five variables or propositions. It provides a simple interface for teaching the basics of propositional logic and truth tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 57

https://web.stanford.

edu/class/cs103/tools/truth-table-tool/

The Foundations: Logic and Proofs

Section 1.1
1) Which of these are propositions? What are the truth values of those that are
propositions?
The following sentences are propositions
a) Boston is the capital of Massachusetts. (True)
b) Miami is the capital of Florida (False, the correct answer is Tallahassee) 
c) 2 + 3 = 5. (True)
d) 5 + 7 = 10 (False)

These sentences are not propositions


e) x + 2 = 11. ( x is undefined)
f ) Answer this question ( a command)

2) Which of these are propositions? What are the truth values of those that are
propositions?
The following sentences are propositions
c) There are no black flies in Maine. (False)
e) The moon is made of green cheese (False)

These senteces are not propositions:


a) Do not pass go. (a command)
b) What time is it ( a question)
d) 4 + x = 5. ( x is undefined)
f) 2n ≥ 100. ( n is undefined)

3. What is the negation of each of these propositions?


a) Linda is NOT younger than Sanjay.
b) Mei DOES NOT make more money than Isabella.
c) Moshe is NOT taller than Monica.
d) Abby is NOT richer than Ricardo
4. What is the negation of each of these propositions?
a) Janice DOES NOT have more Facebook friends than Juan.
b) Quincy is NOT smarter than Venkat.
c) Zelda DOES NOT drive more miles to school than Paola.
d) Briana DOES NOT sleep longer than Gloria.

5. What is the negation of each of these propositions?


a) Mei DOES NOT have an MP3 player.
b) There IS pollution in New Jersey.
c) 2 + 1 ≠ 3.
d) The summer in Maine is NOT hot and sunny
Or The summer in Maine is hot BUT NOT sunny
Or The summer in Maine is sunny BUT NOT hot

Section 1.2
3.
4.

5.

6. Show that (p → q) → r and p → (q → r) are not logically equivalent.


p q r (p → q) (p → q) → r (q → r) p → (q → r)
F F F T F T T

7. Show that (p ∧ q) → r and (p → r) ∧ (q → r) are not logically equivalent.


p q r p^q (p ^ q) → r (p → r) (q → r) (p → r) ∧ (q → r)
T F F F T F T F

8. Show that (p → q) → (r → s) and (p → r) → (q → s) are not logically


equivalent.
p q r s (p → q) → (r → s) (p → r) → (q → s)
F F T F F T

9 Find the dual of each of these compound propositions?


a) p ∨ ¬q
p ^ ¬q
b) p ∧ (q ∨ (r ∧ T))
p v (q ^ (r v F))
c) (p ∧ ¬q) ∨ (q ∧ F)
(p v ¬q) ^ (q v T)

Section 1.4
1. Let P(x) denote the statement “x ≤ 4”. What are these truth values?
P(0): True
P(4): True
P(6): False

2. Let P(x) be the statement “the word x contains the letter a.” What are these
truth values?
a) P (orange) : True
b) P (lemon) : False
c) P (true) : False
d) P (false): True

3. Let Q(x, y) denote the statement “x is the capital of y”. What are these truth
values?
a) Q(Denver, Colorado) : True
b) Q(Detroit, Michigan) : False ( The correct answer is Lansing)
c) Q(Massachusetts, Boston) : True
d) Q(New York, New York): False(The correct answer is Albany)

4. State the value of x after the statement if P(x) then x := 1 is executed, where
P(x) is the statement “x > 1”, if the value of x when this statement is reached is
a) x = 0.
x=0
b)x = 1.
x=1
c) x = 2
x=1
5. Let P(x) be the statement “x spends more than five hours every weekday in
class,” where the domain for x consists of all students. Express each of these
a) ∃xP(x)
There exists a student who spends more than five hours every weekday in class.
b)∀xP(x)
All students spend more than five hours every weekday in class
c)∃x ¬P(x)
There exists a student who does not spend more than five hours weekday in
class

d) ∀x ¬P(x)
There are no students that spend more than five hours weekday in class

7. Let P(x) be the statement “x = x2 ”. If the domain consists of the integers, what
are these truth values?
a) P(0)
True ( 0 = 0)

b) P(1)
True ( 1 = 1)

c) P(2)
False ( 2 = 4)

d) P(−1)
False ( -1 = 1)

e) ∃xP(x)
True ( if x = 0, then 0 = 0 )
f ) ∀xP(x)
False ( if x = -1, then -1 = 1
8. Let Q(x) be the statement “x + 1 > 2x.” If the domain consists of all integers,
what are these truth values?
a) Q(0)
True ( 1 > 0)

b) Q(−1)
True ( 0 > -2)

c) Q(1)
False (2 > 2)

d) ∃xQ(x)
True ( If x = 0, then the statement is true)

e) ∀xQ(x)
False ( If x = 1, then the statement is false)

f ) ∃x¬Q(x)
True ( If x = 1, then the statement is flase)

9. Determine the truth value of each of these statements if the domain consists
of all integers.
a) ∀n(n + 1 > n)
True ( n + 1 > n ↔ 1> 0 )

b) ∃n(2n = 3n)
True ( If n = 0 , then the statement is true)
c) ∃n(n = −n)
True ( If n = 0, then the statement is true)

d) ∀n(3n ≤ 4n)
False ( 3 n ≤ 4 n ↔ n ≥0 , If n < 0 then the statement is false)

10. Determine the truth value of each of these statements if the domain consists
of all real numbers.
a) ∃x(x3 = −1)
True ( If x = -1 then the statement is true)

b) ∃x(x4 < x2 )
True ( If x = 0.5, then the statement is true)

c) ∀x((−x)2 = x2 )
True
d) ∀x(2x > x)
False (2 x> x ↔ x >0 , the statement is false when x < 0)

11. Determine the truth value of each of these statements if the domain for all
variables consists of all integers.
a) ∀n(n2 ≥ 0)
True
b) ∃n(n2 = 2)
False (The solutions n=± √2 are not intergers)
c) ∀n(n2 ≥ n)
True ( n2 ≥ n↔ n ≥ 1∨n ≤ 0), the statement is true for all integers)
d) ∃n(n2 < 0)
False

12. Suppose that the domain of the propositional function P(x) consists of the
integers 0, 1, 2, 3, and 4. Write out each of these propositions using disjunctions,
conjunctions, and negations.
a) ∃xP(x)
P(0) v P(1) v P(2) v P(3) v P(4)
b) ∀xP(x)
P(0) ^ P(1) ^ P(2) ^ P(3) ^ P(4)
c) ∃x¬P(x)
¬P(0) v ¬P(1) v ¬P(2) v ¬P(3) v ¬P(4)
d) ∀x¬P(x)
¬P(0) ^ ¬P(1) ^ ¬P(2) ^ ¬P(3) ^ ¬P(4)
e) ¬∃xP(x)
¬( P(0) v P(1) v P(2) v P(3) v P(4))
f ) ¬∀xP(x)
¬(P(0) ^ P(1) ^ P(2) ^ P(3) ^ P(4))
13.Suppose that the domain of the propositional function P(x) consists of the
integers 1, 2, 3, 4, and 5. Express these statements without using quantifiers,
instead using only negations, disjunctions, and conjunctions.
a) ∃xP(x)
P(1) v P(2) v P(3) v P(4) v P(5)
b) ∀xP(x)
P(1) ^ P(2) ^ P(3) ^ P(4) ^ P(5)
c) ¬∃xP(x)
¬( P(1) v P(2) v P(3) v P(4) v P(5))
d) ¬∀xP(x)
¬(P(1) ^ P(2) ^ P(3) ^ P(4) ^ P(5))

Section 1.5
1. Find the argument form for the following argument and determine whether it is
valid. Can we conclude that the conclusion is true if the premises are true?
If Socrates is human, then Socrates is mortal.
Socrates is human.
∴ Socrates is mortal.
P: Socrates is human
Q Socrates is mortal
1. P → Q Premise
2. P Premise
3. Q Modus ponen from (1) and (2)
Conclusion: Socrates is mortal

2. Use rules of inference to show that the hypotheses “Randy works hard”, “If
Randy works hard, then he is a dull boy”, and “If Randy is a dull boy, then he will
not get the job” imply the conclusion “Randy will not get the job”.
P: Randy works hard
Q: He is a dull boy
R: Randy will not get the job
1. P Premise
2. P → Q Premise
3. Q → R Premise
4. P → R Hypothetical syllogism
5. R Modus ponen from (1) and 4)
Conclusion: Randy will not get the job

3. For each of these collections of premises, what relevant conclusion or


conclusions can be drawn? Explain the rules of inference used to obtain each
conclusion from the premises.
a) “If I take the day off, it either rains or snows”. “I took Tuesday off or I took
Thursday off”. “It was sunny on Tuesday”. “It did not snow on Thursday”.
P: I take x off
Q: x rains
R: x snows
Summary
1. ∀x( P(x) →Q(x) v R(x)) Premise
2. P(Tuesday) v P(Thursday) Premise
3. ¬(Q(Tuesday) v R(Tuesday)) Premise
4. ¬R(Thursday) Premise
5. P(Tuesday) →Q(Tuesday) v R(Tuesday)
6. ¬P(Tuesday) Modus tollen from (3) and (5)
7. P(Thursday) Disjunctive syllogism
8. Q(Thursday) v R(Thursday) Modus ponen from (1) and (7)
9. Q(Thursday) Disjunctive syllogism from (4) and (8)

Conclusin: I took Thursday off and It rained


b) “If I eat spicy foods, then I have strange dreams”. “I have strange dreams if
there is thunder while I sleep”. “I did not have strange dreams”.
P: I eat spicy foods
Q: I have strange dreams
R: There is thunder while I sleep
Summary
1. P → Q Premise
2. R → Q Premise
3. ¬ Q Premise
4. ¬ P Modus tollen from (1) and (3)
5. ¬ R Modus tollen from (2) and (3)
Conclusion: I does not eat spicy foods and There is not thunder while I sleep

c) “I am either clever or lucky”. “I am not lucky”. “If I am lucky, then I will win the
lottery”
Summary
P: I am clerver
Q: I am lucky
R: I win the lottery
1. P v Q Premise
2. ¬ Q Premise
3. Q → R Premise
4. P Disjunctive syllogism from (1) and (2)
Conclusin: I am clever

d) “Every computer science major has a personal computer”. “Ralph does not
have a personal computer”. “Ann has a personal computer”.
Summary
P(x): x is a computer science major
Q(x): x has a personal computer
1. ∀x( P(x) →Q(x)) Premise
2. ¬Q(Ralph) Premise
3. Q(Ann) Premise
4. P(Ralph) → Q(Ralph)
5. ¬P(Ralph) Disjunctive syllogism from (2) and (4)
Conclusion: Ralph is not computer science major

e) “What is good for corporations is good for the United States”. “What is good for
the United States is good for you”. “What is good for corporations is for you to
buy lots of stuff”.
p: good for corporations
q: good for the United States
r: good for you
g: x you buy lots of stuff
1. p → q Premise
2. q → r Premise
3. g → p Premise
4. g → q Hypothetical syllogism from (1) and (3)
5. g →r Hypothetical syllogism from (2) and (4)
6. p → r Hypothetical syllogism from (1) and (2)
Conclusion: You buy lots of stuff is good for United States, you buy lots of stuff is
good for you, what is good for corporations is good for you

f ) “All rodents gnaw their food”. “Mice are rodents”. “Rabbits do not gnaw their
food”. “Bats are not rodents.
Summary
P(x): x is rodents
Q(x): x gnaw their food
1. ∀x(P(x) →Q(x)) Premise
2. P(Mice) Premise
3. ¬Q(Rabbits) Premise
4. ¬P(Bats) Premise
5. P(Mice) →Q(Mice)
6. P(Rabbits) →Q(Rabbits)
7. Q(Mice) Modus ponen from (2) and (5)
8. ¬P(Rabbits) Modus tollen from (3) and (6)
Conclusion: Mice gnaw their food and Rabbits are not rodents

4. Determine whether each of the following arguments is valid or not valid.


a) All parrots like fruit. My pet bird is not a parrot. Therefore, my pet bird does
not like fruit.
Not valid

b) Everyone who eats granola every day is healthy. Linda is not healthy.
Therefore, Linda does not eat granola every day.
True
c) No man is an island. Manhattan is an island. Therefore, Manhattan is not a
man.
Not valid
d) A convertible car is fun to drive. Isaac's car is not a convertible. Therefore,
Isaac's car is not fun to drive.
Not valid
e) If Mai knows French, Mai is smart. But Mai doesn't know French. So, she is
not smart.
Not valid
f) Lin can't go fishing if she doesn't have a bike. Last week, Lin went fishing with
her friends. Therefore, she has got a bike.
Valid

Section 2.1
2.1 Sets 1. List the members of these sets.
a) {x | x is a real number such that x2 = 1}
S = {-1,1}
b) {x | x is a positive integer less than 12}
S = {1,2,3,4,5,6,7,8,9,10,11,12}
c) {x | x is the square of an integer and x < 100}
S={0,1,4,9,16,25,36,49,64,81}
d) {x | x is an integer such that x2 = 2}
S={∅ }

2. For each of the following sets, determine whether 2 is an element of that set.
a) {x ∈ R | x is an integer greater than 1} : yes
b) {x ∈ R | x is the square of an integer} : no
c) {2,{2}} : yes
d) {{2},{{2}}} : no
e) {{2},{2,{2}}} : no
f ) {{{2}}} : no

3. Determine whether each of these statements is true or false.


a) 0 ∈ ∅ : False
b) ∅ ∈ {0}: True
c) {0} ⊂ ∅: False
d) ∅ ⊂ {0}: True
e) {0} ∈ {0}: False
f ) {0} ⊂ {0} : True
g) {∅} ⊆ {∅}: True

4. Determine whether each of these statements is true or false.


a) x ∈ {x} : True
b) {x} ⊆ {x}: True
c) {x} ∈ {x} : False
d) {x} ∈ {{x}} : True
e) ∅ ⊆ {x} :True
f ) ∅ ∈ {x}: False

5. What is the cardinality of each of these sets?


a) {a}: 1
b) {{a}}: 1
c) {a, {a}}: 2
d) {a, {a}, {a, {a}}}: 3

6. What is the cardinality of each of these sets?


a) ∅: 0
b) {∅}: 1
c) {∅, {∅}}: 2
d) {∅, {∅}, {∅, {∅}}}: 2
7. Find the power set of each of these sets, where a and b are distinct elements.
a) {a}
{∅,{a})
b) {a, b}
{∅,{a},{b},{a,b}}
c) {∅, {∅}}
{∅,{{∅}},{{{∅}}}}}

8. How many elements does each of these sets have where a and b are distinct
elements?
a) P({a, b, {a, b}}): 3
b) P({∅, a, {a}, {{a}}}):4
c) P(P(∅)):0

9. Find A2 and A3 if
a) A = {1, 3}
{1,3} x {1,3} = {(1,1),(1,3),(3,1),(3,3)}
{1,3} x {1,3} x {1,3} = {(1,1,1),(1,1,3),(1,3,1),(1,3,3),(3,1,1),(3,3,3)}
b) A = {1, a }

10. Let A 1,2,3 and B 1, a. What is the cardinality of each of these sets? a)
a) A  B: 6
b) A^2 :9
c) PB  : 4
d) P B  A
e) A  B: 4
11. Find the truth set of each of these predicates where the domain is the set of
integers.
a) P (x): x2 < 3
{0,1}
b) Q(x): x2 > x

c) R(x): 2x + 1 = 0: ∅

Section 2.2
1. Let A = {1, 2, 3, 4, 5} and B = {0, 3, 6}. Find
a) A ∪ B: {1,2,3,4,5,0,6}
b) A ∩ B: {3}
c) A – B: {1,2,4,5}
d) B − A.: {0,6}

2. Let A = {a, b, c, d, e} and B = {a, b, c, d, e, f, g, h}. Find


a) A ∪ B: {a, b, c, d, e, f, g, h}
b) A ∩ B : {a,b,c,d,e}
c) A − B: ∅
d) B – A: {f,g,h}
3. Find the sets A and B if A − B = {1, 5, 7, 8}, B − A = {2, 10}, and A ∩ B = {3, 6,
9}.
A = (A – B) ∪ (A ∩ B) = {1,5,7,8,3,6,9}
B = (B – A) ∪ (A ∩ B) = {2,10,3,6,9}

4. Let A and B be sets. Show that


a) (A ∩ B) ⊆ A
b) A ⊆ (A ∪ B)
c) A − B ⊆ A
d) A ∩ (B − A) = ∅
e) A ∪ (B − A) = A ∪ B
f) A ⊕ B = (A ∪ B) − (A ∩ B).

5. Suppose that the universal set is U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Express


each of these sets with bit strings where the ith bit in the string is 1 if i is in the
set and 0 otherwise.
a) {3, 4, 5}: 0011100000

b) {1, 3, 6, 10}: 1010010001

c) {2, 3, 4, 7, 8, 9}: 0111001110

Section 2.3

1. Why is f not a function from R to R if


a) f (x) = 1/x? x is unidentified at 0
b) f (x) = √ x ? unidentified when x < 0
c) f (x) = ± √ x 2 +1? f(a) take two values.

2. Determine whether f is a function from Z to R if

a) f (n) = ±n f(n) take two two values


2
b) f ( n )=√ n +1 True
1
c) f ( n )= 2
n +4
true
3. Find these values
a)  1,1 = 2
b)  -0,1 = 0
c)  4 = 4
d)  3.2  = 3
e)  2  = 2
1 2
f)  2 + 3  = 1

4. Determine whether each of these functions from {a, b, c, d} to itself is one-to-


one (onto)
a) f (a) = b, f (b) = a, f (c) = c, f (d) = d: yes
b) f (a) = b, f (b) = b, f (c) = d, f (d) = c: no
c) f (a) = d, f (b) = b, f (c) = c, f (d) = d: no
5. Determine whether each of these functions from Z to Z is one-to-one (onto)

a) f (n) = n – 1: yes
b) f (n) = n2 +1: no
c) f (n) = n3: no
n
d) f(n) =  2 : no

6. Determine whether f : Z × Z → Z is onto if


a) f (m, n) = 2m – n: no
b) f (m, n) = m2 +n2: no
f(1,1) = f(-1,1)
c) f (m, n) = m + n + 1: no
d) f (m, n) = |m| − |n|: no
e) f (m, n) = m2−4: no
f) f (m, n) = m + n: no

7. Determine whether each of these functions is a bijection from R to R.


a) f (x) = −3x + 4: yes

b) f (x) = −3 x 2+7 : no

c) f (x) = (x + 1)/(x + 2): no

d) f (x) = x 5+ 1: yes

8. Let S = {−1, 0, 2, 4, 7}. Find f (S) if


a) f (x) = 1
b) f (x) = 2x + 1
x
c) f (x) =  5 

9. Let f be the function from R to R defined by f (x) = x 2 . Find


Section 2.4
1. 1. Find these terms of the sequence {an}, where an = 2(−3)n +5 n.

a) a 0 2
b) a 1 -1
c) a 4 182
d) a 5 -461

2. What is the term a8 of the sequence {an} if an equals


a.) a8 = 2n - 1= 28 - 1 =27 = 128
b.) a8 = 7 = 7
c.) a8 = 1 + (-1)n = 1 +(-1)8 = 1 + 1 = 2
d.) a8 = – (-2)n = –(-2)8= -256
Section 3
2. Devise an algorithm that finds the sum of all the integers in a list.
Sum:=0
Foreach element in list:
Sum: = Sum + element
3. List all the steps used to search for 9 in the sequence 1, 3, 4, 5, 6, 8, 9, 11
using
a) a linear search
location:=0
Step 1: 1  9
Step 2: 3  9
Step 3: 4  9
Step 4: 5  9
Step 5: 5  9
Step 6: 8  9
Step 7: 9 = 9: location = 7

Step 8: 8  9
b) a binary search.
i:=1
j:=8
Step 1: i < j
m = (i+j)/2= 4
9 > a m=5: i = m + 1 = 5
Step 2: I < j
m = (i+j)/2= 6
9 > a m=8 : i = m + 1 = 7
Step 3: i < j
m = (i+j)/2= 7
9 == a m=9 : location = 7

4. Describe an algorithm that inserts an integer x in the appropriate position into


the list a1, a2, . . . , an of integers that are in increasing order
For i:= 1 to n
If a i< ai+1:
Location:= i
End
Else

If i > n
Location = i

5. Use the bubble sort to sort 3, 1, 5, 7, 4, showing the lists obtained at each
step.
Section 3.2
1. Determine whether each of these functions is O(x).
a) f (x) = 10
if x > 10 then x > f(x) = 10
|f(x)| ≤ C|g(x)| whenever x > k = 10, C = 1 . Therfore, f(x) is O(x)
b) f (x) = 3x + 7
If x > 7, then 4x > 3x + 7
f(x)| ≤ C|g(x)| when x > 7, C = 4
Therefore f(x) is O(x)
c) f ( x )=x 2 + x +1
x 2+ 1> 0 , ∀ x

↔ x2 + x +1> x , ∀ x
There is no k,C such that f(x)| ≤ C|g(x)| and x > k for every
arbitrarily large x.Therefore, f(x) is not O(x)
d) f (x) = 5 log x
Observe that, x <e x whenever x >1
↔ log ( x ) < x whenever x>1

↔ 5 log ( x ) <5 x whenever x >1

|f(x)| ≤ C|g(x)| when x > 1, C=5


Therefore, f(x) is O(x)
2. Determine whether each of these functions is O( x 2).
a) f (x) = 17x + 11
Observe that, 17 x <17 x2 ∧11< x 2 when x >4
↔ 17 x +11< 17 x 2 + x 2 when x >4

↔ 17 x +11< 18 x 2 when x > 4


C= 18, |f(x)| ≤ C|g(x)| when x > k = 4. Therefore, f(x) is O( x 2).
b) f ( x )=x 2 +1000
x 2> 1000∧2 x 2> x 2 when x >32

↔ 3 x 2 > x 2+ 1000 when x >32


|f(x)| ≤ C|g(x)| when x > k = 32, C= 3. Therefore, f(x) is O( x 2).

c) f (x) = x log x
x <e x , when x >1

↔ log ( x ) < x , when x >1

↔ xlog ( x )< x2 , when x >1

|f(x)| ≤ C|g(x)| when x > k = 1, C =1. Therefore, f(x) is O( x 2).

4
x
d) f ( x )=
2

x4 2
Suppose that there is c,k for which ≤ C x whenever x >k
2

x2
Observe that when x > k > 0: ≤C
2

x2
The inequality ≤ C cannot hold for all x with x > k. Therefore, f(x)
2
is not O( x 2).

e) f ( x )=2 x
Cx2
Observe that lim =¿ 0 ¿, C is a consant.
x→ ∞ 2x

Therefore, the inequality 2 x ≤ Cx2cannot hold for all x with x >k. f(x) is not O( x 2).

3
x +2 x
f) f ( x )=
2 x +1
Observe that x 3< 2 x 3∧2 x< x2 whenever x> 2

x 3+ 2 x <2 x3 + x 2 whenever x >2

↔ x3 +2 x< x2 ( 2 x +1 ) whenever x>2

↔ x3 +2 x< x2 ( 2 x +1 ) whenever x>2


Observe that , 2 x +1>0 whenever x >2

x3 +2 x 2
<x
2 x +1
C= 1, |f(x)| ≤ C|g(x)| when x > k = 2. Therefore, f(x) is O( x 2).

3.Find the least integer n such that f(x) is O(x) for each of these functions.

a) f ( x)  2 x 3  x 2 log x
2 x 3  x 2 log x  2 x 3  x3 , x  0
2 x 3  x 2 log x  3 x 3
C= 3, |f(x)| ≤ C|g(x)| when x > k = 0 Therefore, n = 3.

b) f ( x)  3 x 3  (log x) 4
3 x 3  (log x) 4  3 x 3  x 3 , x  1
3 x 3  (log x) 4  4 x 3
C= 4, |f(x)| ≤ C|g(x)| when x > k = 1 Therefore, n = 3.

x4  x2  1
c) f ( x) 
x3  1
Simplify fraction first.

x4  x2  1 1
 x
x 1
3
x 1
1
x  2 x, x  1
x 1
C= 2, |f(x)| ≤ C|g(x)| when x > k = 1.Therefore, n = 1.

4. Determine whether x 3 is O(g(x)) for each of these functions g(x).


a) g ( x )=x 2
Observe that, x 3 > x2 whenevere x >1 . There is no k,c The inequality |f(x)| ≤ C|
g(x)| can not hold for all x
b) g ( x )=x 3
x 3 >0 when x >0

↔ 2 x 3 > x 3 when x >0

C = 2, |f(x)| ≤ C|g(x)| when x > 0. Therefore x 3 is O(g(x))


c) g ( x )=x 2+ x 3
0 ¿ x 2 when x >0

↔ x3 < x 2 + x 3 when x> 0

C = 1, |f(x)| ≤ C|g(x)| when x > 0. Therefore x 3 is O(g(x))


d) g ( x )=x 2+ x 4
0 ¿ x 2 when x >0

↔ x 4 < x 2+ x 4 when x> 0

C = 1, |f(x)| ≤ C|g(x)| when x > 0. Therefore x 3 is O(g(x))


e) g(x) = 3 x
x3
Observe that, lim =0
x→ ∞ 3x

There is no costant k,c such that |f(x)| ≤ C|g(x)| when x is


arbitrarily large. Therefore x 3 is not O( g(x) )
x3
f ) g ( x )=
2
x3 3
(4 =2 x ¿ ¿ 3)> x when x >0 ¿
2

C = 4, |f(x)| ≤ C|g(x)| when x > 0. Therefore x 3 is O(g(x))

5) Arrange the functions n ,1000log n, n log n,2n !,2 ,3 , n / 1000000 in a


n n 2

list so that each function is big-O of the next function.

1000log n, n , n log n, n 2 / 1000000,2n ,3 n ,2n !

6) Give as good a big-O estimate as possible for each of these functions

a)( n 2  8)(n  1)
(n 2  8)(n  1)  n3  n 2  8n  2
Biggest term is n3 so the function is O(n3 ).

b)(n log n  n 2 )(n 3  2)


 n 4 log n  n5  2n log n  2n 2
Biggest term is n5 so the function is O(n5 ).

c )(n ! 2n )(n 3  log(n 2  1))


 n 3 n ! n !log( n 2  1)  2n n 3  2n log( n 2  1)

Biggest term is n n ! so the function is O( n n ! ).


3 3

Section 3.3
1. Consider the algorithm
procedure giaithuat(a 1 , a2 , a3 , … , an : integers)
count:= 0 for i:= 1 to n do

if a i> 0 then count: = count + 1


print(count)
---------------------------------------------------------------------
Number of comparisons for the worst case:
n + 1 (compare i to n)
n (compare a i to 0 )
Total: 2n + 1
The algorithm is O(n)

2. Consider the algorithm


Number of comparison for the worst case:
n + 1 (compare i to n)
Total: n + 1
The algorithm is O(n)

3. Consider the algorithm


Number of comparison for the worst case:
n (compare i to n)
n -1 (compare a to max )
Total: 2n - 1
The algorithm is O(n)

Section 3.4
1. Does 17 divide each of these numbers?
a) 68
17 | 68, 68 / 17 = 4
b) 84
17 ∤ 84 , 84 / 17 = 84 /17
c) 357
17 | 357, 357 / 17 = 21
d) 1001
17 ∤ 1001, 1001 / 17 = 1001 / 17
2. What are the quotient and remainder when
a) 19 is divided by 7?
19 = 7 x 2 + 5
Therefore, q = 2 and r = 5
b) −111 is divided by 11?
Dividen must be a positive integer
c) 789 is divided by 23?
789 = 23 x 34 + 7
Therefore, q = 34 and r = 7
d) 1001 is divided by 13?
1001 = 13 x 77
Therefore, q = 77 and r = 0
e) 0 is divided by 19?
Dividen must be a positive integer
f ) 3 is divided by 5?
3=5x0+3
Therefore, q = 0 and r = 3
3. Suppose that a and b are integers, a ≡ 4 (mod 13), and b ≡ 9 (mod 13). Find
the integer c with 0 ≤ c ≤ 12 such that
a) c ≡ 9a (mod 13)
c ≡ 9(4) (mod 13)
c ≡ 36 (mod 13)
10 ≡ 36 (mod 13) because 36 = 13 · 2 + 10
c = 10
b) c ≡ 11b (mod 13)
c ≡ 11(9) (mod 13)
c ≡ 99 (mod 13)
8 ≡ 99 (mod 13) because 99 = 13 x 7 + 8
c=8
c) c ≡ a + b (mod 13)
c ≡ 4 + 9 (mod 13)
c ≡ 13 (mod 13)
0 ≡ 13 (mod 13) because 13 = 13 x 1 + 0
c=0
e)

6. Decide whether each of these integers is congruent to 5 modulo 17.


a) 80
17 ∤80 – 5
80 ≢ 5 (mod 17)

b) 103
17 ∤103 - 5
103 ≢ 5 (mod 17)

c) −29
17 | (5-(-29) = 34
-29 ≡ 5 (mod 17)
d) −122
17 ∤ (5-(-122) = 127
-122 ≢ 5 (mod 17)

7. Find each of these values.


a) (992 mod 32)3 mod 15
992 mod 32=0

(992 mod 32)3 mod 15=03 mod 15

0 mod 15 = 0
Result: 0

b) (34 mod 17)2 mod 11


34 modulo 17 = 0
(34 mod 17)2 mod 17=02 mod 11

0 mod 11 = 0
Result: 0
c) (193 mod 23)2 mod 31
193 mod 23 = 9

(193 mod 23)2 mod 31=92 mod 31

92 mod 31=81mod 31
81 mod 31=19

Result: 19
d) (893 mod 79)4 mod 26
893 mod 79=24

(893 mod 79)4 mod 26=24 4 mod 26

24 4 mod 26=331776 mod 26


331776 mod 26=16

Result: 16

9. Convert the binary expansion of each of these integers to a decimal expansion


a) (11011)₂
= (1 × 2⁴) + (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2⁰)
= (27)₁₀

b) (1010110101)₂
= (1 × 2⁹) + (0 × 2⁸) + (1 × 2⁷) + (0 × 2⁶) + (1 × 2⁵)
+ (1 × 2⁴) + (0 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰)
= (693)₁₀

c) (1110111110)₂
= (1 × 2⁹) + (1 × 2⁸) + (1 × 2⁷) + (0 × 2⁶) + (1 × 2⁵)
+ (1 × 2⁴) + (1 × 2³) + (1 × 2²) + (1 × 2¹) + (0 × 2⁰)
= (958)₁₀
d) (111110000011111)₂
= (1 × 2¹⁴) + (1 × 2¹³) + (1 × 2¹²) + (1 × 2¹¹) + (1 × 2¹⁰)
+ (0 × 2⁹) + (0 × 2⁸) + (0 × 2⁷) + (0 × 2⁶) + (0 × 2⁵)
+ (1 × 2⁴) + (1 × 2³) + (1 × 2²) + (1 × 2¹) + (1 × 2⁰)
= (31775)₁₀

12. Convert 69 to
a) a binary expansion

Remainder
Division Quotient (Digit) Digit #
69/2 34 1 0
34/2 17 0 1
17/2 8 1 2
8/2 4 0 3
4/2 2 0 4
2/2 1 0 5
1/2 0 1 6
= (1000101)2

b) a base 6 expansion

Remainder
Division Quotient (Digit) Digit #
69/6 11 3 0
11/6 1 5 1
1/6 0 1 2
= (153)6

c) a base 9 expansion

Remainder
Division Quotient (Digit) Digit #
69/9 7 6 0
7/9 0 7 1
= (76)9

13. Suppose a mod 3 = 2 and b mod 6 = 4, find ab mod 3.

Section 3.5
2. Find the prime factorization of each of these integers.
a) 39
31 x 131
b) 81
34
c) 101
101
d) 143
111 x 131
e) 289
172
f ) 899
291 x 311
6) Find these values of the Euler φ-function.

Section 3.6
1. Suppose pseudo-random numbers are produced by using: x n+1=(3 x n+ 11) mod 13
. If x 3= 5, find x 2 and x 4.
x 4 =( 3 x3 +11 ) mod13=( 3∗5+11 ) mod 13=0
x 5=( 3 x 4 +11 ) mod13=11

x 6=( 3 x 5 +11 ) mod 13=5

x 7=( 3 x 6 +11 ) mod 13=0

x 8=( 3 x 7 +11 ) mod 13=11


This sequence contains 3 different numbers before repeating. Therefore,
x 3=x 5=11

2. Suppose pseudo-random numbers are produced by using: x n+1=(2 xn +7)mod 9.


a) If x 0 = 1, find x 2 and x 3
x 1=( 2 x 0+7 ) mod 9=0

x 2=( 2 x 1+7 ) mod 9=7

x 3=( 2 x 2+7 ) mod 9=3

b) If x 3 = 3, find x 2 and x 4.
x 4 =( 2 x 3 +7 ) mod 9=¿ 4

x 5=( 2 x 4 +7 ) mod 9=¿ 6

x 6=( 2 x 5+ 7 ) mod 9=¿ 1

x 7=( 2 x 6 +7 ) mod 9=¿ 0

x 8=( 2 x 7+ 7 ) mod 9=¿ 7

x 9=( 2 x 7 +7 ) mod 9=¿3

x 10=( 2 x 9+7 ) mod 9=¿ 4

This sequence contains 6 different numbers before repeating. Therefore


x 2=x 8=7
4. Which memory locations are assigned by the hashing function h(k) = k mod
101 to the records of insurance company customers with these Social Security
Numbers?
a) 104578690
h(104578690) = 104578690 mod 101 = 58
b) 432222187
h(432222187) = 432222187 mod 101 = 60

3. Using the function f(x) = (x + 10) mod 26 to encrypt messages. Answer each
of these questions.
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12

N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25

a) Encrypt the message STOP


Encoding “STOP”:
18 19 14 15
Encrypting:
2 3 11 25
Encoding :
CDYZ
b) Decrypt the message LEI
Encoding the messege “LEI” : 11 4 8

Decrypt the messege by function f −1 (x)=( x−10 ) mod 26

1 20 24
Decoding
BUY

5. Use the Euclidean algorithm to find


a) gcd(14, 28)
14 = 28*0 + 14
28 = 14*2
gcd(14, 28) = 14
b) gcd(8, 28)
28 = 8*3 + 4
8 = 4*2
gcd(8, 28) = 4

Section 4.1
n (n+1)(2 n+1)
1. Let P (n) be the statement that 12 +22+ 32+ …+n2 = for the
6
positive integer n.
a) What is the statement P (1)?
1(1+ 1)(1+2)
P(1): 1 =
6

b) Show that P (1) is true, completing the basis step of the proof.
1(1+ 1)(1+2)
=1 , so P(1) is true
6

c) What is the inductive hypothesis?


The inductive hypothesis is that P(n) is true for 8 ≤ n ≤ k,
where k ≥ 10.
k (k +1)(k + 2)
12 +22+ 32+ …+k 2=
6

d) What do you need to prove in the inductive step?


(k+ 1)( k +2)( 2k + 3)
12 +22+ 32+ …+k 2+(k +1)2=
6

e) Complete the inductive step, identifying where you use the inductive
hypothesis.
3.

4.
Section 4.3

4. Determine whether each of these proposed definitions is a valid


recursive definition of a function f from the set of nonnegative integers to
the set of integers. If f is well defined, find a formula for f(n) when n is a
nonnegative integer and prove that your formula is valid.
7. Give a recursive definition of each of these sets.
Section 4.4
Section 5.1
15

18

19

You might also like