You are on page 1of 12

CS 205 Quiz #10 Dec 6, 2012

NAME: _____________________________SOLUTIONS___________________________________


RUID:___________________________________________________________________________

Electronic Devices are not permitted during the quiz. These include but are not restricted to calculators,
computers and cell phones.
No communication between students or anyone outside of class is permitted during the quiz.
Textbooks, notes and any other written materials are not permitted during the quiz.

DO NOT OPEN UNTIL
INSTRUCTED TO DO SO


1.
a) Find a proposition using only p, q, and the connective v with the following truth table.


b) Find a proposition using only p, q, and the connective v with the following truth table.


c) Suppose P(x, y) is a predicate and the universe for the variables x and y is {1, 2, 3}.
Suppose P(1, 3), P(2, 1), P(2, 2), P(2, 3), P(3, 1), P(3, 2) are true, and
P(x, y) is false otherwise. Write True in the blank below if the corresponding statement is true,
otherwise write False.


_____True________ x -y P(x, y)



_____True________ -x y P(x, y)



_____False_______ -x -y ( P(x, y) . P(y, x) )



_____True________ y -x ( P(x, y) P(y, x) )



_____False_______ x y ( x y ( P(x, y) v P(y, x) ))



_____False_______ y -x ( x y . P(x, y) )

(p v q)
(p v q) v (p v q)

2.
a) Recall that a set of propositions is consistent if there is an assignment of truth values to each of
the variables in the propositions that makes each proposition true. Determine if the following
set of propositions is consistent. If so, provide an assignment of truth values. If not, explain
why such a setting is impossible.

- The system is in multiuser state if and only if it is operating normally.
- If the system is operating normally, the kernel is functioning.
- The system is operating normally if it is in interrupt mode.
- The kernel is not functioning or the system is in interrupt mode.
- If the system is not in multiuser state, then it is in interrupt mode.
- The system is in interrupt mode.

Use propositions
M = The system is in a multiuser state N = the system is operating normally
P = The kernel is functioning I = the system is in interrupt mode

Consistent
M= 1 N= 1 P= 1 I= 1




b) Provide the rule of inference used in each of the following (see beginning of the quiz for rules of
inference). Using variables, indicate the propositions and how they fit the rule of inference.

- If it snows today, the university will be closed. The university will not be closed today.
Therefore, it did not snow today.

Modus Tollens
p = it snows today q = the university will be closed
p q
q
p

- If I work all night on this homework, then I can answer all the exercises. If I answer all the
exercises, I will understand the material. Therefore, if I work all night on this homework,
then I will understand the material.

Hypothetical Syllogism
p = I work all night on the homework q = I can answer all the exercises
r = I understand all the material
p q
q r
p r
3.
a) Write True in the blank if the corresponding statement is in CNF. Otherwise, write False.


___True_____

a

___True_____

(a v b) . c

___True_____

a v b

___False____

(a . b) v c

___True_____

a . b

___False____

(a v b)

___False____

a b

___False____

(a b) (c d)

___False____

a b

___True_____

(a b) (c d)

b) Determine whether the following argument is valid. If the argument is valid, demonstrate its
validity either through resolution refutation, or by use of logical equivalences. If the argument is
invalid, provide a counterexample.

If you are not in the tennis tournament, you will not meet Ed.
If you arent in the tennis tournament or if you arent in the play, you wont meet Kelly.
You meet Kelly or you dont meet Ed.
It is false that you are in the tennis tournament and in the play.
Therefore, you are in the tennis tournament.
Use propositions
T = You are in the tennis tournament E = You will meet Ed
P = You are in the play K = You will meet Kelly


Invalid
Counterexample: T=0, E=0, K=0, P=0 or T=0, E=0, K=0, P=1

4.
a) Suppose a = 3, B = { 3 }, C = { 1, 2, 3} and D = {1, 4, 5}. Mark each of
the following statements as True or False.


____True_______

a D

____True_______

a B

____True_______

a

____False______

a P(B)

____False______

a (B C)

____False______

B { a }

____True_______

D

____False______

D D

____True_______

B D

____False______

C D = B




b) For each of the following statements, provide the cardinality of the result.



______0________



______8________

({1,2} {3,4}) {5,6}

______1________

{}

______2________

({1,2} {3}) ({3} {2,1})

______3________

{1,2,,}

______0________

P((P({1}) P({2})))

______2________

{} {{}}

2
2*2*3
=2
12
=4096_

P({1,2} ({3,4} {5,6,7}))

2^2^2^2^0 = 16_

P(P(P(P())))

__2
8
= 256_____

P({1,2,3,4} {5,6,7,8})


5. For each of the relations below, select the most appropriate option and write its letter in the
corresponding blank.

A) A partial function, but not a total function
B) A total function that is not injective, surjective, bijective, or invertible
C) An injective total function, but not an surjective, bijective or invertible function
D) A surjective total function, but not an injective, bijective or invertible function
E) A bijective total function, but not an injective, surjective or invertible function
F) An invertible total function (whose inverse is a total function), but not an injective,
surjective or bijective function
G) A total function that is injective, surjective, bijective and invertible (and whose inverse is a
total function)


_______G___________ a) f(x) = x - 1, where f : R R


_______B___________ b) f(x) = x
4
, where f : Z Z


_______A___________ c) f(x) = (x - 1) / (x + 2), where f : Z R
f(-2) undefined

_______C___________ d) f(x) = lg x, where f : Z R


_______ C___________ e) f(x) = 1 / x, where f : Z
+
{a R | 0 < a 1}


_______B___________ f) f(m, n) = 2m / n, where f : Z Z
+
R


_______D___________ g) f(m, n) = m mod n, where f : N Z
+
N
f(m, m+1) = m => surjective

