A graph is a pair G=(V,E), it consists of a finite set V of objects called the vertices (or nodes or points) and a set E of 2-elements subsets of V called edges, another way to denote the vertex set/edges of a graph G is using V(G) (the vertex set of G) and E(G) (the edge set of G)

G=(V,E)V={1,2,3,4,5,6,7}E={{1,5},{5,7},{2,3},{2,4},{3,4}}

Properties

  • the order of a graph is the number of vertices (written as G)
  • the size of a graph is the number of edges (written as G)
  • an edge u,v is usually written as uv (or vu), if uv is an edge of G then u and v are said to be adjacent in G
  • a vertex v is incident with an edge e if ve
  • the set of neighbors of a vertex v is denoted by N(v)
  • the degree of a vertex v is the number of edges incident to v (loops are counted twice)

Let G=(V,E) and G=(V,E) be two graphs, we set GG=(VV,EE) and GG=(VV,EE)

  • if GG= then G and G are disjoint
  • if VV and EE then G is a subgraph of G written as GG
  • if G is a subgraph of G and either VV or EE then G is a proper subgraph of G
  • if G is a subgraph of G and V=V then G is an spanning subgraph of G
  • if VV and all the edges e=uvE so that uV and vV and also eE then G is an induced graph of G

Movement

A walk in a graph is a sequence of movements beginning at u moving to a neighbor of u and then to a neighbor of that vertex and so on until we stop at a vertex v

W=(u=v0,v1,,v=vk)

where k0, note that there are no restrictions on the vertices visited so a vertex can be visited more than once also there are no restrictions on the edges traversed so an edge can be traversed more than once, every two consecutive vertices in W are distinct since they are adjacent, if u=v then we said that the walk is closed otherwise it’s open

  • 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 repeat no edges)
  • a cycle is a circuit that repeat no vertex (think of it as a closed path), a k-cycle is a cycle of length k (e.g. a 3-cycle is a triangle)

Properties related with path lengths

  • the distance between two vertices u and v is the smallest length of any uv path in G denoted by d(u,v)
  • the diameter is the greatest distance between any two vertices of a connected graph

Some additional properties related with connectivity in a graph

  • if a graph G contains a uv path then u and v are said to be connected
  • a graph G is connected if every two vertices of G are connected
  • a connected subgraph of G that is not a proper subgraph of any other connected subgraph of G is a component of G
  • the number of components of a graph is denoted by k(G), then a graph is connected if k(G)=1

Common classes of graphs

Complete graph

A graph G is complete if every two distinct vertices of G are adjacent

  • a complete graph of order n is denoted by Kn, for complete graphs Kn has the maximum possible size for a graph of n vertices
  • the number of pairs of vertices in Kn is (n2)=n(n1)2

Sparse graph

A graph G of order n and size m is a sparse graph if m is close to the minimal number of edges i.e. when mn, in this case adjacency lists are prefered since they require constant space for every edge, a tree is a good example of a sparse graph

Dense graph

A graph G of order n and size m is a dense graph if m is close to the maximal number of edges i.e. when mn2, in this case an adjacency matrix is prefered, a complete graph is a dense graph

Complement graph

The complement G¯ of a graph G is a graph whose vertex is the set V(G) and such that for each pair u,v of distinct vertices, uvE(G¯) and uvE(G), that means that the complement of a complete graph is a graph of order n and size 0

  • if G is diconnected, G¯ is connected

Bipartite graph

A graph G is bipartite when the set V(G) can be partitioned into two subsets U and W called partite sets such that every edge of G joins a vertex of U and a vertex of W

  • a nontrivial graph G is bipartite if it doesn’t contain odd length cycles
  • a complete bipartite graph is a bipartite graph where each vertex of U is adjacent to every vertex of W, it’s denoted as KU,W
  • a star is a complete bipartite graph where K1,W or KU,1

k-partite graph

A graph G is k-partite when the set V(G) can be partitioned into k subsets V1,V2,,Vk such that every edge of G joins a vertex of U and a vertex of W

Biconnected graph

A biconnected graph G is a connected and “nonseparable” graph meaning that if any vertex (and its incident edges) is removed the graph will remain connected, therefore a biconnected graph doesn’t have cut-vertices

Multigraphs

