Docsity

Solved Problems on Applied Discrete Structure - Final Exam | COT 3100, Exams of Computer Science

Toggle sidebar
bg1
COT 3100, sect. #7094X, Fall ‘99
Solutions to
Sample Final Exam Problems
From Chapter 1
1. Write out the complete truth table for the compound proposition .
Include columns for all sub-expressions.
pqr
-- -- -- ---- ---- ---------- --------------- --------- ----------------------------
F F F T T T F F F
F F T T F T F F F
F T F F T T F F F
F T T F F F T F T
T F F T T T F T T
T F T T F T F F F
T T F F T T F T T
T T T F F F T F T
2. Using propositional logic symbols, write a compound proposition with three variables p,q,r
that is true when exactly one of the three variables is true, and false otherwise.
Here’s one:
This also works but is longer:
3. Prove that is a tautology via a symbolic derivation using a series of
propositional equivalences, based on general substitution laws you have learned.
(definition of )
(DeMorgan’s law)
(defn. of again)
(distributive law)
(standard contradiction)
(or with false)
(associative law)
(std. contradiction)
(and with false)
(not false)
r q¬→( )¬ p r¬∧( )∨
q¬
r¬
r q¬→
r q¬→( )¬
p r¬∧
r q¬→( )¬ p r¬∧( )∨
p q r⊕ ⊕( ) pqr∧ ∧( )¬∧
q p q¬→( )∧( ) p¬→
q p q¬→( )∧( ) p¬→
⇔
q p q¬→( )∧( )¬ p¬∨
→
⇔
q p q¬→( )∧( ) p∧( )¬
⇔
q p¬q¬∨( )∧( ) p∧( )¬
→
⇔
q p¬∧( ) q q¬∧( )∨( ) p∧( )¬
⇔
q p¬∧( ) F∨( ) p∧( )¬
⇔
q p¬∧( ) p∧( )¬
⇔
q p¬p∧( )∧( )¬
⇔
qF∧( )¬
⇔
F¬
⇔
T
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Solved Problems on Applied Discrete Structure - Final Exam | COT 3100 and more Exams Computer Science in PDF only on Docsity!

COT 3100, sect. #7094X, Fall ‘

Solutions to

Sample Final Exam Problems

From Chapter 1

  1. Write out the complete truth table for the compound proposition. Include columns for all sub-expressions.

p q r


F F F T T T F F F F F T T F T F F F F T F F T T F F F F T T F F F T F T T F F T T T F T T T F T T F T F F F T T F F T T F T T T T T F F F T F T

  1. Using propositional logic symbols, write a compound proposition with three variables p , q , r that is true when exactly one of the three variables is true, and false otherwise.

Here’s one: This also works but is longer:

  1. Prove that is a tautology via a symbolic derivation using a series of propositional equivalences, based on general substitution laws you have learned.

(definition of ) (DeMorgan’s law) (defn. of again) (distributive law) (standard contradiction) (or with false) (associative law) (std. contradiction) (and with false) (not false)

¬( r →¬ q )∨( p ∧¬ r )

¬ q ¬ r r → ¬ q ¬( r →¬ q ) p ∧ ¬ r ¬( r →¬ q )∨( p ∧¬ r )

( p ⊕ q ⊕ r ) ∧¬( p ∧ q ∧ r ) ( p ∧ ¬ q ∧¬ r ) ∨ ( ¬ p ∧ q ∧¬ r ) ∨( ¬ p ∧ ¬ q ∧ r )

( q ∧( p →¬ q )) →¬ p

( q ∧( p →¬ q )) → ¬ p ⇔ ¬( q ∧( p →¬ q ))∨ ¬ p → ⇔ ¬( ( q ∧( p →¬ q )) ∧ p ) ⇔ ¬( ( q ∧( ¬ p ∨¬ q )) ∧ p ) → ⇔ ¬( ( ( q ∧¬ p ) ∨( q ∧¬ q )) ∧ p ) ⇔ ¬( ( ( q ∧¬ p ) ∨ F ) ∧ p ) ⇔ ¬( ( q ∧¬ p ) ∧ p ) ⇔ ¬( q ∧( ¬ p ∧ p )) ⇔ ¬( q ∧ F ) ⇔ ¬ F ⇔ T

  1. Translate the statement “If you study hard, then you will excel.” into a compound predicate- logic proposition using p=”you study hard” and q=”you will excel”. Write its converse, contra- positive, and logical negation in predicate logic, then translate back into English.

Original statement: p -> q “If you study hard, then you will excel.”

  1. Converse: q->p “You will excel only if you study hard.”
  2. Contrapositive: “You will fail to excel only if you don’t study hard.”
  3. Negation: “You study hard, yet you won’t excel.”

