Lesson 7

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

LESSON 7: GRAPHS

PART I
The history of graph theory states it was introduced by the famous Swiss
mathematician named Leonhard Euler, to solve many mathematical problems by
constructing graphs based on given data or a set of points. The graphical
representation shows different types of data in the form of bar graphs, frequency tables, line
graphs, circle graphs, line plots, etc.

A graph is a pictorial representation of any data in an organised manner. The graph


shows the relationship between variable quantities. In a graph theory, the graph represents
the set of objects, that are related in some sense to each other. The objects are basically
mathematical concepts, expressed by vertices or nodes and the relation between the pair of
nodes, are expressed by edges.

Formally, a graph is denoted as a pair G(V, E).

Where V represents the finite set vertices and E represents the finite set edges.

Therefore, we can say a graph includes non-empty set of vertices V and set of edges
E.

Example: Suppose, a Graph G=(V,E), where

Vertices, V={a,b,c,d} 

Edges, E={{a,b},{a,c},{b,c},{c,d}}

The graphs are basically of two types, directed and undirected. It is best understood by the
figure given below. The arrow in the figure indicates the direction.
Directed Graph

In graph theory, a directed graph is a graph made up of a set of vertices connected by edges,
in which the edges have a direction associated with them.

Undirected Graph

The undirected graph is defined as a graph where the set of nodes are connected together, in
which all the edges are bidirectional. Sometimes, this type of graph is known as the
undirected network.

Other types of graphs

● Null Graph: A graph that does not have edges.


● Simple graph: A graph that is undirected and does not have any loops or multiple
edges.

● Multigraph: A graph with multiple edges between the same set of vertices. It has
loops formed. 

● Connected graph: A graph where any two vertices are connected by a path.

● Disconnected graph: A graph where any two vertices or nodes are disconnected by a
path.
● Cycle Graph: A graph that completes a cycle. 

● Complete Graph: When each pair of vertices are connected by an edge then such
graph is called a complete graph
● Planar graph: When no two edges of a graph intersect and are all the vertices and
edges are drawn in a single plane, then such a graph is called a planar graph

Graph Terminology
Adjacency: A vertex is said to be adjacent to another vertex if there is an edge connecting
them. Vertices 2 and 3 are not adjacent because there is no edge between them.

Path: A sequence of edges that allows you to go from vertex A to vertex B is called a path.
0-1, 1-2 and 0-2 are paths from vertex 0 to vertex 2.

Directed Graph: A graph in which an edge (u,v) doesn't necessarily mean that there is an
edge (v, u) as well. The edges in such a graph are represented by arrows to show the direction
of the edge.

Graph Representation
Graphs are commonly represented in two ways:

1. Adjacency Matrix

An adjacency matrix is a 2D array of V x V vertices. Each row and column represent a


vertex.

If the value of any element a[i][j] is 1, it represents that there is an edge connecting vertex i
and vertex j.

The adjacency matrix for the graph we created above is


Graph adjacency matrix
Since it is an undirected graph, for edge (0,2), we also need to mark edge (2,0); making the
adjacency matrix symmetric about the diagonal.

Edge lookup (checking if an edge exists between vertex A and vertex B) is extremely fast in
adjacency matrix representation but we have to reserve space for every possible link
between all vertices(V x V), so it requires more space.

2. Adjacency List

An adjacency list represents a graph as an array of linked lists.

The index of the array represents a vertex and each element in its linked list represents the
other vertices that form an edge with the vertex.

The adjacency list for the graph we made in the first example is as follows:

Adjacency list representation


An adjacency list is efficient in terms of storage because we only need to store the values for
the edges. For a graph with millions of vertices, this can mean a lot of saved space.

PART II
Graph Operations

The most common graph operations are:

Check if the element is present in the graph

Graph Traversal

Add elements (vertex, edges) to graph

Finding the path from one vertex to another

Isomorphism of Graphs
Graph Isomorphism is a phenomenon of existing the same graph in more than one forms.
Such graphs are called as Isomorphic graphs.

Graph Isomorphism Conditions-


 

For any two graphs to be isomorphic, following 4 conditions must be satisfied-

● Number of vertices in both the graphs must be same.


● Number of edges in both the graphs must be same.
● Degree sequence of both the graphs must be same.
● Same cycle vector
Example:

