1 Graph Preliminaries
1 Graph Preliminaries
Graph
• A (linear) graph G = (V, E) consists of a set of objects V= {v1,v2,…..}
called vertices, and another set E = {e1,e2,…..}, whose elements are
called edges, such that each edges ek is identified with an unordered
pair (vi,vj) of vertices.
• The vertices vi,vj associated with edges ek are called end vertices of ek.
• The edge having the same vertex as both its end vertices is called a
self-loop or simply a loop.
• More than one edges associated with same end vertices are called
parallel edges.
• A graph that has neither self-loops nor parallel edges is called a simple
graph.
• A graph that has self-loops and/or parallel edges is called a general
graph.
• A graph is also called a linear complex, 1-complex or a one-
dimensional complex.
• A vertex is also referred to as a node, a junction, a point, 0-cell, or an
0-simplex.
• An edge is also referred to as a branch, a line, an element, a 1-cell, an
arc, and a 1-simplex.
Applications of graph
• Konigsberg Bridge Problem
• Utilities Problem
• Electrical Network Problem
• Seating Problem: Nine members of a
club meet each day for lunch at a round
table. They decide to sit such that every
member has different neighbours at
each lunch. How many days can this
arrangement last?
• Given n people, possible number of
such arrangements is (n-1)/2 if n is odd,
and (n-2)/2 if n is even.
• Solution: 1234567891, 1352749681,
1573928461, 1795836241
• A graph with a finite number of vertices as well as a finite number of
edges is called a finite graph, otherwise, it is an infinite graph.
Incidence and Degree
• When a vertex vi is an end vertex of some edge ej, vi and ej are said to
be incident with each other.
• Two nonparallel edges are said to be adjacent if they are incident on a
common vertex.
• Two vertices are said to be adjacent if they are the end vertices of the
same edge.
• The number of edges incident on a vertex vi, with self-loop counted
twice, is called the degree, d(vi), of vertex vi. The degree of a vertex is
sometimes also referred to as its valency.
• Handshaking Theorem: The sum of the degree of all vertices in G is
twice the number of edges in G.
• THEOREM 1-1: The number of vertices of odd degree in a graph is
always even.
𝑛
https://www.geeksforgeeks.org/graph-and-its-representations/
• Incidence Matrix
https://en.wikipedia.org/wiki/Incidence_matrix
When to use which graph representation?
• Graph representation (v = number of vertices and e = number of
edges)
• Adjacency Matrix : Time and Space Complexity O(v2)
• Adjacency List: Time complexity = O(e) and Space Complexity = O(v+e)
• Check edge presence:
• Adjacency Matrix: Time = constant
• Adjacency List: O(v)
• Adjacency matrix is used when the graph is dense.
• Adjacency list is used when the graph is sparse (worse case time
complexity = O(v2)
Time and Space Complexity of Adjacency Matrix and List | Baeldung on Computer Science
Maze representation using graph
• A maze can be represented and solved by using a
graph.
• The pathways can be represented by edges, and
the junctions and endpoints of the paths can be
represented by vertices.
• One way to solve a maze is to construct a graph
that represents the maze and find a path that leads
from the starting vertex to the ending vertex of
that graph.
https://www.chegg.com/homework-help/maze-represented-solved-using-graph-pathways-represented-edg-chapter-
6.2-problem-46p-solution-9780495388838-exc
• The first step in creating a graphical
representation of the maze is to draw
all pathways, as shown in (a).
• Next, identify all vertices at
junctions (intersections) and
endpoints as shown in (b).
• After labeling all vertices, as shown
in (c), we see that the path that leads
from vertex A, at the entrance, to
vertex J, at the exit, is AGIJ.
• This path is the solution to the maze,
as illustrated in (d).
https://www.chegg.com/homework-help/maze-represented-solved-using-graph-pathways-represented-edg-chapter-
6.2-problem-46p-solution-9780495388838-exc
Exercise: Represent this maze by means of a graph such that a vertex denotes
either a corridor or a dead end. An edge represents a possible path between two
vertices. What is the length of a path from the entrance to the center of the maze.
Solving Decanting Problem using graph
• You are given three vessels A, B, and C of capacities 8,5, and 3
gallons respectively. A is filled while B and C are empty. Divide the
liquid in A into two equal quantities.
• How many vertices are there in the graph which represents the possible states
of jugs?
• List out the possible states based on the conditions of the jugs.
Equilateral Triangle
(8,0,0)
Solution 1:
(8,0,0), (5,0,3), (5,3,0), (2,3,3), (2,5,1),
(7,0,1), (7,1,0), (4,1,3), (4,4,0)
Solution 2:
(8,0,0), (3,5,0), (3,2,3), (6,2,0), (6,0,2),
(1,5,2), (1,4,3), (4,4,0)
(0,8,0) (0,0,8)
Amount in 5L jug
https://en.wikipedia.org/wiki/Water_pouring_puzzle
Isomorphic graphs
• Two graphs G and G’ are isomorphic to each other if there is a one-to-one
correspondence between their vertices and between their edges such that
the incidence relationship is preserved.
• Such isomorphism shows identical behaviour in terms of geometric
properties. Two graphs are thought of as equivalent if they have identical
behaviour in terms of graph-theoretic properties.
• Two isomorphic graphs must have:
• The same number of vertices.
• The same number of edges.
• An equal number of vertices with a given degree.
• However these conditions are necessary but not sufficient. For eg.
Subgraphs
• A graph g is said to be subgraph of a graph G if all the vertices and all
the edges of g are in G.
Observations
• Every graph is its own subgraph.
• A subgraph of a subgraph of G is a subgraph of G.
• A single vertex in a graph G is a subgraph of G.
• A single edge in G, together with its end vertices, is also a subgraph of
G.
• Edge – disjoint subgraphs: Two subgraphs g1 and g2 of a graph G are
said to be edge disjoint if g1 and g2 do not have any edge in common.
• Vertex – disjoint subgraphs: Two subgraphs g1 and g2 of a graph G
are said to be vertex disjoint if g1 and g2 do not have any vertex in
common.
A puzzle with multicolored Cubes
We are given four cubes. The six
faces of cube are colored with
blue, green, red or white. Is it
possible to stack the cubes one on
top of another to form a column
such that no color appears twice
on any of the four sides of the
column?
The solution of this problem exists if their
exists two edge- disjoint subgraphs of
graph G containing all vertices & one
edge of each number. Also degree of
each vertex must be 2.
Walks, Paths, and Circuits
A walk is defined as a finite alternating sequence of vertices and edges, beginning
and ending with vertices, such that each edge is incident with the vertices
preceding and following it. No edge appears (is covered or traversed) more than
once in a walk. A vertex may appear more than once.
A walk is also referred to as an edge train or a chain.
v1 a v2 b v3 c v3 d v4 e v2 f v5 is a walk.
True/False: The set of vertices and edges constituting a given walk in a graph G
is a subgraph of G.
• Vertices with which a walk begins and ends are called its terminal
vertices. A walk which begins and ends at the same vertex is called a
closed walk. A walk which does not begin and end at the same vertex
is called an open walk.
• An open walk in which no vertex appears more than once is called a
path or simple path or an elementary path.
• A path does not interest itself.
• The number of edges in a path is called the length of a path.
• True/False: A self-loop can be included in a walk but not in path.
• The terminal vertices of a path are of degree one, and the rest of the
vertices (intermediate vertices) are of degree two.
• A closed walk in which no vertex (except the initial and the final
vertex) appears more than once is called a circuit. A circuit is a closed,
non-intersecting walk.
• A circuit is also called a cycle, elementary cycle, circular path, and
polygon.
• Every vertex in a circuit is of degree two.
• True/False: Every self-loop is a circuit, but not every circuit is a self-
loop.
Example: Walk, path and circuit
Connected Graph
• A null graph with more than one vertex is disconnected.
• A disconnected graph consists of two or more connected graphs. Each of
these connected subgraphs is called a component.
• Theorem 2-1: A graph G is disconnected if and only if its vertex set V
can be partitioned into two nonempty, disjoint sets V1 and V2 such that
there exists no edge in G whose one end vertex is in subset V1 and the
other in subset V2.
• Theorem 2-2: If a graph has exactly two vertices of odd degree, there
must be a path joining these two vertices.
• Theorem 2-3: A simple graph with n vertices and k components can
have at most (n-k)(n-k+1)/2 edge.
Euler Graph
• If some closed walk in a graph G contains all the edges of the graph, then the walk
is called the Euler line and the graph is Euler graph.
• True/False: Euler graph (assumption: no isolated vertices in a graph) is always
connected.
• Theorem 2-4: A given connected graph G is an Euler graph if and only if all
vertices of G are of even degree.
• Theorem 2-5: In a connected graph G with exactly 2k odd vertices, there exist k
edge-disjoint subgraphs such that they together contain all edges of G and that
each is a unicursal graph.
• An open walk that includes (or traces) all edges of a graph without retracing any
edge is called a unicursal line or open Euler line. A connected graph that has
a unicursal line is called a unicursal graph.
• Theorem 2-6: A connected graph G in an Euler graph if and only if it can be
decomposed into circuits.
• What property must a vertex v in a Euler graph have such that an Euler
line is always obtained when one follows any walk from vertex v
according to the single rule that whenever one arrives at a vertex one
shall select any edge (which has not been previously traversed)?
• Theorem 2-7: An Euler graph G is arbitrarily traceable from vertex v
in G if and only if every circuit in G contain v.
Operations on Graphs
• Union: Union of two graphs G1 = (V1,E1) and G2 = (V2,E2) is another
graph G3 = (V3,E3) whose vertex set V3 = V1 ∪ V2 and the edge set E3
= E1 ∪ E2.
• Intersection: Intersection of two graphs G1 = (V1,E1) and G2 = (V2,E2)
is another graph G3 = (V3,E3) whose vertex set V3 = V1 ∩ V2 and the
edge set E3 = E1 ∩ E2.
• Ring sum: The ring sum (G1 ⊕ 𝐺2) of two graphs G1 = (V1,E1) and G2
= (V2,E2) is a graph G3(V3,E3) whose vertex set V3 = V1 ∪ V2 and
edges that are either in G1 or G2, but not both.
All the these operations are commutative.
• If G1 and G2 are edge disjoint, then G1 ∩ G2 is a null graph, and G1 ⊕
𝐺2 = G1 ∪ G2.
• If G1 and G2 are vertex disjoint, then G1 ∩ G2 is empty.
• For any graph G, G1 ∩ G2 = G1 ∪ G2 = G and G1 ⊕ 𝐺2 = a null graph.
• If g is a subgraph if G, then G ⊕ g = G – g, whenever g ⊆ G.
• Decomposition: A graph G is said to have been decomposed into two
subgraphs, g1 and g2 if g1 ∪ g2 = G and g1 ∩ g2 = a null graph.
• In decomposition, isolated vertices are disregarded.
• A graph containing m edges {e1,e2,e3,……em} can be decomposed in
2m-1 – 1 different ways into pairs of subgraphs g1,g2.
• True/False: A graph can not be decomposed into more than two
subgraphs?
• Deletion: If vi is a vertex in graph G, then G – vi denotes a subgraph of
G obtained by deleting vi from G. Such vertex deletion always implies
the deletion of all edges incident on that vertex. If ej is an edge in G,
then G-ej is a subgraph of G obtained by deleting ej from G. Such edge
deletion does not imply deletion of its end vertices, i.e. G – ej = G ⊕
ej.
Time Complexity of Adjacency Matrix and
List
• Removing an edge
• Adjacency Matrix: O(1)
• Adjacency List: O(v)
• Removing a vertex
• Adjacency Matrix: O(v)
• Adjacency List: O(v2)
• Fusion: A pair of vertices a, b in a graph are said to be fused ( merged
or identified) if the two vertices are replaced by a single new vertex
such that every edge that was incident on either a or b or both is
incident on the new vertex.
• The fusion of two vertices does not alter the number of edges, but it
reduces the number of vertices by one.
• Complement: For a graph G = (V, E), the complement of G is the
graph G’ with vertex set V and edge set En-E, where En is the set of
edges of the complete graph with V vertices.
Which of the following graphs are isomorphic?
Spanning Subgraphs
Hamiltonian Paths and Circuits
• Hamiltonian circuit in a connected graph is defined as a closed walk
that traverses every vertex of G exactly once except the starting vertex.
A circuit in a connected graph G is said to be Hamiltonian if it
includes every vertex of G. Hence a Hamiltonian circuit in a graph of
n vertices consists of exactly n edges.
• Hamiltonian path in a graph G traverses every vertex of G. The length
of a Hamiltonian path of a graph with n vertices is n-1.
• What is a necessary and sufficient condition for a connected graph G
to have a Hamiltonian circuit?
• Complete Graph is a simple graph in which there exists an edge
between every pair of vertices. Complete graph is also known as
universal graph or a clique.
• Number of Hamiltonian Circuits in a Graph: A given graph may
contain more than one Hamiltonian circuit.
• True/False: If a graph contains more than one Hamiltonian circuits,
than all such circuits are edge-disjoint.
• Theorem 2-8: In a complete graph with n vertices there are (n-1)/2
edge-disjoint Hamiltonian circuits, if n is an odd number ≥ 3.
• This theorem enables us to solve the problem of the seating
arrangement at around table.
Traveling-SalesMan Problem
• A salesman is required to visit a number of cities during a trip. Given
the distances between the cities, in what order should he travel so as to
visit every city precisely once and return home with the minimum
mileage travelled?
• Weighted graph
• The number of non-edge disjoint Hamiltonian circuits in a complete graph of n
vertices can be shown to be (n-1)! / 2. Why?
List all the different paths between vertices 5
and 6.
• Group the listed paths into sets
of edge disjoint paths. Check
whether two edge disjoint paths
form a circuit.
• You are given a 10-piece domino set whose tiles have the following
set of dots: (1,2), (1,3),(1,4), (1,5), (2,3), (2,4), (2,5), (3,4), (3,5), (4,5).
Discuss the possibilities of arranging the tiles in a connected series
such that one number on a tile always touches the same number of its
neighbour. (Hint: Use a five-vertex complete graph and see if it is an
Euler graph.)
• Prove that complete graph with n vertices contains n(n-1)/2 edges.
Graph Theoretic Model for LAN
Graphic Sequence
Build a graph theoretical model of the LAN problems as mentioned below:
• In a college campus, there are seven blocks, Computer Center (C), Library
(L), Academic (AC), Administrative (AD), Health Center (H), Guest House
(G), Security (S).
• The problem is to design two LANs satisfying certain conditions:
• LAN 1
• Two of the blocks are connected to exactly five of the blocks.
• Two of the blocks are connected to three of the blocks.
• Three of the blocks are connected to two of the blocks.
• LAN 2
• Four of the blocks are connected to five of the blocks.
• Three of the blocks are connected to two of the blocks.
Degree Sequence
• Definition. If G is a graph on n vertices v1; v2; : : : ; vn with degrees
d1; d2; : : : ; dn respectively, then the n-tuple (d1; d2; : : : ; dn) is
called the degree sequence of G.
• Graph with its degree sequence is: