graph theory reminder - YaccConstructor/QuickGraph GitHub Wiki
This is intended to refresh these notions for those who have not played with them recently. It is also intended to specify the standards names used in the project and the library itself. As much as possible, QuickGraph naming convention follows the standard of graph theory naming.
Let us start by redefining the basic concepts of directed graphs, vertices and edges. All these definitions are illustrated in the figure above.
- A directed graph
G=(VxE)
consists of a finite setV=V(G)
of vertices and a finite multi-setE
contained inVxV = {(u,v)| u,v in V}
of edges that are ordered pair of vertices whereu
is called the source vertex andv
the target vertex.
Tip:
-
TVertex and TEdge are generic parameters in QuickGraph. The
TEdge
parameter has an additional constraint that it has to implementIEdge<TVertex>
public interface IEdge<TVertex>
{
TVertex Source {get;}
TVertex Target { get;}
}
public interface ISomeGraphAlgorithm<TVertex,TEdge>
where Edge : IEdge<TVertex>
{…}
- If
e=(u,v)
, thene
is an out-edge ofu
and an in-edge ofv
.in-degree(v)
denotes the number of incoming edges ofv
andout-degree(u)
, the number of outgoing edges ofu
. The degree ofu
is the sum of its in-degree and out-degree. - If a graph allows multiple edges from the same
u
,v
vertex pair, it is called a multi-graph. Such edges are called parallel edges. - A path from
u
tov
is a sequence of edgese1,e2,...,en
such thate1
source isu
,en
target isv
and each edge in the sequence is an out-edge of it’s predecessor. - A cycle is a path where the beginning vertex is equal to the end vertex.
- A directed acyclic graph (DAG) is a directed graph with no cycle.
- A weighted directed graph
G:(VxExW)
is a directed graph with an additional relation that associate each edge to a weight:e -> w(e)
(for example, the distance). - An adjacency graph is a data structure to represent a directed graph where the out-edges of any vertex can be accessed in amortized constant time.
- A bidirectional graph is a data structure to represent directed graph where both the out-edges and the in-edges of any vertex can be accessed in amortized constant time.
- QuickGraph also provides data structures for UndirectedGraph.
tip:
The adjacency graph is implemented as a dictionary of Vertex to a collection of out-edges. When using a bidirectional graph, two dictionaries (one for in-edges, one for out-edges) have to be used, which doubles the required memory. Such data structures are most efficient for sparse graphs.