The Wayback Machine - https://web.archive.org/web/20250210163813/https://www.geeksforgeeks.org/mathematics-graph-theory-basics/
Open In App

Mathematics | Graph Theory Basics – Set 2

Last Updated : 27 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Graph theory is a basic branch of discrete mathematics that mainly focuses on the relationship between objects. These objects are called vertices and these vertices are joined by edges. Graphs are common in computer science, network analysis, and many other everyday uses because they provide a good representation of connection, relationship, and process. Here we shall discuss graph theory, different types of graphs, terms used in the subject, and how to solve sample problems.

Graph Theory Basics

A graph is a structure amounting to a set of objects in which some pairs of the objects are in some sense “related”. The objects of the graph correspond to vertices and the relations between them correspond to edges. A graph is depicted diagrammatically as a set of dots depicting vertices connected by lines or curves depicting edges. 
Formally, 

“A graph [Tex]G = (V, E) [/Tex]consists of [Tex]V [/Tex], a non-empty set of vertices (or nodes), and [Tex]E [/Tex], a set of edges. Each edge has either one or two vertices associated with it, called its endpoints.” 

Types of Graph

There are several types of graphs distinguished on the basis of edges, their direction, their weight etc. 

1. Simple graph: A graph in which each edge connects two different vertices and where no two edges connect the same pair of vertices is called a simple graph. For example, Consider the following graph – 
 


The above graph is a simple graph, since no vertex has a self-loop and no two vertices have more than one edge connecting them. 
The edges are denoted by the vertices that they connect- [Tex]\{A,B\} [/Tex]is the edge connecting vertices [Tex]A [/Tex]and [Tex]B [/Tex]. 

2. Multigraph: A graph in which multiple edges may connect the same pair of vertices is called a multigraph. 
Since there can be multiple edges between the same pair of vertices, the multiplicity of edge tells the number of edges between two vertices. 
 


The above graph is a multigraph since there are multiple edges between [Tex]B [/Tex]and [Tex]C [/Tex]. The multiplicity of the edge [Tex]\{B, C\} [/Tex]is 2. 

In some graphs, unlike the one’s shown above, the edges are directed. This means that the relation between the objects is one-way only and not two-way. The direction of the edges may be important in some applications. 

Based on whether the edges are directed or not we can have directed graphs and undirected graphs. This property can be extended to simple graphs and multigraphs to get simple directed or undirected simple graphs and directed or undirected multigraphs. 

Basic Graph Terminology

In the above discussion some terms regarding graphs have already been explained such as vertices, edges, directed and undirected edges etc. There are more terms which describe properties of vertices and edges. 

  • Adjacency: In a graph [Tex]G [/Tex]two vertices [Tex]u [/Tex]and [Tex]v [/Tex]are said to be adjacent if they are the endpoints of an edge. The edge [Tex]\{u, v\} – e [/Tex]is said to be incident with the vertices. 
    In case the edge is directed, [Tex]u [/Tex]is said to be adjacent to [Tex]v [/Tex]and [Tex]v [/Tex]is said to be adjacent from [Tex]u [/Tex]. Here, [Tex]u [/Tex]is said to be the initial vertex and [Tex]v [/Tex]is said to the terminal vertex. 
     
  • Degree: The degree of a vertex is the number of edges incident with it, except the self-loop which contributes twice to the degree of the vertex. Degree of a vertex [Tex]u [/Tex]is denoted as [Tex]deg(u) [/Tex]. 
    In case of directed graphs, the degree is further classified as in-degree and out-degree. The in-degree of a vertex is the number of edges with the given vertex as the terminal vertex. The out-degree of a vertex is the number of edges with the given vertex as the initial vertex. In-degree is denoted as [Tex]deg^-(u) [/Tex]and out-degree is denoted as [Tex]deg^+(u) [/Tex]. 
    For example in the directed graph shown above depicting flights between cities, the in-degree of the vertex “Delhi” is 3 and its out-degree is also 3.  

