Final Course Review: Practice Problems

1. Algorithm Paradigm Identification

If you're solving a problem by breaking it into subproblems that share the same recursive structure and overlap extensively, which paradigm should you use?

Show Answer

Dynamic Programming.

Overlapping subproblems are the hallmark of DP. Divide and Conquer is used when subproblems are independent.

2. Sorting Complexity

Can a comparison-based sorting algorithm sort $n$ elements in $O(n)$ time worst-case? Why or why not?

Show Answer

No.

The lower bound for comparison-based sorting is $\Omega(n \lg n)$ due to the decision tree height required to represent all $n!$ permutations.

3. Shortest Paths

You have a graph with negative edge weights but no negative cycles. Which algorithm should you use for single-source shortest paths?

Show Answer

Bellman-Ford.

Dijkstra fails with negative weights because it assumes the shortest distance to a vertex is final once extracted from the priority queue.

4. Complexity Classes

Is $P \subseteq NP$? Explain.

Show Answer

Yes.

Any problem solvable in polynomial time (P) is trivially verifiable in polynomial time (NP) by simply re-solving it.