Connectivity
A graph is said to be connected if there is a path between every pair of vertex. From every
vertex to any other vertex, there should be some path to traverse. That is called the
connectivity of a graph. A graph with multiple disconnected vertices and edges is said to be
disconnected.

Example 1
In the following graph, it is possible to travel from one vertex to any other vertex. For
example, one can traverse from vertex 'a' to vertex 'e' using the path 'a-b-e'.

Example 2
In the following example, traversing from vertex 'a' to vertex 'f' is not possible because
there is no path between them directly or indirectly. Hence it is a disconnected graph.

Connectivity Types
Graph Connectivity can be classified broadly into two categories −
● Edge Connectivity
● Vertex Connectivity
Edge Connectivity
Let 'G' be a connected graph. The minimum number of edges whose removal makes 'G'
disconnected is called edge connectivity of G.

Notation − λ(G)

In other words, the number of edges in a smallest cut set of G is called the edge
connectivity of G.

If 'G' has a cut edge, then λ(G) is 1.

Example
Take a look at the following graph. By removing two minimum edges, the connected graph
becomes disconnected. Hence, its edge connectivity (λ(G)) is 2.

Here are the four ways to disconnect the graph by removing two edges −
Vertex Connectivity
Let 'G' be a connected graph. The minimum number of vertices whose removal makes 'G'
either disconnected or reduces 'G' in to a trivial graph is called its vertex connectivity.

Notation − K(G)

Example
In the above graph, removing the vertices 'e' and 'i' makes the graph disconnected.

For graph G1, either {c} or {e} is a vertex cut. Hence, K(G1) = 1

For graph G2, {c} or {e} is a vertex cut. Hence, K(G2) = 1

Shortest Path Problems

In data structures,

● Shortest path problem is a problem of finding the shortest path(s) between vertices
of a given graph.
● Shortest path between two vertices is a path that has the least cost as compared to all
other existing paths.

Shortest Path Algorithms-


 

Shortest path algorithms are a family of algorithms used for solving the shortest path
problem.

Applications-
Shortest path algorithms have a wide range of applications such as in-

● Google Maps
● Road Networks
● Logistics Research
 

Types of Shortest Path Problem-


 
Various types of shortest path problem are-

1. Single-pair shortest path problem


2. Single-source shortest path problem
3. Single-destination shortest path problem
4. All pairs shortest path problem
 

Single-Pair Shortest Path Problem-


 

● It is a shortest path problem where the shortest path between a given pair of
vertices is computed.
● A* Search Algorithm is a famous algorithm used for solving single-pair shortest
path problem.
 
Single-Source Shortest Path Problem-
 

● It is a shortest path problem where the shortest path from a given source vertex to
all other remaining vertices is computed.
● Dijkstra’s Algorithm and Bellman Ford Algorithm are the famous algorithms used
for solving single-source shortest path problem.

Single-Destination Shortest Path Problem-


 

● It is a shortest path problem where the shortest path from all the vertices to a
single destination vertex is computed.
● By reversing the direction of each edge in the graph, this problem reduces to
single-source shortest path problem.
● Dijkstra’s Algorithm is a famous algorithm adapted for solving single-destination
shortest path problem.
 

All Pairs Shortest Path Problem-


 

● It is a shortest path problem where the shortest path between every pair of vertices
is computed.
● Floyd-Warshall Algorithm and Johnson’s Algorithm are the famous algorithms
used for solving All pairs shortest path problem.
 
REFERENCES:
https://byjus.com/maths/graph-theory/#:~:text=Graph%20Theory%2C%20in%20discrete%2
0mathematics%2C%20is%20the%20study,used%20to%20create%20a%20pairwise%20relatio
nship%20between%20objects.

https://www.programiz.com/dsa/graph#:~:text=Graph%20Terminology%201%20Adjacency
%3A%20A%20vertex%20is%20said,is%20an%20edge%20%28v%2C%20u%29%20as%20well.
%20

https://www.gatevidyalay.com/graph-isomorphism/

https://www.gatevidyalay.com/tag/null-graph-definition/

https://www.tutorialspoint.com/connectivity-of-graph

https://www.gatevidyalay.com/shortest-path-algorithms-shortest-path-problems/

You might also like