Wednesday, December 5, 2001 Name:____________________
Please use the following notation on this quiz:
q To specify the number of vertices in a graph, write V.
q To specify the number of edges in a graph, write E.
(Much less cumbersome than writing |V| and |E|)
Use average case analysis to compute the tightest possible running time bounds.
q Give your answers in terms of the average number of vertices adjacent to a given vertex. (Hint: think of the adjacency list as being analogous to a hash table chain.)
q Use V, E or both as appropriate in your answers.
q Give your answers in big-O notation.
q Assume that accessing a single vertex is an O(1) operation.
q Base each answer on whether the graph is represented as an adjacency list or an adjacency matrix.
|
Adjacency List |
Adjacency Matrix |
Access all vertices adjacent to a given vertex. |
|
|
Access all edges adjacent to a given vertex. |
|
|
Given vertices u and v, determine whether (u, v) is an edge in the graph. |
|
|
q Assume the graph is represented as an adjacency list.
q Assume each vertex is labeled with its in-degree (# of inbound edges).
q For loop statements, the running time bound should be the number of loop iterations.
q Where appropriate, use your result(s) from Problem 1 to compute the tightest possible running time bounds.
void TopoSort() { |
|
For each vertex v in the list of vertices |
|
If v has in-degree 0, put it in a queue |
|
While the queue is not empty |
|
Dequeue a vertex v and output it |
|
For each vertex u adjacent to v |
|
Reduce u’s in-degree by 1 |
|
If u has in-degree 0, enqueue it |
|
} |
|
Yes |
No |
Reachability in a directed graph. |
Yes |
No |
Adjacency in an undirected graph. |
Yes |
No |
Equality among integers. |
Yes |
No |
Loose inequality (£ or ³) among integers. |
The following definitions apply to the
questions below.
q The density d of a non-empty graph is
defined as:
d º (# edges) / (# vertices) º E / V
q A complete graph is one in which every
vertex is adjacent to every other vertex.
q An unconnected graph is one in which no
vertex is adjacent to any other vertex.
q A self-edge is an edge (v, v) that
joins a vertex v to itself.
Answer the following questions exactly.
q Don’t use big-O notation.
q Assume that all graphs are non-empty.
q Assume that there are no self-edges.