Note: If a vertex has zero degree, it is called isolated. If the degree is one then it’s called pendant. 

  • Handshaking Theorem: What would one get if the degrees of all the vertices of a graph are added. In case of an undirected graph, each edge contributes twice, once for its initial vertex and second for its terminal vertex. So the sum of degrees is equal to twice the number of edges. This fact is stated in the Handshaking Theorem. 
     

Let [Tex]G = (V, E)[/Tex] be an undirected graph with [Tex]e[/Tex] edges. Then

[Tex]2e = \sum_{u\in V} deg(u)[/Tex]

In case G is a directed graph,

[Tex]\sum_{u\in V} deg^-(u) = \sum_{u\in V} deg^+(u) = |E|[/Tex]


The handshaking theorem, for undirected graphs, has an interesting result – 
 

An undirected graph has an even number of vertices of odd degree.


Proof : Let [Tex]V_{1} [/Tex]and [Tex]V_{2} [/Tex]be the sets of vertices of even and odd degrees respectively. 
We know by the handshaking theorem that, 
[Tex]2e = \sum_{u\in V} deg(u) [/Tex]
So, 
[Tex]2e = \sum_{u\in V} deg(u) = \sum_{u\in V_{1}} deg(u) + \sum_{u\in V_{2}} deg(u) [/Tex]
The sum of degrees of vertices with even degrees is even. The LHS is also even, which means that the sum of degrees of vertices with odd degrees must be even. 
Thus, the number of vertices with odd degree is even. 

Some Special Simple Graphs

1. Complete Graphs: A simple graph of [Tex]n [/Tex]vertices having exactly one edge between each pair of vertices is called a complete graph. A complete graph of [Tex]n [/Tex]vertices is denoted by [Tex]K_{n} [/Tex]. Total number of edges are n*(n-1)/2 with n vertices in complete graph. 

 

Complete Graphs, K2, K3.. to K7



2. Cycles: Cycles are simple graphs with vertices [Tex]n \geq 3 [/Tex]and edges [Tex]\{1, 2\},\: \{2, 3\}…\: \{n-1, n\}\: and\: \{n, 1\} [/Tex]. Cycle with [Tex]n [/Tex]vertices is denoted as [Tex]C_{n} [/Tex]. Total number of edges are n with n vertices in cycle graph. 

 



3. Wheels: A wheel is just like a cycle, with one additional vertex which is connected to every other vertex. Wheels of [Tex]n [/Tex]vertices with 1 addition vertex are denoted by [Tex]W_{n} [/Tex]. Total number of edges are 2*(n-1) with n vertices in wheel graph. 
 

Wheels- W4, W5, W6 and W7



4. Hypercube: The Hypercube or n-cube is a graph with [Tex]2^n [/Tex]vertices each represented by a n-bit string. The vertices which differ by at most 1-bit are connected by edges. A hypercube of [Tex]2^n [/Tex]vertices is denoted by [Tex]Q_{n} [/Tex]. Total number of edges are n*[Tex]2^{n-1} [/Tex]with [Tex]2^n [/Tex]vertices in cube graph. 

 



5. Bipartite Graphs: A simple graph [Tex]G [/Tex]is said to be bipartite if its vertex set [Tex]V [/Tex]can be divided into two disjoint sets such that every edge in [Tex]G [/Tex]has its initial vertex in the first set and the terminal vertex in the second set. Total number of edges are (n*m) with (n+m) vertices in bipartite graph. 

 

Bipartite Graph example




Theorem: A simple graph is bipartite if and only if it is possible to assign one of two 
different colors to each vertex of the graph so that no two adjacent are assigned the 
same color. 

A bipartite graph with [Tex]m [/Tex]and [Tex]n [/Tex]vertices in its two disjoint subsets is said to be complete if there is an edge from every vertex in the first set to every vertex in the second set, for a total of [Tex]mn [/Tex]edges. A complete bipartite graph with [Tex]m [/Tex]vertices in the first set and [Tex]n [/Tex]vertices in the second set is denoted as [Tex]K_{m,n} [/Tex]. 

 

