Final Exam

Consider a connected undirected graph with distinct edge costs. Which of the following are true? [Check all that apply.]

  • Suppose the edge is not the cheapest edge that crosses the cut . Then does not belong to any minimum spanning tree.
  • Suppose the edge is the most expensive edge contained in the cycle . Then does not belong to any minimum spanning tree.
  • The minimum spanning tree is unique.
  • Suppose the edge is the cheapest edge that crosses the cut . Then belongs to every minimum spanning tree.

ANSWER: Option 3 is correct because the edge weights are distinct. Options 2 and 4 follow from the Cut Property based on the correctness of option 3 and are correct as well.

Consider the following graph, where cost of edge is greater than the cost of edge . Edges and are both included in the MST, even though isn’t the cheapest edge crossing the cut shown.

   X
A+-X--+B
   X   +
   X   |
   X   +
D+-X--+C
   X

Thus, option 1 is incorrect.

Which of the following graph algorithms can be sped up using the heap data structure?

  • Dijkstra’s single-source shortest-path algorithm (from Part 2).
  • Prim’s minimum-spanning tree algorithm.
  • Our dynamic programming algorithm for computing a maximum-weight independent set of a path graph.
  • Kruskal’s minimum-spanning tree algorithm.

ANSWER: Options 1 and 2 are correct. MWIS doesn’t consider the edges in sorted order, so a heap won’t help. Kruskal’s algorithm requires the edges to be sorted, which can be done by using a min-heap, but it won’t provide any speed up over a fast comparison sort.

Which of the following problems reduce, in a straightforward way, to the minimum spanning tree problem? [Check all that apply.]

  • The maximum-cost spanning tree problem. That is, among all spanning trees of a connected graph with edge costs, compute one with the maximum-possible sum of edge costs.
  • The minimum bottleneck spanning tree problem. That is, among all spanning trees of a connected graph with edge costs, compute one with the minimum-possible maximum edge cost.
  • The single-source shortest-path problem.
  • Given a connected undirected graph with positive edge costs, compute a minimum-cost set such that the graph is acyclic.

ANSWER: If we negate the weights of all edges, a minimum-cost spanning tree algorithm yields a maximum-cost spanning tree. Thus, option 1 is correct.

A minimum bottleneck spanning tree is also a MST. Thus, option 2 is correct.

Option 4 is also correct since a MST, by definition, doesn’t have a cycle. However, it’s not clear to me what prevents is to take only a single edge. There’s nothing in the question that indicates needs to be connected.

Option 3 is incorrect; this problem doesn’t consider edge costs.

Recall the greedy clustering algorithm from lecture and the max-spacing objective function. Which of the following are true? [Check all that apply.]

  • If the greedy algorithm produces a -clustering with spacing , then every other -clustering has spacing at most .
  • Suppose the greedy algorithm produces a -clustering with spacing . Then, if are two points in a common cluster of this -clustering, the distance between and is at most .
  • If the greedy algorithm produces a -clustering with spacing , then the distance between every pair of points chosen by the greedy algorithm (one pair per iteration) is at most .
  • This greedy clustering algorithm can be viewed as Prim’s minimum spanning tree algorithm, stopped early.

ANSWER: Option 1 is correct; the greedy algorithm is optimal.

Option 2 is incorrect. The greedy algorithm merges closest points as long as the number of clusters is less than or equal to . If the distance between was at most , they would’ve been merged.

Option 3 is correct.

Option 4 is incorrect. The greedy algorithm can be viewed as Kruskal’s algorithm stopped early, not Prim’s.

We are given as input a set of jobs, where job has a processing time and a deadline . Recall the definition of completion times from the video lectures. Given a schedule (i.e., an ordering of the jobs), we define the lateness of job as the amount of time after its deadline that the job completes, or as if . Our goal is to minimize the total lateness, .

Which of the following greedy rules produces an ordering that minimizes the total lateness? You can assume that all processing times and deadlines are distinct.

WARNING: This is similar to but not identical to a problem from Problem Set #1 (the objective function is different).

  • Schedule the requests in increasing order of processing time
  • None of the other options are correct
  • Schedule the requests in increasing order of deadline
  • Schedule the requests in increasing order of the product

ANSWER: Potts and Van Wassenhove have shown this to be a NP-Hard problem Single Machine Scheduling to Minimize Total Late Work. Option 2 is correct.

Which of the following extensions of the Knapsack problem can be solved in time polynomial in , the number of items, and , the largest number that appears in the input? [Check all that apply.]

  • You are given items with positive integer values and sizes, as usual, and two positive integer capacities, and . The problem is to pack items into these two knapsacks (of capacities and ) to maximize the total value of the packed items. You are not allowed to split a single item between the two knapsacks.
  • You are given items with positive integer values and sizes, and a positive integer capacity , as usual. The problem is to compute the max-value set of items with total size exactly . If no such set exists, the algorithm should correctly detect that fact.
  • You are given items with positive integer values and sizes, and a positive integer capacity , as usual. You are also given a budget on the number of items that you can use in a feasible solution. The problem is to compute the max-value set of at most items with total size at most .
  • You are given items with positive integer values and sizes, as usual, and positive integer capacities, . These denote the capacities of different Knapsacks, where could be as large as . The problem is to pack items into these knapsacks to maximize the total value of the packed items. You are not allowed to split a single item between two of the knapsacks.