(Remember that of these three, it is the contrapositive and only the contrapositive that is logically equivalent to the original implication.)

  1. Let P(x,y) be the statement x|y (x divides y with no remainder). Give the truth values of the fol-

lowing predicate logic statements in a universe of discourse of the integers: (a) (b)

(c) (d) (e) (f) (g) .

(a) true - there is something that divides something (e.g. 1 divides 1) (b) false - not everything divides everything (e.g. 2 does not divide 3) (c) true - everything divides itself (e.g., 3 divides 3) (d) true - there is something (namely 1) that divides everything (e) true - for everything, there is something it divides (e.g., itself) (f) true - there is something that everything divides (namely y=0). For any integer x, x|y, because there is an integer b (0) such that xb=y. (See defn 1 on p. 113) (g) true - for everything, there is something that divides it (e.g., 1)

  1. Letting U(x)=”x is an upper-level course”, M(x)=”x is a math course”, F(x)=”x is a freshman”, A(x)=”x is a part-time student”, B(x)=”x is a full-time student”, T(x,y)=”student x is taking course y”, translate the following into predicate logic: (a) All students are freshmen (b) Every freshman is a full-time student (c) Every student is taking at least one course. (d) There is a part-time student who is not taking any math course. (e) Every part-time freshman is taking some upper-level course.

(a) (b) (c) (d) (e)

  1. Prove that by giving: (a) a containment proof (prove that each side is a subset of the other)

¬ q →¬ p ¬( p → q )⇔ ¬( ¬ p ∨ q )⇔ p ∧¬ q

∃ x ∃ y P(x,y) ∀ x ∀ y P x y ( , ) ∀ x P x x ( , ) ∃ x ∀ y P x y ( , ) ∀ x ∃ y P x y ( , ) ∃ y ∀ x P x y ( , ) ∀ y ∃ x P x y ( , )

∀ x ( A x ( ) ∨ B x ( )) → F x ( ) ∀ x F x ( ) → B x ( ) ∀ x ∃ y T x y ( , ) ∃ x A x ( ) ∧ ¬∃ y T x y ( , ) ∧ M y ( ) ∀ x ( A x ( ) ∧ F x ( )) → ∃ y T x y ( , ) ∧ U y ( )

A ∩ ( B ∪ C ) = ( A ∩ B ) ∪( A ∩ C )

  1. Derive a simple closed-form expression for.

This is a telescoping sum. All the terms cancel out except for 1/1 in the first term, and 1/(n+1) in the last term. So the sum is 1 + 1/(n+1) = (n+2)/(n+1).

  1. Show that f(n)=3n^2 +8n+7 is O(n^2 ) using the definition of O() and deriving c and k values that work.

3n^2 +8n+7 3n^2 +8n^2 +7n^2 if n> = 18 n^2

So f(n) < 18 n^2 if n>1. So with k=1 and c=18, f(n)<c n^2 , so by definition f(n) is O(n^2 ).

  1. Show that f(x)=(x+2)log(x^2 +1)+log(x^3 +1) is.

(x+2) is order x. log(x^2 +1) is log of order x^2 , which is order 2 log x which is order log x. Multiplying the orders, the first term is order x log x. The second term is similarly order log x, and since this is lower than x log x the second term drops out, leaving just order (x log x) overall.

From Chapter 2

  1. Describe an algorithm that takes a list of n>0 integers and finds the location of the last even integer in the list, or returns 0 if there are no even integers in the list.

procedure findlasteven (a1, a2, ..., an : integers) i := n while (i > 0) { if (2|ai) then return i i := i - 1 } return 0

  1. Explain in your own words why binary search takes only order log n operations to search a list of n items.

On each iteration, the size of the range of indices being searched is cut roughly in

i

i + 1

i = 1

n

∀ n>k

Θ ( x log x )

half. After n halvings, the size is cut by about 2n. If the initial size is about 2n^ then after n iterations the size will be about 1 (and from there the algorithm takes only constant time). Therefore, the number of iterations is about log 2 of the initial number of elements, and each iteration takes constant time, so the total time is order log 2 n. The base does not make a difference to the order so we can express this as just order (log n).

  1. Give an algorithm to compute the permutation function P(n,k) = n!/(n-k)!. Assuming each mul- tiplication or division takes order-1 time, give the order of growth of the worst-case time complex- ity of your algorithm (a) as a function of n and k, and (b) as a function of n.

procedure perm (n, k: integers) prod := 1 for i := n-k+1 to n prod := prod i return prod

(a) order k (the first loop has k iterations) (b) order n (since k is at most n)

  1. Give the prime factorizations of: (a) 1,024, (b) 1,025 (c) 510,

