2 Graphs, in general

A graph consists of vertices and edges among the vertices. Let us use V represent a set of vertices. An edge is a tuple (n,m), in which both n and m are elements of V . Note that edges cannot be represented as a function because a vertex corresponds to many other vertices. The set of all edge tuples is represented by V . Thus, a graph can be represented as G = (V,E). It only makes sense that (x,y) E : x,y V . In other words, E cannot contain an edge such that at least one of its vertices is not in V .

In terms of representation, each vertex is associated with any number of other vertices. Consequently each vertex has a container associated with it to represent vertices that are reachable directly from the vertex.

In this case, a container can be a linked list, an array or a tree. However, it is usually best to use a container that is efficient at lookup operations. A sorted array or a tree (AVL tree) are efficient containers.