Problem Set 4
Given an adjacencylist representation of a directed graph, where each vertex maintains an array of its outgoing edges (but *not* its incoming edges), how long does it take, in the worst case, to compute the indegree of a given vertex? As usual, we use and to denote the number of vertices and edges, respectively, of the given graph. Also, let denote the maximum indegree of a vertex. (Recall that the indegree of a vertex is the number of edges that enter it.)
 \(\Theta(n)\)
 Cannot determine from the given information
 \(\Theta(k)\)
 \(\Theta(m)\)
ANSWER: We must read all edges (or the edge not read may contribute to a indegree count of the given vertex), so we have the time lowered bounded by .
We can compute the indegree by just reading all edges and keep track of the indegree count, so we have the time upper bounded by .
Therefore the solution is . Option 4 is correct.
Consider the following problem: given an undirected graph with vertices and edges, and two vertices and , does there exist at least one path?
If is given in its adjacency list representation, then the above problem can be solved in time, using BFS or DFS. (Make sure you see why this is true.)
Suppose instead that is given in its adjacency *matrix* representation. What running time is required, in the worst case, to solve the computational problem stated above? (Assume that has no parallel edges.)
 \(\Theta(n * m)\)
 \(\Theta(m + n\log n)\)
 \(\Theta(n^2)\)
 \(\Theta(m + n)\)
ANSWER: Option 3 is correct. For the lower bound, every time we want to find the edges adjacent to a given vertex , we have to traverse the whole array, which is of length ; this happens for all the vertices. One easy way to prove the upper bound is to first build an adjacency list representation in time, with a single scan over the given adjacency matrix and then run BFS or DFS as in the video lectures.
This problem explores the relationship between two definitions about graph distances. In this problem, we consider only graphs that are undirected and connected. The diameter of a graph is the maximum, over all choices of vertices and , of the shortestpath distance between and . (Recall the shortestpath distance between and is the fewest number of edges in an path.)
Next, for a vertex , let denote the maximum, over all vertices , of the shortestpath distance between and . The radius of a graph is the minimum of over all choices of the vertex .
Which of the following inequalities always hold (i.e., in every undirected connected graph) for the radius and the diameter ? [Select all that apply.]
 \(r \leq \frac{d}{2}\)
 \(r \leq d\)
 \(r \geq d\)
 \(r \geq \frac{d}{2}\)
ANSWER: We need some definitions:
 Distance: The distance between two vertices and in a graph is is defined as the length of a shortest path from to and is denoted by . Distance on graphs is a metric and defines a metric space. Mathematically, , where is the vertex set and the set of positive integers.
Distance rules:
 \(d(u, v) \geq 0\) and \(d(u, v) = 0 \iff u = v\)
 \(d(u, v) = d(v, u)\)
 \(d(u, w) \leq d(u, v) + d(v, w)\)
1 and 2 should be obvious. 3 follows from the Triangle inequaity; we can use this property because distance on graphs is a metric.

Eccentricity: Maximum distance between a given vertex to any other vertex in the graph.

Diameter: Maximum eccentricity.

Radius: Minumum eccentricity.
Example:
v  e(v) 

v1  3 
v2  2 
v3  2 
v4  2 
v5  3 
\(diam(G) = 3, rad(G) = 2\)
 Center: The set of all such vertices for which make up the center of .
 Periphery: The set of all such vertices for which make up the periphery of .
Now, we will prove that . The first part is obvious from the definitions of radius and diameter. For the second part, consider two vertices and on the periphery. Consider a vertex in the center. By distance law:
Therefore, options 2 and 4 are correct.
Consider our algorithm for computing a topological ordering that is based on depthfirst search (i.e., NOT the “straightforward solution”). Suppose we run this algorithm on a graph that is NOT directed acyclic. Obviously it won’t compute a topological order (since none exist). Does it compute an ordering that minimizes the number of edges that go backward?
For example, consider the fournode graph with the six directed edges . Suppose the vertices are ordered . Then there is one backwards arc, the arc. No ordering of the vertices has zero backwards arcs, and some have more than one.
 Sometimes yes, sometimes no
 Never
 If and only if the graph is a directed cycle
 Always
ANSWER: The graph in question is shown below:
If we run DFS from vertex , there is only one backward edge . But if we run DFS from , the ordering is , with all the edges pointing backward. Thus, option 1 is coorect.
On adding one extra edge to a directed graph , the number of strongly connected components…?
 …never decreases by more than 1 (no matter what is)
 …never decreases (no matter what is)
 …could remain the same (for some graphs )
 …will definitely not change (no matter what is)
ANSWER: Consider the directed path ; there are four SCCs, one for each vertex. If we add an edge , then the four SCCs merge into one; therefore, options 1, 2 and 4 are incorrect. On the other hand, adding edge doesn’t change anything. Thus, option 3 is correct.