• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 76 pages
Exam (elaborations)

CS 5800 Midterm Exam | Questions and answers with Rationales | Updated | 100% Correct - Northeastern University.

Document preview thumbnail
Preview 4 out of 76 pages

CS 5800 Midterm Exam | Questions and answers with Rationales | Updated | 100% Correct - Northeastern University.

Content preview

CS 5800 Midterm Exam | Questions and
Solutions | 2026 Updated | 100% Correct -
Northeastern University.

1. Which of the following statements about the asymptotic relationship between the
functions f(n) = n^2 log n and g(n) = n^2.001 is true?

A. f(n) = O(g(n))
B. f(n) = (g(n))
C. f(n) = (g(n))
D. f(n) and g(n) are asymptotically incomparable

Answer: A. f(n) = O(g(n))
Rationale: For large n, n^2.001 grows faster than n^2 log n because any positive power of
n eventually dominates any polylogarithmic factor. Thus f(n) = O(g(n)), but the reverse is
not true, so and are incorrect. Incomparability is false because both are positive functions
and one dominates.


2. Consider the recurrence T(n) = 2T(n/4) + n. What is the tight asymptotic bound for
T(n)?

A. (n)
B. (n log n)
C. (n)
D. (n log n)

Answer: B. (n log n)
Rationale: Using the Master Theorem: a=2, b=4, f(n)=n. log_b a = log_4 2 = 0.5, so
n^{log_b a} = n. Since f(n) = (n), we are in Case 2, giving T(n) = (n log n). Other options
misapply the theorem or ignore the logarithmic factor.




Page 1 of 76

,3. In the 0/1 knapsack problem, a dynamic programming solution uses a table dp[i][w]
representing the maximum value achievable using the first i items with capacity w. If
item i has weight w_i and value v_i, which recurrence correctly computes dp[i][w]?

A. dp[i][w] = max(dp[i-1][w], v_i + dp[i-1][w - w_i])
B. dp[i][w] = max(dp[i-1][w], v_i + dp[i][w - w_i])
C. dp[i][w] = max(dp[i-1][w], v_i + dp[i-1][w])
D. dp[i][w] = dp[i-1][w] + v_i

Answer: A. dp[i][w] = max(dp[i-1][w], v_i + dp[i-1][w - w_i])
Rationale: For 0/1 knapsack, each item can be used at most once, so we must refer to the
previous row (i-1) when including the item. Option B allows reusing the same item
(unbounded knapsack), Option C ignores the weight constraint, and Option D always adds
the value without considering capacity.


4. Which of the following problems can be solved optimally by a greedy algorithm?

A. 0/1 knapsack problem
B. Activity selection problem
C. Traveling salesman problem
D. Longest common subsequence

Answer: B. Activity selection problem
Rationale: The activity selection problem exhibits the greedy-choice property and optimal
substructure, allowing a greedy algorithm that selects the activity with the earliest finish
time. The 0/1 knapsack and TSP are NP-hard, and longest common subsequence requires
dynamic programming.




Page 2 of 76

,5. In a directed graph with non-negative edge weights, which algorithm correctly
computes single-source shortest paths and has a time complexity of O(E + V log V)
when implemented with a Fibonacci heap?

A. Bellman-Ford algorithm
B. Dijkstra's algorithm
C. Floyd-Warshall algorithm
D. Prim's algorithm

Answer: B. Dijkstra's algorithm
Rationale: Dijkstra's algorithm with a Fibonacci heap achieves O(E + V log V) for
non-negative weights. Bellman-Ford handles negative weights but is O(VE);
Floyd-Warshall solves all-pairs; Prim's algorithm finds minimum spanning trees, not
shortest paths.


6. Which of the following statements about the NP-completeness of the Boolean
satisfiability problem (SAT) is correct?

A. SAT is NP-complete, and 3-SAT is also NP-complete.
B. SAT is NP-complete, but 3-SAT is in P.
C. SAT is in P, but 3-SAT is NP-complete.
D. Both SAT and 3-SAT are in P.

Answer: A. SAT is NP-complete, and 3-SAT is also NP-complete.
Rationale: The Cook-Levin theorem establishes SAT as NP-complete. 3-SAT is also
NP-complete because any SAT instance can be reduced to 3-SAT in polynomial time. The
other options incorrectly claim 3-SAT or SAT is in P.




Page 3 of 76

, 7. Consider a randomized algorithm that, on any input, has a probability of at most
1/2 of giving an incorrect answer. If we run the algorithm independently 10 times and
take the majority answer, what is the probability that the majority answer is
incorrect?

A. At most 1/2
B. At most 1/4
C. At most (1/2)^10
D. At most 1/1024

Answer: C. At most (1/2)^10
Rationale: This question is under revision. The correct answer is C based on the
assumption that the majority vote reduces error exponentially, but the exact bound depends
on the error probability. In standard randomized algorithms, repeating independent runs
and taking majority reduces error probability exponentially if the original error probability
is strictly less than 1/2. Here, with error 1/2, the bound (1/2)^10 is a loose upper bound.
However, the question is flawed; a better version would specify error 1/3. For now, C is the
intended answer.


8. In the context of NP-completeness, which of the following is a polynomial-time
reduction from problem A to problem B?

A. A function f that maps instances of A to instances of B such that x A if and only if
f(x) B, and f can be computed in polynomial time.
B. A function f that maps instances of A to instances of B such that x A if and only if
f(x) B, and f can be computed in exponential time.
C. A function f that maps instances of B to instances of A such that x B if and only if
f(x) A, and f can be computed in polynomial time.
D. A function f that maps instances of A to instances of B such that x A implies f(x) B,
and f can be computed in polynomial time.

Answer: A. A function f that maps instances of A to instances of B such that x A if and
only if f(x) B, and f can be computed in polynomial time.
Rationale: A polynomial-time reduction from A to B requires a polynomial-time
computable function f such that x A iff f(x) B. Option B uses exponential time, which is not
a polynomial-time reduction. Option C reverses the direction, and Option D only requires
one direction, missing the 'if and only if' condition.




Page 4 of 76

Document information

Uploaded on
October 13, 2026
Number of pages
76
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$26.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ProfReginaBank
4.7
(3)
Sold
22
Followers
2
Items
1970
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions