Graphs Lecture Notes
Graphs Lecture Notes
Graphs Lecture Notes
Graphs make it possible to reason about the relations between objects and how individual
connections between objects can give rise to larger structures.
A graph is a collection of objects (usually referred to as nodes or vertices) that can be
connected to one another. Specifically, any pair of nodes may be connected by an edge
(sometimes called an arc).
A computer network is an example of a graph. Vertices or nodes represent the computers and
edges represent the communication links between the computers.
A graph G = (V ,E) consists of V , a nonempty set of vertices (or nodes) and E, a set
of edges. Each edge has either one or two vertices associated with it, called its
endpoints. An edge is said to connect its endpoints.
Typically, anything can act as nodes in a graph: people, places, words, numbers, etc.
Since edges run between two nodes, we often represent edges as which pair of nodes they
connect.
GRAPHS
For example, consider the following graph, which represents friendships in a group of
people.
Amy Bob
Cathy Dean
Frank
Ethan
E = {}, {}
{}}
Notice that in the this case, our edges were represented as a set of unordered pairs,
because friendship is bidirectional – if person A is a friend of person B, then person B is
GRAPHS
An unordered pair is a set {a, b} of two elements a ≠ b.
An unordered pair represents two objects without specifying that one of these
objects is the “first” object and that one of these is the “second” object. For
example, the friendship between Amy and Bob might be represented as the
unordered pair { Amy, Bob }. Since sets are unordered collections of distinct
elements, this means that { Amy, Bob } = { Bob, Amy }.
An undirected graph is a graph where V is a set of nodes, which can be anything, and
E is a set of unordered pairs.
GRAPHS
Now consider Ethihad airline network where each airport is represented by a
vertex. We can model all the flights by the airline each day using a directed edge to
represent each flight, going from the vertex representing the departure airport to
the vertex representing the destination airport..
Harare JHB
Nairobi
Dubai Paris
A directed graph is an ordered pair where is a set of nodes, which can be anything,
and E is a set of edges, which are ordered pairs of nodes drawn from V.
Vertices and are said to be adjacent or neighbors if there is an edge In such a case,
and are called the endpoints of , and is said to connect and . Also, the edge is said to
be incident on each of its endpoints and .
The degree of a vertex in an undirected graph is the number of edges incident with it,
except that a loop at a vertex contributes twice to the degree of that vertex. The
degree of the vertex v is denoted by .
Handshaking Theorem : The sum of the degrees of the vertices of a graph G is equal
to twice the number of edges in G.
A vertex of degree zero is called an isolated vertex.
GRAPHS
Graph Properties
A path in a graph is a series of nodes where for any with , there is an edge from to
In other words, a path is a series of nodes such that any two consecutive nodes in the
sequence are adjacent.
The number of edges is called the length of the path. The length of the path is n-1.
Notice that this definition just says that a simple path cannot repeat any nodes. This
implicitly also means that the simple path cannot repeat any edges, since if that were
the case the path would have to repeat that edge's endpoints.
A cycle/circuit is a closed path of length 3 or more in which all vertices are distinct
except = . A cycle of length k is called a k-cycle.
A simple cycle is a cycle that does not contain any duplicate nodes (except for the very
GRAPHS
Example: Consider the graph G
Describe G formally, that is, find the set V (G) of vertices of G and the set E(G) of
edges of G.
V (G)={A,B,C,D,E}
E(G) = {{A,B}, {A,C}, {A,D}, {B,C}, {B,E}, {C,D}, {C,E}} – there are the 7 pair of vertices
Find the degree of each vertex.
The degree of a vertex is equal to the number of edges to which it belongs; e.g., deg(A) = 3
since A belongs to the three edges {A,B}, {A,C}, {A,D}. Similarly, deg(B) = 3, deg(C) = 4,
deg(D) = 2, deg(E) = 2
This proves the theorem which states that the sum of degrees is equal to 2 times the
number of edges. 3+3+4+2+2= 2*7 =14
GRAPHS
Find all simple paths from A to E;
A simple path from A to F is a path such that no vertex, and hence no edge, is
repeated.
Which of them are connected? If a graph is not connected, find its connected
components.
Only (1) and (3) are connected, (2) is disconnected; its connected components are
{A,D,E} and {B,C}. (4) is disconnected; its connected components are {A,B,E} and
{C,D}.
GRAPHS
Euler paths and circuits
Let G = (V,E) be a graph with no isolated vertices. An Euler path in G is a simple path
that transverses every edge of the graph exactly once. Analogously, an Euler circuit in
G is a simple circuit that transverses every edge of the graph exactly once.
Let G be a connected multigraph. Then G contains an Euler circuit if and only if G its
vertices have even degree.
Also, G contains an Euler path/trail from vertex a to vertex b () if and only if a and b
have odd degree, and all its other vertices have even degree.
GRAPHS
Hamilton circuits
A Hamilton circuit in a graph G is a circuit that contains each vertex of G once (except
for the starting and ending vertex, which occurs twice). A Hamilton path in G is a path
(not a circuit) that contains each vertex of G once.
Example:
Which of the graphs have a Hamiltonian circuit? If not, why not?
GRAPHS
Planar graphs
A graph is called a planar graph if there is some way to draw it in a 2D plane without
any of the edges crossing.
A graph is called the utility graph if there is no way to draw it in the plane without
edges crossing. For further explanation, you can view this video
https://youtu.be/VvCytJvd4H0
GRAPHS
Example
Draw a planar representation of the graph below.
Solution
A planar graph does not edges that cross.
GRAPHS
Graph Coloring
A coloring of a simple graph is the assignment of a color to each vertex of the graph
so that no two adjacent vertices are assigned the same color
The chromatic number of a graph is the least number of colors needed for a
coloring of this graph. The chromatic number of a graph G is denoted by χ(G).
GRAPHS
Welch and Powell Algorithm for Graph Coloring
Order the vertices of graph G according to decreasing degrees
Assign the first colour to the first vertex and then in sequential order, assign to
each vertex adjacent which is not adjacent to the previous vertex which was
assigned .
Repeat step 2 with a second colour and the subsequence of non-coloured vertices.
Repeat step 3 with a third colour and so on until all the vertices are coloured.
.
GRAPHS
Example
Find the chromatic number of the graph given below
The chromatic number of a graph is the least number of colours needed for graph
colouring.
Vertices according to a c b d e
decreasing degrees deg(a)=3 deg(c)=3 deg(b)=2 deg(d)=2 deg(e)=2
Colour c1 c1 c2 c2 c2
The χ(G)=2