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?
BoundingSums
- 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.
GrowableArray
- 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)?
UnionFind
- 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.
HashTable
RecurrenceRelations
- 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).
Graphs
- Define the following terms: neighbor, path, cycle, tree, spanning tree, connected graph, connected component, vertex degree.
DepthFirstSearch
- 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.
BreadthFirstSearch
- 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).
CutVerticesByDFS
- 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.
DiGraphs
DFSInDiGraphs
CyclesByDFS
- Prove that a directed graph has a cycle if and only if DFS will classify some edge of the graph as a back edge.
TopologicalSortByDFS
- 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?
GraphDataStructures
- Describe three different data structures for representing graphs.
- What are the operations supported by these data structures, and what are their time complexities?
CountingPathsByDP
- 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.
FibonacciByDP
- 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.
NChooseKByDP
- 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).
SubsetSumByDP
- 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
MinWtTriangulationByDP
- 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)
ShortestPathsByDijkstras
- 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.
ShortestPathsByDP
- 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.
MinimumSpanningTreesByKruskals
/MinimumSpanningTreeExercises (/MSTExerciseSolutions)
- 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
- Stack via shrinkable array
- Union-Find using parent pointers
- O-notation, sums
- Induction
- Recurrence relations
- Simulate DFS on a directed graph
- Classification of edges
- Algorithm for topologically sorting a directed acyclic graph
- Prove that the root vertex of the DFS tree is a cut vertex iff it has more than one child in the DFS tree
- 1,2. Variations on counting paths.
- 3. Longest ascending subsequences by dynamic programming.
/Hwk4, /Hwk4Soln (maximum shared subsequence)
- example
- prove the recurrence relation
- bound the running time of the recursive algorithm without caching.
- describe a faster algorithm, prove correctness, bound running time.
- implement and run the algorithm.
- Run Dijkstra's on example.
- maximum bottleneck paths.
- minimum spanning tree example.
- shortest vertex-weighted paths
- maximum bottleneck paths.
- non-uniqueness of shortest path trees even if all edge weights are distinct
- s,t-cut vertices
- red and blue rules for finding MST's.
Programming projects
- /Prog1 - growable array, hash table
- /Prog2 - graph class
- /Prog3 - finding a path through a maze
- /Prog4 - distances in a maze
- /Prog5 - shortest vertex-weighted paths
- /Prog6 - finding cut vertices, s,t-cut vertices