Problem Set 4
Given an adjacency-list 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 in-degree 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 in-degree of a vertex. (Recall that the in-degree of a vertex is the number of edges that enter it.)
- Cannot determine from the given information
ANSWER: We must read all edges (or the edge not read may contribute to a in-degree count of the given vertex), so we have the time lowered bounded by
We can compute the in-degree by just reading all edges and keep track of the in-degree count, so we have the time upper bounded by
Therefore the solution is
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.)
ANSWER: Option 3 is correct. For the lower bound, every time we want to find the edges adjacent to a given vertex
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 shortest-path distance between and . (Recall the shortest-path 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 shortest-path 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.]
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:
and
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 |
- 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
Therefore, options 2 and 4 are correct.
Consider our algorithm for computing a topological ordering that is based on depth-first 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 four-node 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
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
Leave a comment