Final Exam Rubric

True/False 6pts each (48 pts total)

General grading instructions for T/F

A. [True/False] 3SAT is an NP-complete problem. To show that some other problem Q is also NP-complete, it is sufficient to show that there is a polynomial time reduction from Q to 3SAT and that Q is in NP.

Example Solution:
False. A reduction from A to B shows that B is at least as hard as A. So to find new NP-Hard problems, we reduce a known NP-Complete problem to the candidate in order to show that the candidate problem must be at least as hard as any NP-Complete problem. Then to further show the candidate is NP-Complete, we'd show that it's also in NP.

Student Answers:

B. [True/False] 2lognO(n)2^{\log n} \in \mathcal{O}(n) for n1n \geq 1

Example Solution:
True. We stated that we would assume base 2 for all logs in the class unless otherwise noted. So, for example, 2log2n=n2^{\log_2 n} = n. So, 2lognO(n)2^{\log n} \in \mathcal{O}(n).
Answer can also be false if student considered a base less than 2. Recall that difference in log base is a constant factor difference. A constant factor exponent difference gives us a different asymptotic complexity!

Student Answers:

C. [True/False] Every connected weighted graph contains a unique minimum spanning tree.

Example Solution:
False. A graph may have multiple distinct minimum spanning tree. Answer needs to be a counterexample, so consider a complete graph with 3 vertices, A, B, and C and equal edge weights between them. A spanning tree for this graph contains 3 vertices and two edges. This graph contains 3 distinct minimum spanning trees, since there are 3 different spanning trees and they are all equally minimum. [A-B, B-C], [B-C, C-A], and [C-B, B-A].

Student Answers: Apparently a tough reading comprehension question. However, it is a question we answered in class and is in the posted week 8 notes.

D. [True/False] A graph with vv vertices and ee edges is represented by an adjacency list. A trivial lower bound for deciding if the graph is complete or fully connected is Ω(v+e)\Omega(v + e).

Example Solution:
True. Trivially, for any graph, we'd need to look at each vertex and edge to determine if it's complete. A counting function to do this just needs to count the number of vertices and edges: if there are v(v1)2\frac{v(v-1)}{2} nondirected edges, then the graph is complete.

Student Answers:

E. [True/False] NP-Hard problems are at least as hard as any problem in NP. An NP-hard problem cannot in general be reduced to 3SAT, which is NP-Complete.

Example Solution:
True. Given that NP-Hard problems are at least as hard as any problem in NP, it follows that NP-hard problems cannot generally be reduced to 3SAT, which is NP-complete. Some problems in NP-Hard can be reduced to 3SAT, i.e. any NP-complete problems can be reduced to any other NP-complete problems and NP-complete problems are also NP-Hard. However, this can't be generally done, and the key phrase here is 'in general'.

Student Answers:
(-2) If student answers false. Definition of NP-Hard is correct and correctly identifies that some NP-Hard problems can be reduced to 3SAT. However, this can't be done in general.

F. [True/False] A problem that can be solved by an algorithm whose running time is in O(nlogn)\mathcal{O}(n^{\log n}) is intractable.

Example Solution:
False. Tractable problems are by definition solvable in polynomial-time (i.e. in class P). An algorithm that runs in O(n^(log n)) is not polynomial-time. However, that doesn't preclude the possibility that there is an algorithm that solves it in polynomial-time.

Student Answers:
Definition 1 in chapter 11.3 defines tractable problems as those in complexity class P, i.e. solvable in polynomial time. And intractable problems all problems not in P. In particular, we don't know whether problems in NP are tractable or not, since we don't know whether P=NP.

G. [True/False] Any algorithm with a pair of nested loops has a complexity of O(n2)\mathcal{O}(n^2)

Important to be careful about the reasoning for their answer.

Example Solution:
False. The inner loop could do more than constant work, for instance, which would result in worse than O(n2)\mathcal{O}(n^2) time.

For i in 1...n:
	For j in 1...n:
		insert(<i, j>) into list(A)  # where insert is O(n)-time operation.

Student Answers:

H. [True/False] Dynamic programming and greedy algorithms both require the problems they solve to have optimal substructure.

Example Solution:
True. Dynamic programming and greedy algorithms both require that the problem has optimal substructure. This is because both strategies need to be able to take the optimal solutions to subproblems to generate optimal solutions to the whole problem.

Student Answers:

{Problem 2} (7 pts) If we define sparse graphs as graphs for which EO(V)|E| \in \mathcal{O}(|V|), which implementation of DFS will have a better time efficiency for such graphs, the one that uses an adjacency matrix or the one that uses an adjacency list? Explain your answer.

