Homework Assignment 8
Due: Apr. 6 before class starts
Assignment
-
(40 points) Draw an adjacency list and adjacency matrix representation of
the undirected graph shown in Figure 14.1.
-
(30 points) Suppose we represent a graph
G having
n vertices and m edges with the edge list
structure. Why, in this case, does the insertVertex method
run in O(1) time while the removeVertex method
runs in O(m) time? Statement and proof of complexity required.
-
(30 points) Would you use the adjacency matrix structure or the adjacency
list structure in each of the following cases? Justify your choice.
- The graph has 10,000 vertices and 20,000 edges, and it is important
to use as little space as possible.
- The graph has 10,000 vertices and 20,000,000 edges, and it is
important to use as little space as possible.
- You need to answer the query
getEdge(u, v) as fast as
possible, no matter how much space you use.
-
Bonus.
(10 points) Suppose we wish to represent an
n-vertex graph
G using the edge list structure, assuming that we identify the
vertices with the integers in the set {0, 1, ..., n - 1}.
Describe how to implement the collection E to support
O(log n)-time performance for the getEdge(u, v)
method. How are you implementing the method in this case?