Logo 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_inline70093, uses tex2html_wrap_inline70519 linked lists--one for each vertex. The linked list for vertex tex2html_wrap_inline70223 contains the elements of tex2html_wrap_inline70523, the set of nodes adjacent to tex2html_wrap_inline70259. As a result, the lists are called adjacency lists .

Figure gif shows the adjacency lists for the directed graph tex2html_wrap_inline70187 of Figure gif and the directed graph tex2html_wrap_inline70341 of Figure gif. Notice that the total number of list elements used to represent a directed graph is tex2html_wrap_inline70531 but the number of lists elements used to represent an undirected graph is tex2html_wrap_inline70533. Therefore, the space required for the adjacency lists is tex2html_wrap_inline70535.

   figure48823
Figure: Adjacency lists.

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


next up previous contents index

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