Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Adjacency Lists

One technique that is often used for a sparse graph, say tex2html_wrap_inline69997, uses tex2html_wrap_inline70423 linked lists--one for each vertex. The linked list for vertex tex2html_wrap_inline70127 contains the elements of tex2html_wrap_inline70427, the set of nodes adjacent to tex2html_wrap_inline70163. As a result, the lists are called adjacency lists .

Figure gif shows the adjacency lists for the directed graph tex2html_wrap_inline70091 of Figure gif and the directed graph tex2html_wrap_inline70245 of Figure gif. Notice that the total number of list elements used to represent a directed graph is tex2html_wrap_inline70435 but the number of lists elements used to represent an undirected graph is tex2html_wrap_inline70437. Therefore, the space required for the adjacency lists is tex2html_wrap_inline70439.

   figure48743
Figure: Adjacency lists.

By definition, a sparse graph has tex2html_wrap_inline70381. Hence the space required to represent a sparse graph using adjacency lists is tex2html_wrap_inline70447. Clearly this is asymptotically better than using adjacency matrices which require tex2html_wrap_inline70371 space.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.