Examples

  1. Simple Graph: Let us take the example of graph that has vertices say {A, B, C, D} and the edges labelled as (A, B), (B, C), (C, D), and (D, A). This is connected and simple graph because there are no one pair of vertices that is connected by more than one edges or self loops.
  2. Multigraph: For instance if there are two arrows connecting A and B and one arrow between B and C, then this diagram is a multigraph.
  3. Directed Graph: In the case of a directed graph there could be a directed arc from A to B and another from B to C.
  4. Complete Bipartite Graph: In one set there should be 3 vertices namely A, B and C; while in the other set there should be only two vertices, namely X and Y. Another graph is complete bipartite graph, in this graph, each vertex of {A, B, C} is connected with each vertex of {X, Y}.

Sample Problems

Problem 1: Find the degree of each vertex in a simple undirected graph with vertices {A, B, C, D} and edges {(A, B), (B, C), (C, D)}.

The Degree between nodes A & B= 1 The Degree between nodes B & C= 2 The Degree between nodes C & D= 2 The Degree between nodes D & A= 1.

Problem 2: Check whether the graph with vertices {A, B, C, D} and edges {(A, B), (B, C), (C, A)} is bipartite.

The delivered graph turns out to be a cycle of 3 vertices thus can’t be bipartite. Therefore we can concluded that it is not a bipartite graph.

Problem 3: Verify the handshaking theorem for a graph with 4 vertices and 3 edges.

Degrees of all vertex = where where outside radius + outside radius + outside radius + outside radius = 6. Applying the handshaking theorem here gives that 2e = 6, thus e = 3 Which is the same number of edges we have.

Problem 4: Calculate the number of edges in a complete graph with 5 vertices.

That of a complete graph is given by 5(5-1)/2 = 10.

Problem 5: How many edges are in a wheel graph with 6 vertices (including the central vertex)?

Edges = 2*(n-1) = 2 * (6-1) = 10.

Practice Problems

Problem 1: Find the number of edges in a complete bipartite graph K3,4.

Problem 2: Determine whether a graph with vertices {A, B, C, D} and edges {(A, B), (B, C), (C, D), (D, A), (A, C)} is a cycle graph.

Problem 3: Verify the handshaking theorem for a graph with 6 edges and 4 vertices.

Problem 4: How many vertices does a hypercube graph Q3 have?

Problem 5: Is a graph with 4 vertices and no edges bipartite?

Problem 6: What is the degree of each vertex in a complete graph with 4 vertices?

Problem 7: Can a graph with 5 vertices be a simple graph if it has 8 edges?

Problem 8: How many edges does a cycle graph with 8 vertices have?

Problem 9: Find the out-degree of a vertex in a directed graph with 3 outgoing edges.

Problem 10: Determine whether the graph with edges {(A, B), (B, C), (C, D), (D, A), (A, D)} is a simple graph.

Summary

Graph theory provides a framework for modeling relationships and connections in various fields. The types of graphs and key properties such as adjacency, degrees, and the handshaking theorem are crucial in understanding the structure and behavior of graphs. By solving problems in graph theory, we gain insights into the complexity and patterns in data and networks.

FAQs on Graph Theory Basics

What is the degree of a vertex?

The degree of a vertex is the number of edges connected to it.

What is a simple graph?

A simple graph is a graph in which each edge connects two distinct vertices, with no multiple edges or loops.

What is a bipartite graph?

A bipartite graph is a graph in which the vertices can be divided into two disjoint sets such that each edge connects a vertex in one set to a vertex in the other.

What is a complete graph?

A complete graph is a graph in which every pair of distinct vertices is connected by a unique edge.

What is the handshaking theorem?

The handshaking theorem states that the sum of the degrees of all vertices in an undirected graph is equal to twice the number of edges.

GATE CS Corner Questions

Practicing the following questions will help you test your knowledge. All questions have been asked in GATE in previous years or in GATE Mock Tests. It is highly recommended that you practice them. 

1. GATE CS 2013, Question 25 
2. GATE CS 2014 Set-1, Question 61 
3. GATE CS 2006, Question 71 
4. GATE CS 2002, Question 25 
5. GATE CS 2004, Question 37 
6. GATE CS 2014 Set-2, Question 13 
 



Next Article

Similar Reads

three90RightbarBannerImg