* HashTable * RecurrenceRelations |

HashTable RecurrenceRelations |

GeometricSums

### Homeworks

#### /Hw1, /Hwk1Soln

#### /Hwk2, /Hwk2Soln

#### /Hwk3, /Hwk3Soln

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

#### /Hwk5, /Hwk5Soln

#### /Hwk6, /Hwk6Soln

#### Programming projects

- 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}i^{2}? - 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 N
^{2}'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 2
^{n/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.

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.

- 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.

- 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.