next up previous index
Next: Java implementation Up: Graph representations Previous: Adjacency matrix   Index


Adjacency lists

An alternative representation uses just the collection of arcs in the graph. It is convenient to subdivide these into classes of arcs originating from given nodes, and at this point we fix specifically on directed graphs.

Let us agree on some terminology. Consider the arc:


\begin{picture}(40,10)(-5,-5)
\put(0,0){\circle{10}}
\put(0,0){\makebox(0,0){$...
...0}}
\put(30,0){\makebox(0,0){$b$}}
\put(5,0){\vector(1,0){19.5}}
\end{picture}
which is directed from node $a$ to node $b$. We shall say that node $a$ is the tail of the arc and that node $b$ is the head of the arc. The terminology comes from thinking of the head and tail of the arrow. We shall also say that node $b$ is adjacent to node $a$ when there is an arc having $b$ as its head and $a$ as its tail.

We can now organise the arcs in a directed graph by listing, for each node in turn, the nodes which are adjacent to it. For the graph in Figure 12.2, this gives

$A \rightarrow \{B,E\}$
$B \rightarrow \{C\}$
$C \rightarrow \{E,F\}$
$D \rightarrow \{A\}$
$E \rightarrow \{B,D,F\}$
$F \rightarrow \{\}$
Note the empty list for $F$. The idea is to represent the graph as a collection of nodes, each of which carries with it its list of adjacent nodes.

Note in passing that the dual representation

$A \leftarrow \{D\}$
$B \leftarrow \{A,E\}$
$C \leftarrow \{B\}$
$D \leftarrow \{E\}$
$E \leftarrow \{A,C\}$
$F \leftarrow \{C,E\}$
where we list the nodes to which a given node is adjacent, would serve equally well. But it is more usual and more intuitive, especially when considering shortest path algorithms, to think in a ``forwards'' direction. For some purposes, however, it may be convenient to make simultaneous use of both representations.


next up previous index
Next: Java implementation Up: Graph representations Previous: Adjacency matrix   Index
Peter Williams 2005-06-07