DMFinal Fall 2017
DMFinal Fall 2017
Name: _____________________________
NetID: _____________________________
1. “If it is raining then the sky is gray.” Which one of the following options is the inverse of this
statement?
*a. If it is not raining then the sky is not gray.
b. If the sky is gray then it is raining.
c. If the sky is not gray then it is not raining.
d. Converse is not possible.
2. How can the following English sentence be translated into a logical expression?
“It is not the case that if it is raining then John is sultry.”
Let p = It is raining and s = John is sultry.
a. p → ¬s
b. ¬p → ¬s
*c. ¬(p → s)
d. ¬p → s
3. How can the following English sentence be translated into a logical expression?
“Mary is sick; and it is raining implies that Bob stayed up late last night.”
Let p = It is raining
q = Mary is sick
t = Bob stayed up late last night
a. ((q ∧ p) → ¬t)
*b. (q ∧ (p → t))
c. ((q ∧ p) → t)
d. (q → t)
6. Which statement best captures in logic the English sentence, "No person is special to
everyone"?
a. ¬∀x∃y(S(x, y))
b. ¬∀x∀y(S(x, y))
*c. ¬∃x∀y(S(x, y))
d. ∃x∀y(S(x, y))
7. Which statement best captures in logic the English sentence, "Somewhere, somebody done
everyone wrong?"
a. ∀x∃y(W(x, y))
b. ∃x∀y(W(x, y))
c. ∀x∀y∀z(W(x, y, z))
*d. ∃x∃y∀z(W(x, y, z))
11. How many strongly connected components does the directed graph specified by the
following adjacency matrix have?
Adj. Matrix: a -> (b), b -> (d), c -> (b), d -> (c), e -> (a, f), f -> (d, g), g -> (e), h -> (e, g)
*a. 4
b. 1
c. 2
d. 3
12. Below is part of an undirected graph. Even though you can only see some of the vertices
and edges, can you deduce whether the graph will have an Euler path or circuit?
Adj. Matrix: a -> (b, c, e), b -> (a, f), c -> (a, h, g), e -> (a, i)
a. It will have both an Euler path and an Euler circuit, as it is a tree.
*b. It will not have an Euler circuit since it has at least one vertex of odd degree, but it might
have an Euler path.
c. It will not have an Euler path or an Euler circuit, since it has too many vertices with odd
degree.
d. It will have both an Euler path but not an Euler circuit, since it has three vertices with odd
degree.
14. What is the postfix form for the following expression (((4x + y) - 17 * (x - z)) + 7)?
*a. 4x y + 17 x z - * - 7 +
b. y 4x + 17 x z - * - 7 +
c. 4x y 17 + x z - * - 7 +
d. 4x y + 17 x z - * 7 +
16. If we have a full binary tree with all leaves at the same level, with five levels (including the
root), how many edges does it have?
a. 14
b. 10
*c. 30
d. 32
17. If we have a binary tree with 10 levels (including the root), what is the least number of
leaves we can have in level 10?
*a. 1
b. 20
c. 1024
d. 2048
18. Which of the following is a valid prefix coding scheme?
*a. a = 01, b = 00, c = 10, d = 110, e = 111
b. a = 001, b = 000, c = 110, d = 01, e = 11
c. a = 001, b = 000, c = 101, d = 00, e = 11
d. a = 111, b = 000, c = 101, d = 01, e = 11
19. Consider the following Huffman code: a = 01, b = 00, c = 101, d = 110, e = 1111, f = 1110.
What alphabetical string do the digits 110111111101010100 represent?
a. bacfed
b. decbaf
*c. defcab
d. fedabc
23. If my code represents a graph by {a: (b, c, d), b: (a, c), c: (a, b, d), d: (a, c), f: ()} then I am
using a ______ to represent it?
a. adjacency matrix
b. incidence matrix
*c. adjacency list
d. adjacency incident
30. For there to be an Eulerian path but not an Eulerian circuit through a graph, there must be
_____.
a. an even number of nodes of odd degree
b. 0 or 2 nodes of odd degree
c. 0 or 2 nodes of even degree
*d. exactly two nodes of odd degree
32. Consider the directed graph described by the adjacency list {a -> (b, c, d), b -> (e), c -> (b),
d -> (f) e: (c), f -> (g), g -> (d)}. What are the strongly connected components of that graph?
a. a-b-c-e and d-f-g
b. a-b-c, e, and d-f-g
*c. a, b-c-e and d-f-g
d. the whole graph is strongly connected
34. An graph is called a ________ if there is not a path between every pair of distinct vertices in
the graph.
a. connected graph
b. distinct graph
*c. disconnected graph
d. cut graph
35. In year one you save $200. Every year thereafter you save $200 more and also you receive
4% interest on what you already had in the bank.
What is the recurrence relation giving your savings after n years?
a. T(1) = 200; T(n) = 1.04 * T(n - 1)
*b. T(1) = 200; T(n) = 200 + 1.04 * T(n - 1)
c. T(1) = 200; T(n) = 200 + T(n - 1)
d. T(1) = 200; T(n) = 200 + 1.04 * T(n)
36. What is the big O of the following equation? T(n) = 16T(n / 16) + n
a. O(16n)
*b. O(n log n)
c. O(n)
d. O(n2)
37. What is the big O of the following equation? T(n) = 6T(n / 2) + n2
a. O(n log n)
b. O(n)
c. O(n2)
*d. O(n2.58)
38. Let f(x) = f(x - 1) + 4, for all integers x > 4, and let f(4) = 2. What is f(10)?
a. 14
b. 18
c. 22
*d. 26
39. Use the master theorem to give the runtime for the recurrence T(n) = 12T(n) + 16n − 1
a. O(6n)
b. O(n)
c. O(n log n)
*d. The master theorem can't be applied.
40. Consider the graph described by the adjacency list {a: (b, c, d), b: (a, c), c: (a, b, d, e), d: (a,
c, e, f), e: (c, d), f: (d)}. Does it contain an Eulerian path?
*a. Yes
b. No
c. Not enough information
41. Consider the graph from Q-40. Does it contain an Eulerian circuit?
a. Yes
*b. No
c. Not enough information
d. All of the above
42. What is the runtime complexity of T(n) = 12T(n/12) + 64n − 1 using the master theorem?
*a. O(n log n)
b. O(6n)
c. O(n)
d. The master theorem doesn't apply.
44. What are the worst-case and average-case complexities of searching in a binary search
tree?
a. O(n2), O(n)
b. O(n lg n), O(n)
*c. O(n), O(lg n)
d. O(n2 lg n), O(n lg n)
45. If there are 10 children in a family, on how many days of the week were at least 3 children
born?
a. at least 1
*b. maybe none
c. 2
d. at least 2
46. In the English alphabet using (and differentiating) both uppercase and lowercase letters,
how many different two-letter usernames can people have, if they can repeat letters?
a. 15,600
b. 2652
c. 52
*d. 2704
47. You have a dozen eggs in your refrigerator, and one of them is rotten. If you reach in and
pull out one at random, what is the probability that you have the rotten egg?
a. .3
b. .25
c. .125
*d .0833
48. How many possibilities are there for the rst, second, and third positions in a car race with 8
cars if all orders of nish are possible?
a. 212
b. 240
c. 512
*d. 336
49. There are 3 available flights from New York to London and, regardless of which of these
flights is taken, there are 2 available flights from London to Paris, and then 4 flights from Paris to
Istanbul. In how many ways can a person fly from New York to London to Paris to Istanbul?
a. 8
b. 16
*c. 24
d. 32
50. If I tell you that C(15, 2) = 105, and C(15, 3) = 455 (where C means "choose"), then C(16, 3)
is?
a. 4.333
b. 47,775
c. 350
*d. 560
51. I give you part of a row of Pascal's triangle: 1, 13, 78, 286, 715... The start of the next row
is?
a. 14, 91, 364, 1001...
b. 1, 13, 14, 78, 91, 364, 715
*c. 1, 14, 91, 364, 1001....
d. none of the above
52. The formula for "choose" is n! / (k! * (n - k)!). The k! exists in the denominator to account for
the fact that ______________.
*a. order in combinations doesn't matter
b. we only chose a few items out of n possibilities
c. k is the probability of getting n choices
d. none of the above
53. If a menu at a banquet dinner has five possibilities for an appetizer, two for an entree, and
five for dessert, how many possible meals are there?
a. 12
*b. 50
c. 72
d. 144
54. What is the complexity of the program given below ? where o, p >= 1.
int x=0;
for (int i = 1; i <=p; i += c) {
x = x * 3;
for (int i = 1; i <= o; i = i * 2) {
x = x + 2;
}
}
a. O(o * p)
b. O(p)
*c. O(p log o)
d. O(o + p)
56. If f(x) = 1/x and g(x) = log x, out of the following possible functions, which one is both the
upper bound for f(x) and the lower bound for g(x)?
a. h(x) = x
b. h(x) = x2
c. h(x) = x1/2
*d. h(x) = 1
57. If f(x) = 64, then f(x) is (not restricting ourselves to the tightest bound):
a. O(1)
b. O(log x)
c. O(x5)
*d. all of the above
58. If f(x) = 64, then f(x) is (restricting ourselves to the tightest bound):
*a. O(1)
b. O(log x)
c. O(x5)
d. all of the above
59. If set A = {all integers} and set B = {all odd integers}, then the complement of B is:
a. all odd integers
*b. all even integers
c. all composite integers
d. all integers that are multiples of 3