{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

set11_sol

# set11_sol - CS112 Spring 2011 Problem Set 11 Graphs I 1...

This preview shows pages 1–2. Sign up to view the full content.

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.

{[ snackBarMessage ]}

### Page1 / 3

set11_sol - CS112 Spring 2011 Problem Set 11 Graphs I 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online