_______D___________ h) f(m, n) = m( n, where f : R R Z
f(m, 1) = m( => surjective ( is multiplication)

_______B___________ i) f(m, n) = -2, where f : R R R


_______D___________ j) f(m, n) = m - n, where f : Z
-
Z
-
Z
f(m, 0) for negatives f(0, n) for positives
f(m, m) for zero
6.
a) Find the least integer n such that the statement is O(x
n
) for each of the following
statements. If no such n is possible, write Impossible.

_____2_____

x

log x

____2______

9x
2
+ x

log x

_____5_____

2x
3
+ x
4
log x

____2______

7x
2
+ (log x)
4


_____1_____

(x
4
+ x
2
+ 1)/(x
3
+ 1)

Impossible_

x
2
+ 2
x

_____1_____

x



____5______

(0.3)
x
+ 4x
5


_____0_____

12

___-1______

5/x + 4/(x!)


b) What is the effect in the time required to solve a problem when you increase the size of the
input from n to n+1, assuming that the number of milliseconds the algorithm uses to solve
the problem with input size n is each of the quantities expressed below? Let W
1
denote the
runtime with input size n+1 and let W
0
denote the runtime with input size n. In each blank,
write the corresponding letter from the table below. Note that an option may be used zero or
more times (i.e. once, more than once, not at all).

A) W
1
- W
0
= 0 B) W
1
- W
0
= 1 C) W
1
- W
0
= 2
D) W
1
- W
0
= n E) W
1
- W
0
= 2n F) W
1
- W
0
= 2n+1
G) W
1
- W
0
= n+1 H) W
1
- W
0
= 2n-1 I) W
1
- W
0
= 2n+2
J) W
1
- W
0
= lg(n+1) lg(n) K) W
1
/ W
0
= 2 L) W
1
/ W
0
= 2n
M) W
1
/ W
0
= n+1 N) W
1
/ W
0
= 2n+1 O) W
1
/ W
0
= 2n+2
P) W
1
/ W
0
= lg(n) Q) W
1
/ W
0
= n
2
R) W
1
/ W
0
= n!
S) W
1
/ W
0
= 2
n
T) W
1
/ W
0
= 2
n+1
U) W
1
/ W
0
= 2
(2n+1)



____A______

3

____B______

n + 1

____C______

2n + 1

____F______

n
2


____**______

n
2
+ n

____M______

n!

____K______

2
n


____U______

2 ^ (n
2
)

____J______

lg n

____H______

(n-1)
2

** This question had no answer. No points were deducted for any answer.
7.
a) For the pair of graphs below, determine whether they are isomorphic. If the graphs are
isomorphic, then fill in blanks to indicate which vertex in the first graph maps to which other
vertex in the second graph. If the graphs are not isomorphic, then provide a clear reason.


Not Isomorphic
Possible Reason: Left has 2 vertices with degree 2, Right has 3

b) Determine if the following graph is bipartite. If so, provide the partitions. If not, provide a clear
reason.

c) How many subgraphs that are cycles can be produced from a complete graph with 4 vertices?

Seven if the vertices are arranged as the corners of a square,
there are 4 triangles, one square, one bow tie and one hour
glass

d) What is the sum of the degrees over all vertices in a complete graph with 10 vertices?

90
Each vertex in a complete graph connects to every other vertex,
so each vertex will have degree 9.

e) What is the maximum and minimum number of edges in a graph with 5 vertices?

Minimum = 0 Maximum = 4+3+2+1 = (5 choose 2) = 10
a _________

d _________

b _________

e _________

c _________

f _________

Bipartite
Partitions:
{a,c,f,h,i,k,n,p}
{b,d,e,g,j,l,m,o}
8.
a) For each of the following trees, provide the preorder, inorder and postorder traversal:


i.
Preorder:
A, B, D, E, C, F, G

Inorder:
D, B, E, A, F, C, G

Postorder:
D, E, B, F, G, C, A

ii.
Preorder:
A, B, C, D, E, F, G

Inorder:
A, B, C, D, E, F, G

Postorder:
G, F, E, D, C, B, A

b) For the following codes, compute the average number of bits to encode a single character if the
character frequencies are as shown. Additionally, specify whether or not the code is a Huffman
code (write True if it is a Huffman Coding, otherwise write False).

code: a: 0, b: 100, c: 101, d: 110, e: 111
frequencies: a: 0.40, b: 0.19, c: 0.15, d: 0.13, e: 0.13


Average Bits: _0.4*1 + 0.6*3 = 2.2_ Huffman Code: ____True_________


c) Compute the value of the prefix expression + - 3 2 2 3 / 6 4 2
4

d) Compute the value of the postfix expression 1 2 * 2 5 3 8 4 / * -

0




9.
a) Consider grammar G = (V, T, S, P) where V = { A, B, a, b, S } and
T = { a, b }. The set of productions P in Backus-Naur form are:
S ::= AB
A ::= aAb |
B ::= bBa |

Determine whether each of the following is derivable starting from S. Write True if it
is derivable and False if it is not derivable.



___False_______

a

___False_______

ab

___False_______

aba

___True________

abba

___True________

abbbaa

___False_______

abab

___False_______

ababa

___False_______

ababab

___True________

aaaabbbbba

___True________





b) Find a set of exactly 3 productions that produces {1
n
01
2n
0 | n 0}.
Use only nonterminals S and A, where S is the start symbol.

S A0
A 1A11
A 0


c) Find a context-free grammar that generates the complete set of all strings over the alphabet
{0, 1} such that there are always more 1s than 0s. (It generates all such strings and no
other types of strings.) List the productions in the space provided below. Use only six
productions and only two nonterminals, S and A.

S A1A
A 0A1, A 1A0, A 1A, A AA, A


The following tables reprinted from the textbook may be useful to you: