Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Adjacency Lists

One technique that is often used for a sparse graph, say tex2html_wrap_inline71355, uses tex2html_wrap_inline71781 linked lists--one for each vertex. The linked list for vertex tex2html_wrap_inline71485 contains the elements of tex2html_wrap_inline71785, the set of nodes adjacent to tex2html_wrap_inline71521. As a result, the lists are called adjacency lists .

Figure gif shows the adjacency lists for the directed graph tex2html_wrap_inline71449 of Figure gif and the directed graph tex2html_wrap_inline71603 of Figure gif. Notice that the total number of list elements used to represent a directed graph is tex2html_wrap_inline71793 but the number of lists elements used to represent an undirected graph is tex2html_wrap_inline71795. Therefore, the space required for the adjacency lists is tex2html_wrap_inline71797.

   figure49405
Figure: Adjacency Lists

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


next up previous contents index

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