Lec Test2 Review
Lec Test2 Review
• You do not need to prove something unless you are explicitly asked to prove
something
• No calculators or electronic devices. You will not need them. If you have to do
any computations, they will be basic enough to do by hand.
• You will put your name on the front page, and put your initials at the top of every
other page.
• Some questions may involve a combination of a couple different things we’ve seen
in different lectures.
For all of these graph algorithms, here’s the short answer on what you should know:
• How is the problem defined? In particular, what type of graph does it apply to?
Are there restrictions?
• What algorithms solve the problem, what is their basic mechanism, and their
runtime?
• Don’t just know how to eye-ball a solution for a small graph. You should know
the mechanics of each algorithm well enough that you could apply it to a small
graph, could write out pseudocode if need be, and provide a runtime analysis
• Undirected and directed, weighted and unweighted (which of these can be viewed
as special cases of others?)
Page 2
2.4 Depth-first search
• Know the different edge types in a depth-first search and what they mean
• Know the two main applications we discussed in class and how to use DFS for
them.
• You should know what a cut is, and what a “safe” edge is.
• We did a mini runtime analysis for Prim’s algorithm: you should know what the
runtime is and how that basic argument worked (there are many other algorithms
with similar types of runtime analyses).
• You should understand the basic mechanism behind each, and different pros/cons
of their runtimes
• What is the basic idea behind the algorithms we have seen? Hint: it isn’t that
you repeatedly try to send flow from s to t as long as you can find unsaturated
paths in the original graph G.
3 Practice Problems
1. When does breadth-first search solve the same problem as Dijkstra’s algorithm?
2. What are the applications of a breadth first search? What problem(s) does it solve?
3. What are the two applications we saw for depth first search? Longer question: how
does each one work?
4. Prove whether this is true or false: running a breadth first search in a directed
graph returns the weakly connected components of that directed graph.
Page 3
Figure 1: Sample graph 1
5. Consider the graph in Figure 2, but for this problem ignore the edge directions.
Write down the minimum spanning tree that you would obtain from running Kruskal’s
algorithm, and the MST obtained by running Prim’s algorithm starting from node
3.
6. Let G = (V, E) be a directed graph. If you assume that |E| = Θ(V 2 ), what
data structure should you use to implement the min-priority queue in Dijkstra’s
algorithm, and why?
7. What are the weakly connected and strongly connected components of sample graph
1?
8. Write down the adjacency matrix and the adjacency list for each of the sample
graphs.
9. Draw the breadth-first tree of the sample graph 1 from starting node e
10. Find the minimum s-t cut of sample graph 1 when s = a and t = f . Explain
whether you get the same minimum s-t cut value when s = f and t = a.
11. Write out a valid s-t flow for the graph in Figure 2.
12. Write out a topological ordering for each of the sample graphs or prove that it
cannot exist.
13. Solve other BFS, DFS, MST, single source shortest path problems on the sample
graphs (e.g., try a different source and/or sink node, change weights slightly, etc.)
Page 4
Figure 2: Sample graph 2
Page 5