ANSWER: Problem 1 is the 0-1 Knapsack Problem with 2 knapsacks, and is solvable in polynomial time. Add another dimension to the array to keep track of the residual capacity of the second knapsack, this increases the running time by a factor of at most . See Problem Set 3 for a solution.

Problem 2 is the Subset-Sum Problem, and is solvable in polynomial time.

Problem 3 is the Bounded Knapsack Problem, and is solvable in polynomial time. Add another dimension to the array to keep track of number of items used so far, this increases the running time by a factor of at most .

Problem 4 is NP-Complete, and is not solvable in polynomial time.

Thus, options 1, 2 and 3 are correct.

Of the following dynamic programming algorithms covered in lecture, which ones always perform work per subproblem? [Check all that apply.]

  • The Floyd-Warshall all-pairs shortest-paths algorithm.
  • The dynamic programming algorithm for the optimal binary search tree problem.
  • The dynamic programming algorithm for the knapsack problem.
  • The dynamic programming algorithm for the sequence alignment problem.
  • The Bellman-Ford shortest-path algorithm.

ANSWER: Each of Floyd-Warshall, DP algorithms for the Knapsack Problem and the Sequence Alignment Problem do work per subproblem.

Bellman-Ford does linear work per subproblem, so does the DP algorithm for the Optimal BST Problem.

Thus, options 1, 3, and 4 are correct.

Assume that . Which of the following problems can be solved in polynomial time? [Check all that apply.]

  • Given a directed acyclic graph with real-valued edge lengths, compute the length of a longest path between any pair of vertices.
  • Given a directed graph with real-valued edge lengths, compute the length of a longest cycle-free path between any pair of vertices (i.e., , where denotes the set of cycle-free paths).
  • Given a directed graph with nonnegative edge lengths, compute the length of a longest cycle-free path between any pair of vertices (i.e., , where denotes the set of cycle-free paths).
  • Given a directed graph with nonnegative edge lengths, compute the length of a maximum-length shortest path between any pair of vertices (i.e., , where is the shortest-path distance between and ).

ANSWER: Option 1: Longest path in a DAG can be computed in polynomial (linear) time by simply negating the edge weights. also see this paper.

Option 2: The NP-Complete Hamiltonian Path problem reduces easily to this problem, so it cannot be solved in polynomial time assuming .

Option 3: The NP-Complete Hamiltonian Path problem reduces easily to this problem, so it cannot be solved in polynomial time assuming .

Option 4: Since edge lengths are nonnegative, there are no negative cycles. Thus, this problem reduces to all-pairs shortest paths.

Recall the all-pairs shortest-paths problem. Which of the following algorithms are guaranteed to be correct on instances with negative edge lengths that don’t have any negative-cost cycles? [Check all that apply.]

  • Run the Bellman-Ford algorithm times, once for each choice of a source vertex.
  • Run Dijkstra’s algorithm times, once for each choice of a source vertex.
  • Johnson’s reweighting algorithm.
  • The Floyd-Warshall algorithm.

ANSWER: Options 1,2, and 4 are correct. Follows from the lectures.

Suppose a computational problem that you care about is NP-complete. Which of the following are true? [Check all that apply.]

  • Since the dynamic programming algorithm design paradigm is only useful for designing exact algorithms, there’s no point in trying to apply it to the problem .
  • You should not try to design an algorithm that is guaranteed to solve correctly and in polynomial time for every possible instance (unless you’re explicitly trying to prove that ).
  • NP-completeness is a “death sentence”; you should not even try to solve the instances of that are relevant for your application.
  • If your boss criticizes you for failing to find a polynomial-time algorithm for , you can legitimately claim that thousands of other scientists (including Turing Award winners, etc.) have likewise tried and failed to solve .

ANSWER: Option 1: False; dynamic programming can potentially be used to design faster (but still exponential-time) exact algorithms (as with TSP), to design heuristics with provable performance guarantees (as with Knapsack), and to design exact algorithms for special caes (as with Knapsack).

Option 2: True; remember, in trying to solve one NP-complete problem, we are trying to solve them all. Countless brilliant minds have tried to devise polynomial-time algorithms for NP-complete problems (and thus, indirectly, for this NP-complete problem); none have yet succeeded.

Option 3: False; perhaps the instances of arising in our domain are special enough to be solved efficiently (in theory and/or in practice).

Option 4: True.

Of the following problems, which can be solved in polynomial time by directly applying algorithmic ideas that were discussed in lecture and/or the homeworks? [Check all that apply.]

  • Given an undirected graph and a value for such that , where is the number of vertices of , does have a vertex cover of size at most ?
  • Given an undirected graph and a constant value for (i.e., , independent of the size of ), does have an independent set of size at least ?
  • Given an undirected graph and a value for such that , where is the number of vertices of , does have an independent set of size at least ?
  • Given an undirected graph and a constant value for (i.e., , independent of the size of ), does have a vertex cover of size at most ?

