A graph is a pair
Properties:
- The order of a graph is the number of vertices (written as
). - The size of a graph is the number of edges (written as
). - An edge
is usually written as (or ). If is an edge of , then and are said to be adjacent in . - A vertex
is incident with an edge e if . - The set of neighbors of a vertex
is denoted by . - The degree of a vertex
is the number of edges incident to (loops are counted twice).
Let
- If
, then and are disjoint. - If
and , then is a subgraph of , written as . - If
is a subgraph of and either or , then is a proper subgraph of . - If
is a subgraph of and , then is a spanning subgraph of . - If
and all the edges such that and are also in , then is an induced subgraph of .
Movement
A walk in a graph is a sequence of movements beginning at
where
- A trail is a walk in which no edge is traversed more than once.
- A path is a walk in which no vertex is visited more than once (note that every path is also a trail).
- A circuit is a closed trail of length 3 or more (it begins and ends at the same vertex but repeats no edges).
- A cycle is a circuit that repeats no vertices (think of it as a closed path). A
-cycle is a cycle of length (e.g., a -cycle is a triangle).
Properties related to path lengths:
- The distance between two vertices
and is the smallest length of any path in , denoted by . - The diameter is the greatest distance between any two vertices of a connected graph.
Some additional properties related to connectivity in a graph:
- If a graph
contains a path, then and are said to be connected. - A graph
is connected if every two vertices of are connected. - A connected subgraph of
that is not a proper subgraph of any other connected subgraph of is a component of . - The number of components of a graph is denoted by
. A graph is connected if .
Common classes of graphs
Complete graph
A graph
- A complete graph of order
is denoted by . For complete graphs, has the maximum possible size for a graph of vertices. - The number of pairs of vertices in
is .
Sparse graph
A graph
Dense graph
A graph
Complement graph
The complement
- If
is disconnected, is connected.
Bipartite graph
A graph
- A nontrivial graph
is bipartite if it doesn’t contain odd-length cycles. - A complete bipartite graph is a bipartite graph where each vertex of
is adjacent to every vertex of . It’s denoted as . - A star is a complete bipartite graph of the form
or .
-partite graph
A graph
Biconnected graph
A biconnected graph
Multigraphs
A multigraph
Pseudographs
A pseudograph
Weighted graph
Let
Digraphs
A directed graph
- If
is a directed edge, then is adjacent to , and is adjacent from .
Degrees
The degree of a vertex
- The minimum degree of a graph
is the minimum degree among all the vertices of , denoted as . - The maximum degree of a graph
is the maximum degree among all the vertices of , denoted as . - A vertex of degree
is called an isolated vertex. - A vertex of degree
is called an end vertex (or leaf). - A vertex of even degree is called an even vertex.
- A vertex of odd degree is called an odd vertex.
- Two vertices of
that have the same degree are called regular vertices. - If a graph
has the same degree for all its vertices, it’s called an r-regular graph.
In a graph
First theorem of graph theory
If
is a graph of size , then
When summing the degrees of
Degrees in a bipartite graph
Suppose that
Corollary: every graph has an even number of odd vertices
Proof: Let
The number
Degree sequences
If the degrees of a graph
Suppose we’re given a finite sequence
- The degree of any vertex can never be greater than
, where is the order of the graph. - A graph has an even number of odd vertices.
There’s a theorem called the Havel-Hakimi theorem, which solves the problem above in polynomial time.
A non-increasing sequence
, where , can form a graph only if the sequence
According to this theorem, we can create a new sequence based on the one above that is also a graph. We can apply the theorem recursively to test if the original sequence forms a graph.
bool graph_from_sequence(vector<int> °rees) {
int sum = 0;
int size = degrees.size();
for (int i = 0; i < size; i += 1) {
sum += degrees[i];
if (degrees[i] >= size || degrees[i] < 0) {
// a vertice can have a maximum degree of n - 1
// also none of the degrees can be negative
return false;
}
}
if (sum == 0) {
// trivial case
return true;
}
sort(degrees.begin(), degrees.end());
// removing d_1
int max_degree = degrees.back();
degrees.pop_back();
size -= 1;
// subtracting 1 from the next d_1 elements
for (int i = 0; i < max_degree; i += 1) {
degrees[size - 1 - i] -= 1;
}
return graph_from_sequence(degrees);
}
Graphs and matrices
A graph can also be described using a matrix. The adjacency matrix of a graph
The incidence matrix of a graph
Useful observations
Let
Proof: Assume for a positive integer
The first element of this sum is the number of walks of length