(a) 1024 = 2^10 (b) 1025 = 2541 = 5^2 (c) 510,510 = 5101001 = 10511001 = 25511001 = 23571113* Part (c) is rather difficult without a calculator and we wouldn’t give one that hard on a real exam.

  1. List all positive integers less than 50 that are relatively prime to 30.

30 = 235, so we are listing all integers<50 that don’t have any of these factors. Eliminate all even numbers, numbers ending in 5, and numbers divisible by 3, and we get: 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49

A real exam question like this would probably be a bit shorter.

  1. Find (a) gcd(20!,12!), (b) lcm(20!,12!) (c) gcd(2^89 , 2^346 )

(a) 12! because 12!|20! (b) 20! (c) 2^89

  1. What is 50! mod 50?

0, because 50|50!.

×

  1. Prove or disprove that for all integers , the integer n^2 -1 is composite.

This is false as stated because for n=2, n^2 -1 = 3 which is prime. However, if we had said n>2, it would be true because (n^2 -1) can be factored into (n+1)(n-1). For n>2, (n-1)>1, so the number n^2 -1 has a factor other than itself and 1 and so is composite.

  1. The following “proof” purports to show that for any integer , the number is prime:

“Proof: We want to prove that for all integers , the number 2 n +1 is prime. Let n be any inte- ger greater than or equal to 1, for example, n =1, n =2, or n =3. If n =1, then 2 n +1=3, which is prime. If n =2, then 2 n +1=5, which is prime. If n =3, then 2 n +1=7, which is prime. We can see

from these examples that whenever , the number 2 n +1 is always prime.” Explain what is wrong with this “proof.” It’s not enough just to show that the “theorem” is false. You must iden- tify the general flaw with the overall type of reasoning that is used in this “proof,” and explain why this sort of reasoning is logically invalid.

The flaw is that it tries to prove a universal statement merely by giving a few examples for which it is true. This is never a valid procedure because it does not prove that the statement is still true for all the other examples that were not considered. In this case the flaw is obvious, since if the example n=4 were tried, 2n+1 = 9 which isn’t prime. However, sometimes the exceptions may be less obvious. So you should always stay away from this practice. It simply isn’t logically valid.

  1. Write a good proof by contradiction showing that at least one of the real numbers a 1 , ..., an is

greater than or equal to the average of these numbers.

Proof by contradiction: Suppose all the numbers were less than their average x, that is, for all i, ai < x = (a 1 +...+an)/n. But the sum of n numbers, each less than x is obviously less than nx. So we have that a 1 +...+an < nx = n(a 1 +...+an)/n = a 1 +...+an, that is, we have that a 1 +...+an < a 1 +...+an, that is, the sum is less than itself, which is impossible. So the assumption that all the numbers were less than their average must be false, therefore some number must be greater than average.

  1. Write a good inductive proof showing that for all.
  2. Write a good inductive proof showing that for all.
  3. Use induction to show that any integer amount of dollars greater than 17 dollars could be made from a combination of 3-dollar bills and 10-dollar bills.
  4. Give a simple recursive definition (with initial condition(s)) of the sequence { an } ( n =1,2,3...) if

n ≥ 2

n ≥ 1 2 n + 1 n ≥ 1

n ≥ 1

( 2 i – 1 ) i = 1

n

∑ n

2 = n ≥ 1

n

  • 3 n ≤ n ≥ 1

(a) an =2 n , (b) an = 3 n - 5, (c) an =( n +1)/3, (d) an = , (e) an = , (f) an = n^2 + n

(a) a(n) = 2a(n-1), a(1)= (b) a(n) = a(n-1)+3, a(1)=- (c) a(n) = a(n-1)+1/3, a(1)=2/ (d) a(n) = a(n-1), a(1)=sqrt(2)

(e) a(n) = , a(1) =. (d) a(n) = a(n-1) + 2n, a(1) = 2

  1. Give a recursive definition of the set S = {0, 3, 6, 9, 12, .... } (the set of non-negative multiples of 3).

, and for all integers n, if then.

  1. Find f (2) and f (3) if (a) f ( n )=2 f ( n -1)+6, f (0)=3, and (b) f ( n ) = f ( n -1) f ( n -2)+1, f (0)=1, f (1)=4.

(a) f(0)=3, f(1)=12, f(2)=30, f(3)= (b) f(0)=1, f(1)=4, f(2) = 5, f(3)=

From Chapter 4

  1. Suppose a “word” is any string of uppercase 7 letters (repetitions allowed) of the 26-letter English alphabet. (a) How many words are there? (b) How many words have no repeated letters? (c) How many words end with T? (d) How many words begin with a vowel? (vow- els={A,E,I,O,U}.) (e) How many words have no vowels? (g) How many words have exactly 1 vowel?