Example Solution:
The adjacency list will be more efficient. If a sparse graph has on the order of V|V| edges, then DFS with an adjacency list will have O(V)\mathcal{O}(|V|) complexity. The efficiency of DFS depends on your graph representation, i.e. what data structure you need to traverse. For an adjacency list, the complexity is O(V+E)\mathcal{O}(|V| + |E|) and if EO(V)|E| \in \mathcal{O}(|V|), then we get O(V)\mathcal{O}(|V|) for searching a sparse adjacency list. On the other hand, an adjacency matrix is a V×V|V| \times |V| 2d array. To traverse this thing, even if the graph it represents is sparse, requires O(V2)\mathcal{O}(|V|^2) time.

Student Answers:

{Problem 3} (8 pts) For the bottom-up dynamic programming algorithm for the knapsack problem, explain in detail why its time efficiency is O(nC)\mathcal{O}(nC).

Example Solution:
The bottom-up (or tabulation) dynamic programming algorithm for the knapsack problem stores the results of all subproblems in an n×Wn \times W table. It must iterate through each field in the table to calculate all sub-results, so the efficiency is O(nW)\mathcal{O}(nW).

Student Answers:
Key idea to the answer is that the tabulation method requires setting up an n×Wn \times W 2d array and must iterate through each index.

{Problem 4} (10 pts) Briefly describe the way Kruskal's algorithm constructs a minimum spanning tree and its asymptotic complexity.

Example Solution:
Kruskal's builds a minimum spanning tree by iterating through edges in nondecreasing order by weight. We begin with a forest of trees, where every vertex is a tree with just a root. With each edge considered, we add it if and only if the two vertexes of that edge are parts of different trees, making them part of the same tree. To decide if two vertices are part of the same tree, we use a union-find or disjoint set data structure. When all edges have been considered, the vertices along with edges we added constitute a MST.

Kruskal's runs in O(ElogE)\mathcal{O}(E \log E) time or equivalently O(ElogV)\mathcal{O}(E \log V) time, since EE is at most V2V^2 so logE<2logV\log E < 2 \log V. This is because we can sort the edges in O(ElogE)\mathcal{O}(E \log E) time, so considering an edge with min weight can operate in constant time. Deciding whether two vertices are part of the same tree requires O(V)\mathcal{O}(V) operations total. Using a union-find or disjoint set data structure, we can do this in O(VlogV)\mathcal{O}(V \log V) time. So Kruskal's runs in O(ElogE)\mathcal{O}(E \log E) or the tighter bound O(ElogV)\mathcal{O}(E \log V) time.

Student Answers:

{Problem 4} (15 pts total) Consider the following algorithm:
def unknown(n):
	if n = 1:
		return 1
	else
		return unknown(floor(n/2)) + 1

a. (3 pts) What does this algorithm compute?

Example Solution:
It computes the number of digits in a binary representation of nn, i.e. floor(log2n)+1(\log_2 n) + 1

b. (3 pts) What's the basic operation for this algorithm?

Example Solution:
Floor, division, addition are all reasonable picks. Division or floor probably represent the most costly basic operations.

c. (3 pts) Is the best case different from the worst case?

Example Solution:
No, they are the same. The input is some number nn and there's no variance for a given input size.

d. (6 pts) Find the worst case asymptotic complexity for this algorithm?

Example Solution:
Solve T(n)=T(n2)+1T(n) = T(\frac{n}{2}) + 1, for n>1n>1, where T(1)=0T(1) = 0. That ends up being O(logn)\mathcal{O}(\log n) or Θ(logn)\Theta(\log n). Rigorous proof, solving the recurrence relation using backward or forward substitution, or using the master theorem are good solutions, a good informal explanation for the asymptotic complexity is also acceptable.

Student Answers:

{Problem 5} (12 pts total) Greedy Job Scheduling

Consider the problem of scheduling n jobs of known durations t1,t2,...,tnt_1, t_2, . . . , t_n for execution by a single processor. The jobs can be executed in any order, one job at a time. You want to find a schedule that minimizes the total time spent by all the jobs in the system. (The time spent by one job in the system is the sum of the time spent by this job in waiting plus the time
spent on its execution.)

a. (6 pts) Describe a greedy algorithm for this problem. (Primarily looking a greedy rule.)

Example Solution:
Sort them in nondecreasing order by their duration tit_i, then schedule along this order. The greedy rule is to pick the shortest duration first. Idea is that if the shorter jobs are executed first, then later jobs wait less. So we want the minimize the time waiting. Notice that the total execution time for the nn jobs is the same no matter the order. But the amount of time that each job waits to be executed is not.

Student Answers:

b. (6 pts) Does the greedy algorithm always yield an optimal solution? Explain.

Example Solution:
Yes, it's optimal. Optimal in this case refers to the total time spent executing jobs in addition to each job's time waiting to be executed. So picking the shortest duration jobs first means that other jobs wait less before they get executed. That will minimize the total amount of time in execution and waiting.

Student Answers: