CS112 Spring 2011: Problem Set 11
Graphs I

1.
Suppose a weighted undirected graph has /n/ vertices and /e/ edges.
The weights are all integers. Assume that the space needed to store
an integer is the same as the space needed to store an object
reference, both equal to one unit. /What is the minimum value of e/
for which the adjacency matrix representation would require less
space than the adjacency linked lists representation? Ignore the
space needed to store vertex labels.
*SOLUTION*
Space for adjacency matrix (AMAT) is /n^2/. Space for adjacency
linked lists (ALL) is /n + 2*2e = n + 4e/. (Each node needs 2 units
of space, and there are 2/e/ nodes.) The space required by AMAT and
ALL is the same when /n^2 = n + 4e/, i.e. when /e = (n^2  n)/4/.
The minimum value of /e/ for which the adjacency matrix
representation would require less space than the adjacency linked
lists representation is one more than the /e/ above, which would be
/(n^2  n)/4+1/.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '09
 VENUGOPAL

Click to edit the document details