GRAPHS AND DIGRAPHS I STUDY GUIDE


Undirected graphs vs. directed graphs.   Know when to use each. This should be fairly natural. For example, you'd use an undirected graph to represent friend connections between Facebook users, and a directed graph to represent following connections on Twitter.

Graph representation.   There are many possible internal representations of a graph. We discussed two (adjacency matrix and adjacency lists). You should be familiar with the tradeoffs. Usually, we use the adjacency-lists representation because most real-world graphs are sparse.

Depth-first search. You should know this algorithm absolutely cold by the time the exam comes around. For example, you should be able to write DepthFirstSearch.java in your sleep, and the worst-case running time of Θ(E + V) (using the adjacency-lists representation) should be scorched into your neurons.

Path finding. It's easy to modify DFS to not only find which vertices are reachable from a given vertex s but also to find such a path.

Undirected graphs. Many problems on undirected graphs can be solved by replacing each undirected edge with two anti-parallel directed edges.

Graph client design pattern (used for 4.1, 4.2, 4.3, and 4.4).   Instead of creating bloated data types that both provide basic graph operations and solve graph problems, we have one class (e.g. Digraph) that provides basic graph operations and many special-purpose clients, each of which solves one graph problem (e.g. DirectedDFS).

Recommended Problems

C level

  1. Textbook: 4.1.12
  2. Fall 2012 Final, #3
  3. Spring 2012 Final, #3a
  4. Spring 2014 Final, #2a, #2bb

B level

  1. Textbook: 4.1.14, 4.1.10
  2. What is the running time for DFS if we use the adjacency-matrix representation (instead of the adjacency-lists representation)?

A level

  1. Spring 2012 Final, #12
  2. Textbook: 4.1.33