II. GRAPH REPRESENTATIONS USING
COMPUTER SYSTEMS
In general, there are four ways to represent a
graph in a computer system: The incidence list
representation, the incidence matrix representation,
adjacency list representation, and the adjacency
matrix representation.
Incidence List - This representation uses an
array. Each element in the array corresponds with a
single edge. Each edge contains a list of size two
which corresponds to the endpoints of the edge.
This can also apply to directed graphs by ensuring
the first vertex be defined as the source or
destination while the second should be defined as
the opposite.
Incidence matrix - This representation uses a
matrix of M edges by N vertices. If the vertex is an
endpoint to the edge, a value of 1 is assigned to
their crossing, otherwise, a value of 0 is assigned.
This is a terrible waste of space as every column or
row represented by the edge can only have two
values of 1 while the rest are labelled 0.
These two representations are most useful when
information about edges is more desirable than
information about vertices.
Adjacency list - Much like the incidence list,
each node has a list of which nodes it is adjacent
to. This can sometimes result in "overkill" in an
undirected graph as vertex 3 may be in the list for
node 2, then node 2 must be in the list for node 3.
Either the programmer may choose to use the
unneeded space anyway, or he/she may choose to
list the adjacency once. This representation is
easier to find all the nodes which are connected to
a single node, since these are explicitly listed.
Adjacency matrix - there is an N by N matrix,
where N is the total number of vertices in the
graph. If there is an edge from some vertex x to
some vertex y, then the element Mx,y would be 1,
otherwise it would be 0. This makes it easier to
find sub graphs, and to reverse graphs if needed.
[6].
These two representations are most useful when
information about the vertices is more desirable
than information about the edges. Also these two
representations are also most popular since
information about the vertices is often more
desirable than edges in most applications. [7].