Graph Theory
Introduction
A graph is represented as a non-empty set of vertices (nodes) and a set of edges (arrows) .
A directed edge is represented as an ordered pair of nodes, referred to as endpoints.
A undirected (two-way) edge is represented as a set of two nodes. is the head (initial) and is the tail (end) of the edge.
Type | Description |
---|---|
Multigraphs | Graphs with multiple edges between the same pair of nodes, but no loops |
Pseudographs | Multigraphs with loops |
Digraphs | Graphs with directed edges |
Mixed graphs | Graphs with both directed and undirected edges |
Simple | Undirected graphs with no loops and no multiple edges |
Examples
Nodes connected with one another are neighbours.
The neighbourhood of a node is the set of all nodes that are directly connected to .
The degree of a node can be identified in one of the following ways:
- Visually the number of lines drawn from
- The occurance of in the items of
- , where is the set of neighbours and is the set of loops that contain
This is a direct consequence of the fact that each edge contributes 2 to the sum of degrees, as each edge must have two endpoints.
Proof: Even number of nodes of odd degree
An undirect graph has an even number of nodes that have an odd degree.
Let be the set of nodes with odd degree, and
- As each node in has an even degree, the sum of degrees of all nodes in is even.
- As the LHS is even, the sum of degrees of all nodes in must also be even.
Example application of theorem
"9 people greet each other by shaking hands. Is it possible that each person shook hands with exacty 7 other people?"
Model as , where is the set of people and is the set of handshakes. . By the handshaking theorem, .
As both sides must be integers of either odd or even parity, the equation is impossible to satisfy.
Directed graphs
The following applies in the context of directed graphs.
The in-degree of a node is the number of edges that point to .
The out-degree of a node is the number of edges that point away from .
The degree of a node is the sum of its in-degree and out-degree.
This is a direct consequence of the fact that each edge contributes 1 to the sum of in-degrees and out-degrees, as each edge must have one head and one tail.
Special graphs
is a graph that has all nodes connected to each other.
A graph for which there is a pair of nodes that are not connected is called an incomplete graph.
is a cycle that has an additional node connected to all nodes in the cycle. (So there are nodes in total.)
A bipartite graph is a graph that can be divided into two sets of nodes, called a bipartition , such that no two nodes in the same set are connected.
A complete bipartite graph is a bipartite graph with nodes in one set and nodes in the other set, and all nodes in one set are connected to all nodes in the other set.
Matchings
A matching is a set of edges such that all nodes are distinct in definition.
A perfect matching is a matching that covers all nodes in the graph.
A maximum matching is a matching that has the largest number of edges.
Example
For graph with , a possible matching can be . For this graph, the maximum and perfect matching is , as this is the maximum number of edges that can be selected without sharing nodes, and all nodes are covered.
For a bipartite graph with bipartition , there exists a perfect matching iff for all . ( is the set of neighbours of )
Example application
"Suppose a standard deck of cards is dealth out into 13 stacks of 4 cards each. (There are 13 denomintation of 4 suit each, from Ace to King.) Show that it is possible to select exactly 1 card from each stack, such that 13 cards are of one of each denomination."
Model the problem as a bipartite graph , where is the set of denominations, and is the set of stacks of 4.
We can assign the cards of stacks by making edges between 4 denominations and the stack of 4 cards. This ensures that for all , as each denomination is connected to 4 stacks of cards.
In this scenario, the selection of 1 card from each stack, such that all denominations are selected, is equivalent to the existence of perfect matching in the bipartite graph.
Assume the contradiction that there is no perfect matching. Then, by Hall's Marriage Theorem, there exists such that .
This is a contradiction, as there are 13 denominations and 4 stacks of cards, so for all . Therefore, there exists a perfect matching in the bipartite graph.
Connectivity
A subgraph of a graph is a graph such that and . A proper subgraph .
You can think of subgraphs as a graph that is produced by removing nodes and edges from the original graph.
A induced subgraph is a graph such that and .
You can think of induced subgraphs as a subgraph that is produced by strictly removing nodes from the original graph and only the edges that are connected to the removed nodes.
Remove an edge with it's endpoints and , and merge the nodes to a new node . The new graph is called a contraction of the original graph.
Example
The contraction of edge is , where and .
A path is a sequence of edges, , such that for all . The length of the path is .
The condition for directed graphs is that instead.
Or for simple graphs, such that for all .
A circuit is a path that starts and ends at the same node, and has at least 2 nodes.
Paths and circuits can be classified as simple if they do not contain the same edge more than once.
Example
Consider the above simple graph:
- is a simple path of length 3
- is a non-simple circuit of length 2
- is a non-simple path of length 4
- is a simple circuit of length 3
A graph is connected if there is a path between every pair of distinct nodes, else it is disconnected.
For a directed graph, a graph is strongly connected if there is a path between every pair of distinct nodes in both directions, else it is weakly connected.
A connected component is one of the maximal connected subgraphs of a disconnected graph, or just the whole graph if it is connected.
For a directed graph, a strongly connected component is one of the maximal strongly connected subgraphs of a disconnected graph, or just the whole graph if it is strongly connected.
Example
Consider above as a singular graph. The graph has two connected components: and . The graph is disconnected as there is no path between and .
For the two graphs above, the graph on the left is weakly connected as there is a path between every pair of distinct nodes in one direction, but not in the other direction. (e.g. no path from )
The graph on the right is strongly connected as there is a path between every pair of distinct nodes in both directions.
For the weakly connected graph, the strongly connected components are and .
A cut node (articulation point) is a node whose removal increases the number of connected components in the graph.
A cut edge (bridge) is an edge whose removal increases the number of connected components in the graph.
Example
- Articulation point is , as removing it will disconnect the graph into 3 components.
- is a bridge, as removing it will disconnect the graph into 2 components.
The node connectivity of a graph is the minimum number of nodes that must be removed to disconnect the graph.
The edge connectivity of a graph is the minimum number of edges that must be removed to disconnect the graph.
For disconnected graphs, or graphs with , .
Proof
- , as deleting all neighbors of a node will disconnect the graph to a new component .
- , as deleting all edges of a node will disconnect the graph to a new component .
- , as deleting a bridge will disconnect the graph to a new component, and deleting a cut node will disconnect the graph to a new component.
Represent the graph as an adjacency matrix , where is the number of edges between node and node .
The number of paths of length between nodes and is given by the entry of the matrix .
Example
The number of paths of length between nodes and is given by the entry of the matrix :
So there are two paths of length between nodes and .
Euler paths
An Euler path / circuit is a simple path / circuit that contains every edge in .
A connected undirected multigraph with has an Euler circuit iff all nodes have even degree.
Proof
- Necessary condition:
- If a graph has an Euler circuit, then it must be possible to traverse every edge exactly once and return to the starting point.
- This means that every time you enter a node, you must also leave it.
- Therefore, the degree of each node must be even.
- Sufficient condition: Prove by contradiction:
- Base case: Let . A connected graph can have . is a loop with , and is a circuit with .
- Inductive step: Assume true for some . For , as the graph is connected, there exists a simple circuit. There are two cases then:
- The circuit is the Euler circuit.
- The circuit is not the Euler circuit. Remove the paths and exclusive nodes in this circuit. The remaining components by induction are Euler circuits.
- Hence, you can build an Euler circuit by travelling through the components while tracing the original circuit.
A connected multigraph with has an Euler path but not an Euler circuit iff exactly 2 nodes have odd degree.
Proof
We can prove this from both sides (equivalence):
- Direction 1: Euler path but not Euler circuit two nodes have odd degree
- If a graph has an Euler path, then it must be possible to traverse every edge exactly once
- This means that every time you enter a node, you must also leave it, except for the start and end nodes, which you only traverse once.
- Therefore, the degree of each node must be even, except for the start and end nodes, which must have odd degree.
- Hence, there are exactly 2 nodes with odd degree.
- If a graph has 2 nodes with odd degree, then it must be possible to traverse every edge exactly once
- Direction 2: Two nodes have odd degree Euler path but not Euler circuit
- Suppose has exactly two vertices that have odd degree, and others having even degree.
- If we add a edge between the two odd degree vertices, then all vertices will have even degree.
- Hence, the graph will have an Euler circuit.
- If we remove the edge, then the two vertices will have odd degree again.
- Hence, the graph will have an Euler path but not an Euler circuit.
Hamiltonian paths
A Hamiltonian path / circuit is a simple path / circuit that passes through all node in exactly once.
If is a simple graph with and for all nonadjacent pair of nodes , then has a Hamiltonian circuit:
Proof
Assume there exists that satisfies the condition, but does not have a Hamiltonian circuit.
Let be formed by adding edges to (keeping the same), that it will be a Hamiltonian circuit, if we add one more edge to .
Let be any nodes that satisfy .
The edges in must form a Hamiltonian path . Hence, adding the edge to will create a Hamiltonian circuit. ()
Observation: .
-
This is because if has a connection to a node preceeding a node which is connected to , then the circuit will be made: .
The basic restriction (definition of simple graphs) can be extended to be , as can only connect to nodes that do not preceed any nodes that have connections to .
Hence, , which is a contradiction to the original condition.
Graph coloring and chromatic number
Coloring of a simple graph is the assignment of colors to each node so that no two adjacent nodes have the same color.
The chromatic number of a graph is the smallest number of colors needed to color it, denoted by .
For special graphs:
- has chromatic number
- has chromatic number 2 if is even, and 3 if is odd
- has chromatic number
Note the following properties:
- as each node can be assigned a different color
- Only edgeless graphs have
- as there must be at least one edge between two nodes of different colors
- , where is number of nodes in largest complete subgraph (clique) of
A graph is planar if it can be drawn on a plane without any edges crossing, else non-planar. Such drawing is called a planar representation of the graph.
Example
For example, for , only the right representation is planar.
Two graphs are homeomorphic if they can be transformed into each other by a series of edge contractions.
A graph is non-planar if and only if it contains a subgraph that is a homeomorphic to or .
General steps to prove planarity / non-planarity:
- Identify if we are comparing with or . Notice , and respectively. You can only produce a subgraph by removing e/v.
- Do edge contractions and attempt to produce or .
- Identify if the graph is or by coloring. Recall and .
Example
First notice that all nodes have degree 3, so we will attempt to produce . , and has . Therefore, we have to remove 2 nodes, but keep the degree of the nodes. We can:
- Perform edge contractions on and
We can check if the resulting graph is by coloring:
This verifies that the resulting graph is , and hence the original graph is non-planar.