Exercise 2: Choosing a Representation for a 200-Vertex Sparse Graph — Possible Solution ==================================================================================== GIVEN ------------------------------ V = 200 vertices, E = 190 edges. STEP 1: ADJACENCY MATRIX SPACE ------------------------------ V^2 = 200 x 200 = 40,000 cells STEP 2: ADJACENCY LIST SPACE ------------------------------ V + 2E = 200 + (2 x 190) = 200 + 380 = 580 entries STEP 3: THE RATIO ------------------------------ 40,000 / 580 ~= 69.0 The adjacency matrix would need roughly 69 times more space than the adjacency list for this graph. WHICH REPRESENTATION TO CHOOSE ------------------------------ With only 190 edges against a possible maximum of roughly 19,900 edges for 200 vertices (200 x 199 / 2), this graph is clearly sparse - each vertex connects, on average, to fewer than 2 other vertices out of 199 possible ones. Per this chapter's own sparse-vs-dense guidance, the adjacency list is the clear choice here: it uses dramatically less space (580 vs. 40,000 entries) AND is at least as fast for the neighbor-listing operations that traversal algorithms (Chapter 3 onward) rely on most heavily. There's no real advantage to the matrix's O(1) edge-lookup speed unless that specific operation is needed unusually often. WHY THIS WORKS AS AN ANSWER ------------------------------ Both space figures are computed directly from this chapter's own formulas, the ratio is stated explicitly, and the representation choice is justified by applying this chapter's own sparse-vs-dense reasoning to the actual numbers rather than picking one representation by default.