ANSWER: Option 1: True; the Vertex Cover algorithm covered in lecture has running time and hence runs in polynomial time in this case.

Option 2: True; brute-force search (checking each subset of vertices) runs in time , which is polynomial when .

Option 3: False; there is a reduction between the vertex cover and independent set problems where one can take the complement of one to get the other. Unfortunately, this transforms vertex covers of size to independent sets of size and thus is not useful here. Also, it is not clear how to adapt the Vertex Cover algorithm from lecture to the Independent Set problem. In fact, it is conjectured that this problem cannot be solved in polynomial time at all.

Option 4: True; brute-force search (checking each subset of vertices) runs in time , which is polynomial when .

In lecture we gave a dynamic programming algorithm for the traveling salesman problem. Does this algorithm imply that ? [Check all that apply.]

  • Yes, it does.
  • No. A polynomial-time algorithm for the traveling salesman problem does not necessarily imply that .
  • No. Since we sometimes perform a super-polynomial amount of work computing the solution of a single subprolem, the algorithm does not run in polynomial time.
  • No. Since we perform a super-polynomial amount of work extracting the final TSP solution from the solutions of all of the subproblems, the algorithm does not run in polynomial time.
  • No. Since there are an exponential number of subproblems in our dynamic programming formulation, the algorithm does not run in polynomial time.

ANSWER: Option 1: False; if it did, we’d be a million bucks richer!

Option 2: False; since (the decision version of) the traveling salesman problem is NP-complete, a polynomial-time algorithm for TSP would indeed imply that .

Option 3: False; we only do work computing the answer to a single subproblem; the issue is that there are exponentially many such subproblems.

Option 4: False; We only do work computing the final answer, given the solutions of all of the (exponentially many) subproblems.

Option 5: True.

Consider the Knapsack problem and the following greedy algorithm: (1) sort the items in nonincreasing order of value over size (i.e., the ratio ); (2) return the maximal prefix of items that fits in the Knapsack (i.e., the items with the largest ratios, where is as large as possible subject to the sum of the item sizes being at most the knapsack capacity ). Which of the following are true? [Check all that apply.]

  • If all items have the same value, then this algorithm always outputs an optimal solution (no matter how ties are broken).
  • This algorithm always outputs a feasible solution with total value at least times that of an optimal solution.
  • If all items have the same size, then this algorithm always outputs an optimal solution (no matter how ties are broken).
  • If the size of every item is at most of the Knapsack capacity (i.e., for every ), then this algorithm is guaranteed to output a feasible solution with total value at least times that of an optimal solution.
  • If all items have the same value/size ratio, then this algorithm always outputs an optimal solution (no matter how ties are broken).

ANSWER: Remember that in the Knapsack Problem, we prefer items of higher value and smaller size.

Option 1: True; clearly, the more number of items we pick, greater the value. We can pick more items we we prefer smaller ones than larger ones.

Option 2: False; this is only true if you add a third step, which takes the better of this solution and the max-value item (as discussed in lecture).

Option 3: True; all feasible solutions pack the same number of items, thus, clearly, the optimal solution should choose items with higher values first.

Option 4: True; as discussed in lecture, this is true even without the “step 3” optimization that compares the greedy solution to the max-value item.

Option 5: False; suppose . If ties are broken arbitrarily, might be chosen, whereas the optimal solution would choose and .

Which of the following statements are true about the tractability of the Knapsack problem? [Check all that apply.]

  • Assume that . The special case of the Knapsack problem in which all item sizes are positive integers less than or equal to , where is the number of items, can be solved in polynomial time.
  • If there is a polynomial-time algorithm for the Knapsack problem in general, then .
  • Assume that . The special case of the Knapsack problem in which all item values are positive integers less than or equal to , where is the number of items, can be solved in polynomial time.
  • Assume that . The special case of the Knapsack problem in which all item values, item sizes, and the knapsack capacity are positive integers, can be solved in polynomial time.

ANSWER: Option 1: True; lecture video 17.4.

Option 2: True; the (decision version of) the Knapsack problem is NP-Complete.

Option 3: True; lecture video 17.5.

Option 4: False; if the s and are integers, can solve via DP in time. If s are integers, can solve in time. Can’t solve in polynomial time for arbitrarily large item values, item sizes, and the knapsack capacity.

Which of the following graph algorithms can be implemented, using suitable data structures, in time? (As usual, and denote the number of edges and vertices, respectively.) [Check all that apply.]

  • The Bellman-Ford shortest-path algorithm.
  • Prim’s minimum spanning tree algorithm.
  • Johnson’s all-pairs shortest-path algorithm.
  • Kruskal’s minimum spanning tree algorithm.

ANSWER: Option 1: False; , which in sparse graphs, is , in dense graphs, .

Option 2: True; as covered in lecture, using the heap data structure.

Option 3: False; . Better than invocations of Bellman-Ford in sparse graphs.

Option 4: True; as covered in lecture, using the union-find data structure.