A multigraph M is a graph where every two vertices of M are joined by a finite number of edges, when two or more edges join the same pair of distinct vertices those edges are called parallel edges

Pseudographs

A pseudograph P is a graph where an edge is allowed to join a vertex with itself, such an edge is called a loop

Weighted graph

Let G be a multigraph, let’s replace all the parallel edges joining a particular pair of vertices by a single edge which is assigned a positive integer representing the number of parallel edges, this new representation is refered as a weighted graph

Digraphs

A directed graph D is a finite nonempty set V of vertices and a set E of ordered pairs of distinct vertices, the elements of the set E are called directed edges or arcs, arcs are represented with arrows instead of plain line segments

  • if uv is a directed edge then u is adjacent to v and v is adjacent from u

Degrees

The degree of a vertex v is the number of edges incident with v denoted by deg(v) (with loops counted twice)

  • the minimum degree of a graph G is the minimum degree among all the vertices of G denoted as δ(G)
  • the maximum degree of a graph G is the maximum degree among all the vertices of G denoted as Δ(G)
  • a vertex of degree 0 is called an isolated vertex
  • a vertex of degree 1 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 G that have the same degree are called regular vertices
  • if a graph G has the same degree r for all its vertices it’s called an r-regular graph

In a graph G of n vertices the following equality relation holds

0δ(G)deg(v)Δ(G)n1

First theorem of graph theory

if G is a graph of size m then

vV(G)deg(v)=2m

When summing the degrees of G each edge is counted twice

Degrees in a bipartite graph

Suppose that G is a bipartite graph with two partite sets U and W, then

uV(U)deg(u)=wV(W)deg(w)=m

Corollary: every graph has an even number of odd vertices

Proof: Let G be a graph of size m, dividing V(G) into two subsets Veven which consists of even vertices and Vodd which consists of odd vertices then by the first theorem of graph theory

vVeven(G)deg(v)+vVodd(G)deg(v)=2m

the number vVeven(G)deg(v) is even since it’s a sum of even numbers thus vVodd(G)deg(v) is also even and it can be even only if the number of odd vertices is even (a sum of two odd numbers gives an even number)

Degree sequences

A deIf the degrees of a graph G are listed in a sequence s then s is called a sequence degree, e.g.

s:4,3,2,2,2,1,1,1,0

Suppose we’re given a finite sequence s of nonnegative integers, a well known problem is if we can build a graph out of this sequence, to solve this problem let’s talk about some facts

  • the degree of any vertice can never be greater than n1 where n is the order of the graph
  • a graph has an even number of odd vertices

There’s a theorem called Havel-Hakimi which solves the problem above in polynomial time

A non-increasing sequence s:d1,d2,,dn where d11 can form a graph only if the sequence

s1:d21,d31,,dd1+11,dd1+2,,dn
forms a graph

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

s1:4,3,2,2,2,1,1,1,0s2:2,1,1,1,1,1,1,0removing d1=4 and subtracting 1 from the following 4 elementss3:1,1,1,1,0removing d1=2 and subtracting 1 from the following 2 elementss4:1,1,0removing d1=1 and subtracting 1 from the following elements5:0removing d1=1 and subtracting 1 from the following element
bool graph_from_sequence(vector<int> &degrees) {
  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 G of order n and size m is a n×n matrix A=[aij] $where

aij={1if vivjG0otherwise

The incidence matrix of a graph G of order n and size m is a n×m matrix B=[bij] where

bij={1if vi is incident with ej0otherwise
G=(V,E)V={0,1,2,3,4}E={{0,1},{0,2},{0,3},{1,3},{2,3},{3,4}}
A=[0111010010100101110100010]B=[111000100100010010001111000001]

Useful observations

Let Ak be the adjacency matrix of a graph G raised to the k-th power, the entry aij(k) is the number of distinct vivj walks of length k in G

Proof: assume for a positive integer k that the number of vivj walks of length k is given by aij(k) in the matrix Ak, then Ak+1=Ak×A, now a cell aij(k+1) is the dot product of row i of Ak and column j of A

aij(k+1)=t=1nait(k)atj

The first element of this sum is the number of walks of length k from vi to v1 (stored in ai1(k)) times the number of walks of length 1 from v1 to vj (stored in a1j), the second element follows the same formula but using v2 as the vertex used to “join” the walks of length k and 1