# ClassS04CS141/Review

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences

Difference (from prior major revision) (no other diffs)

Changed: 22,23c22,24
 * HashTable * RecurrenceRelations
 HashTable RecurrenceRelations

GeometricSums
• How do you tell whether a sum is a geometric sum?
• Is a geometric sum proportional to its largest term?
• Is this a geometric sum: i=1..n i2?
• Is that sum proportional to its largest term?
• Give the best big-O upper bound you can on i=1..n i log i.
• Give the best big-Θ lower bound you can on i=1..n i log i.
• Explain why the time taken to support N accesses to a growable array is O(N+M), where M is the maximum index accessed.
• Suppose a sequence of N accesses ends with an access to the N2'th cell in the array. Can the time taken for the entire sequence of accesses be O(N)?
• Describe a data structure for supporting the Union-Find data type that takes O(N + M log M) time to support N Union or Find operations on M elements.
• Explain why your data structure runs in that time.
• Describe the recursion trees for the following recurrences:
T(n) = 3T(n-3); T(0) = 1;
S(n) = 3S(n/3); T(0) = 1;
For each tree, what is the depth and how many children does each node have?
Give the best O and Θ bounds you can on T(n) and S(n).
• Define the following terms: neighbor, path, cycle, tree, spanning tree, connected graph, connected component, vertex degree.
• By hand, run DFS on some undirected and directed graphs. Show the resulting DFS tree and the DFS numbering.
• In an undirected graph, explain why DFS does not classify any edges as cross edges or forward edges.
• What is the worst-case time complexity of DFS on a graph with n nodes and m edges?
• Justify your answer. Give a clear argument bounding the time taken by DFS in terms of n and m.
• Define the distance from a node s to a node t.
• Give pseudo-code for BFS, including the calculation of distances from the source.
• By hand, run BFS on some undirected and directed graphs. Show the resulting distances from the source vertex.
• Give a clear argument that BFS takes linear time -- O(n+m).
• What is the definition of a cut vertex?
• Define what the low numbers are, in the algorithm for finding cut vertices.
• How can you tell whether a vertex is a cut vertex by looking at the low numbers?
• Give a recurrence relation for the low numbers.
• Explain how to use that recurrence relation to find cut vertices in linear time.
• Prove that a directed graph has a cycle if and only if DFS will classify some edge of the graph as a back edge.
• Define topological ordering of a directed acyclic graph.
• Give an example.
• If you order the vertices by DFS number, does that always give a topological ordering?
• Define the DFS post-order numbering.
• Give pseudo-code to compute the DFS post-order numbering.
• If you order the vertices by DFS post-order number, does that always give a topological ordering?
• Describe three different data structures for representing graphs.
• What are the operations supported by these data structures, and what are their time complexities?
• Draw a directed acyclic graph with 10 vertices, choose a source vertex, and label each vertex with the number of paths from the source to that vertex.
• Describe a linear-time algorithm for doing this in arbitrary directed acyclic graphs.
• Describe the recursion tree for the following algorithm:
1. int fib(n) { if (n<= 1) return n; return f(n-1)+f(n-2); }
Argue that the depth of the tree is at least n/2 and at most n.
Argue that the running time of the algorithm is at least 2n/2.
• Describe an algorithm running in O(n) time for computing the n'th fibonacci number.
• Argue that it runs in O(n) time.
• Define "n choose k" = C(n,k).
• Give a recurrence relation for C(n,k).
• Describe an algorithm running in O(nk) time for computing C(n,k).
• Define the subset sum problem.
• Describe a dynamic programming algorithm for the problem.
• What is the running time?
• What is the underlying recurrence relation?

KnapsackByDP - not covered in class

• Define the min-weight triangulation problem.
• Describe a dynamic programming algorithm for the problem.
• What is the running time?
• What is the underlying recurrence relation?

TransitiveClosureByDP (not covered) DynamicProgramming (summary)

• Define the shortest path distance from a node S to a node T in a graph with edge weights.
• Give pseudo-code for Dijkstra's algorithm.
• Illustrate it on a few small examples.
• What is the worst-case running time?
• Give an example of a directed graph with edge weights where Dijkstra's algorithm fails to correctly compute distances from the source.
• Explain the high-level idea behind the proof of correctness.
• Explain the details.
• Give an example of a graph with edge weights where shortest paths are not well defined.
• If a graph has negative edge weights, what is a necessary and sufficient condition for shortest paths in the graph to be well-defined (between every pair of vertices)?
• Describe a dynamic programming algorithm for computing shortest path distances from a given source vertex. The algorithm should work even if the graph has negative edge weights, as long as the shortest paths are well-defined.
• Define what a minimum spanning tree is, in a connected, undirected graph with edge weights.
• Describe two algorithms for finding MSTs.
• Illustrate them on examples.
• What are their worst-case running times? Explain.
• Describe the high-level ideas behind their proofs of correctness.
• Give the details for one of the proofs.

### Homeworks

#### /Hw1, /Hwk1Soln

1. Stack via shrinkable array
2. Union-Find using parent pointers
3. O-notation, sums
4. Induction
5. Recurrence relations

#### /Hwk2, /Hwk2Soln

1. Simulate DFS on a directed graph
2. Classification of edges
3. Algorithm for topologically sorting a directed acyclic graph
4. Prove that the root vertex of the DFS tree is a cut vertex iff it has more than one child in the DFS tree

#### /Hwk3, /Hwk3Soln

1,2. Variations on counting paths.
3. Longest ascending subsequences by dynamic programming.

#### /Hwk4, /Hwk4Soln (maximum shared subsequence)

1. example
2. prove the recurrence relation
3. bound the running time of the recursive algorithm without caching.
4. describe a faster algorithm, prove correctness, bound running time.
5. implement and run the algorithm.

#### /Hwk5, /Hwk5Soln

1. Run Dijkstra's on example.
2. maximum bottleneck paths.
3. minimum spanning tree example.
4. shortest vertex-weighted paths
5. maximum bottleneck paths.

#### /Hwk6, /Hwk6Soln

1. non-uniqueness of shortest path trees even if all edge weights are distinct
2. s,t-cut vertices
3. red and blue rules for finding MST's.

#### Programming projects

1. /Prog1 - growable array, hash table
2. /Prog2 - graph class
3. /Prog3 - finding a path through a maze
4. /Prog4 - distances in a maze
5. /Prog5 - shortest vertex-weighted paths
6. /Prog6 - finding cut vertices, s,t-cut vertices

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences