CS302 Final Exam, December 11, 2012 - James S. Plank

Question 1: Warm Up

There are N bases, numbered 0 through N-1. You will be given a vector of strings named A. A has N strings, each of which has N characters, which are either zero or one. If A[i][j] is equal to '1', then you may teleport from base i to base j. If A[i][j] is '0', then you cannot teleport from base i to base j. Teleports are uni-directional, so just because you can teleport from base i to base j does not mean that you can teleport from base j to base i. Write the procedure fastest() with the following prototype:

int fastest(vector <string> &A);

Fastest() should return the fewest number of teleports that it takes to go from base 0 to base N-1. If you cannot get to base N-1 from base 0, return -1.


Question 2: Topological Sort

Which of the following are valid topological sorts of the graph to the right?
  • a: A, B, C, D, E, F, G, H
  • b: A, B, C, G, F, D, E, H
  • c: A, G, B, C, E, H, F, D
  • d: A, G, H, B, E, F, C, D
  • e: A, B, C, G, E, F, D, H
  • f: A, G, H, E, F, D, B, C
  • g: A, B, E, G, C, F, G, D
  • h: A, G, H, B, E, F, C, D
  • i: There is no valid topological sort.


Question 3: Network flow

The following questions pertain to the graph below, with source S and sink T:

Part 1: Suppose you are determining the maximum flow through this graph. Tell me your first augmenting path using each of the following path determination algorithms:
  • a: Greedy DFS
  • b: Modified Dijkstra
  • c: Edmonds-Karp
Part 2: The maximum flow through this graph is 51. You've asked your friend Skippy to tell you what the minimum cut of this graph is. Below are four potential answers that Skippy gives you. For each of these answers, tell me whether the answer is correct or not. If incorrect, tell me why.
  • a: 51
  • b: CD
  • c: AC, BC, GC
  • d: ET, EI