(a) 26^7 = 8,031,810,176 - more than eight billion (b) 26!/(26-7)! = 26252423222120 = 3,315,312,000 - more than three billion (c) 26^6 = 308,915,776 - three hundred million (d) 26^6 *5 = 1,544,578,880 - over a billion (e) 21^7 = 1,801,088,541 - over a billion (f) 21^6 * 7 * 5 = 3,001,814,235 - three billion

  1. How many different arrangements are there of the letters in the word “COEFFICIENT” (given that the relative order of two identical letters makes no difference)?

There are 11 letters so there would be 11! permutations if they were all different. But the 2!=2 orderings of the 2 C’s don’t matter, nor do the 2!=2 orderings of the 2 E’s, ditto for the 2 F’s and 2 I’s. So we get 11!/2^4 = 111098765432/222 = 111097654*3 = 2,494,800 orderings that make a difference

  1. How many bit strings of length 9 are there? How many of them have exactly 5 zeroes?

1 ⁄ 2 n

an – 1 22

  • n 42 - n
  • – 2

0 ∈ S n ∈ S n + 3 ∈ S

(b) 25000*1.05n-1^ - be careful here : in year n=1, we have 1.05 to the 0! (c) about 38,783, (d) s(n) = s(n-1) * 1.02 + 1000

Use iterative approach to solve: let a=1000, b=1. s(n) = s(n-1)b + a = (s(n-2)b + a)b + a = s(n-2)b^2 + ab + a = (s(n-3)b + a)b^2 + ab + a = s(n-3)*b^3 + ab^2 + ab + a

= s(n-k)*bk^ +.

This summation has a standard formula from the text (table 2, p. 76):

s(n) = s(n-k) bk^ +

Letting n-k=1 or k=n-1, we have

s(n) = s(1) bn-1^ +

or s(10) = 39,631.

  1. Identify which of the following are linear homogeneous recurrence relations with constant coefficients:

(a) an = 0.7 an -1 - 0.3 an -2 (b) an = n an -1 (c) an = 5 an -1^2 - 3 an -2 (d) an = an -1 + 1

(a) only

  1. Solve the following recurrence relation: an = 5 a n-1 - 4 an -2, a 0 =1, a 1 =0.
  2. Given the recurrence relation an = - an -1 + 3 an -3 + 2 an -4,

(a) Write its characteristic equation. (b) Find its roots and their multiplicities. (Hint: one of the roots of the characteristic equation is r=-1). (c) Write the form of general solutions to the recurrence relation.

There is a bug in the problem statement. r=-1 is not a root, and the true roots are difficult to find. I’ll be more careful on the real final. This was intended to be similar to the quiz question.

From Chapter 6

  1. Determine which subset of the properties {reflexive, symmetric, antisymmetric, transitive} is held by each of the following binary relations.

ab i

i = 0

k – 1

ab k

  • a b – 1

a b – 1

------------ b n – 1 ⋅( – 1 )

sn 25 000, 1. n – 1 ⋅ 50 000, 1. n – 1 = + ⋅( – 1 )

(a) The relation R on the numbers N={1,2,3,...} where aRb means a|b. (b) The relation R on {w,x,y,z} where R={(w,w), (w,x), (x,w), (x,x), (x,z), (y,y), (z,y), (z,z)}.

(c) The relation R on Z where aRb means |a-b|.

(a) {reflexive, antisymmetric, transitive} (b) {reflexive} (c) {reflexive, symmetric}

  1. Find the matrix representing the relation R on {-2, -1, 0, 1, 2} where aRb means a^2 =b^2.

With the ordering -2,-1,0,1,2:

  1. For matrix MR = , say yes/no for each of the following properties of R: (a) reflexive,

(b) symmetric, (c) antisymmetric, (d) transitive.

(a) yes (b) no (c) no (d) no

  1. Suppose R is a relation on Z (the set of all integers) such that aRb means that ab is negative. Is R an equivalence relation? If so, give the partition of Z elicited by R. If not, which properties of an equivalance relation does it lack?

No, it is not. It is not reflexive: 22 isn’t negative. It is symmetric: If ab is negative, then so is ba. But it is not transitive: 1-1 is negative, and -12 is negative, but 12 is not negative.

  1. Draw the directed graph representation of the relation in problem 3.
  1. Draw W 5 , label its vertices, pick two vertices a and b, and give an ordered list of the vertices in

a Hamilton path from a to b.

Pick verts 1 and 2. Then one Hamiltonian path from 1 to 2 is 1,5,4,3,6,