Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

Adjacency Lists

One technique that is often used for a sparse graph, say tex2html_wrap_inline70549, uses tex2html_wrap_inline70975 linked lists--one for each vertex. The linked list for vertex tex2html_wrap_inline70679 contains the elements of tex2html_wrap_inline70979, the set of nodes adjacent to tex2html_wrap_inline70715. As a result, the lists are called adjacency lists .

Figure gif shows the adjacency lists for the directed graph tex2html_wrap_inline70643 of Figure gif and the directed graph tex2html_wrap_inline70797 of Figure gif. Notice that the total number of list elements used to represent a directed graph is tex2html_wrap_inline70987 but the number of lists elements used to represent an undirected graph is tex2html_wrap_inline70989. Therefore, the space required for the adjacency lists is tex2html_wrap_inline70991.

   figure49172
Figure: Adjacency lists.

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


next up previous index

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