For example, in the undirected graph above, (4, 3, 1, 6) is a path.
This path is said to contain the vertices v
0
, v
1
, etc., as well as the
edges (v
0
, v
1
), (v
1
, v
2
), etc.
Vertex x is said to be reachable from vertex u if a path exists from u
to x.
A path is simple if it contains no vertex more than once.
A path is a cycle if it is a path from some vertex to that same vertex.
A cycle is simple if it contains no vertex more than once, except the
start (and end) vertex, which only appears as the first and last vertex
in the path.
These definitions extend similarly to directed graphs (e.g., (v
0
, v
1
),
(v
1
, v
2
), etc. must be arcs).
Graph Representation
The choice of representation of a graph is important, as different
representations have very different time and space costs.
The vertices are generally tracked by numbering them, so that one
can index them just by their number. Thus, the representations focus
on how to store the edges.
Edge List
The most obvious way to keep track of the edges is to keep a list of the
pairs of vertices representing the edges in the graph.
This representation is easy to code, fairly easy to debug, and fairly
space efficient. However, determining the edges incident to a given
vertex is expensive, as is determining if two vertices are adjacent.
Adding an edge is quick, but deleting one is difficult if its location in
the list is not known.