The Wayback Machine - https://web.archive.org/web/20240607003717/https://www.geeksforgeeks.org/what-is-bipartite-graph/
Open In App

What is Bipartite Graph

Last Updated : 01 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

A bipartite graph is a graph in which the vertices can be divided into two disjoint sets, such that no two vertices within the same set are adjacent. In other words, it is a graph in which every edge connects a vertex of one set to a vertex of the other set.

An alternate definition: Formally, a graph G = (V, E) is bipartite if and only if its vertex set V can be partitioned into two non-empty subsets X and Y, such that every edge in E has one endpoint in X and the other endpoint in Y. This partition of vertices is also known as bi-partition.

Bipartite Graph

Bipartite Graph

Note: In the above image nodes of the same colour belong to the same set.

Characteristics of Bipartite Graph

The characteristics of a bipartite graph are as follows:

  • Vertices can be divided into two disjoint sets: A bipartite graph can be partitioned into two sets of vertices, with no edges between vertices within each set.
  • Every edge connects vertices in different sets: Every edge in a bipartite graph connects a vertex from one set to a vertex from the other set.
  • No odd-length cycles: A bipartite graph cannot contain any odd-length cycles, as this would require vertices from the same set to be connected by an edge.
  • Maximum degree is bounded by the size of the smaller set: The maximum degree of a vertex in a bipartite graph is equal to the size of the smaller set.
  • Coloring with two colors: A bipartite graph can be colored with two colors,, such that no adjacent vertices have the same color.

How to identify Bipartite Graph?

To identify whether a given graph is bipartite, you can use the following algorithm:

  1. Choose any vertex in the graph and assign it to one of the two sets, say X.
  2. Assign all of its neighbors to the other set, say Y.
  3. For each vertex in set Y, assign its neighbors to set X, and for each vertex in set X, assign its neighbors to set Y.
  4. Repeat step 3 until all vertices have been assigned to a set.
  5. Check if any two adjacent vertices are in the same set. If yes, then the graph is not bipartite. Otherwise, it is bipartite.

To learn more about “How to identify”, refer to this article.

Application of Bipartite Graph

Bipartite graphs have many applications in different fields, including:

  • Matching problems: Bipartite graphs are commonly used to model matching problems, such as matching job seekers with job vacancies or assigning students to project supervisors. The bipartite structure allows for a natural way to match vertices from one set to vertices in the other set.
  • Social networks: Bipartite graphs, where the nodes in one set represent users and the nodes in the other set reflect interests, groups, or communities, can be used to simulate social networks. The bipartite form makes it simple to analyse the connections between users and interests.
  • Web Search engine: The query and click-through data of a search engine can be defined using a bipartite graph, where the two sets of vertices represent queries and web pages.

What else can you read?


Similar Reads

Check if a given graph is Bipartite using DFS
Given a connected graph, check if the graph is bipartite or not. A bipartite graph is possible if the graph coloring is possible using two colors such that vertices in a set are colored with the same color. Note that it is possible to color a cycle graph with an even cycle using two colors. For example, see the following graph. It is not possible t
9 min read
Maximum number of edges in Bipartite graph
Given an integer N which represents the number of Vertices. The Task is to find the maximum number of edges possible in a Bipartite graph of N vertices.Bipartite Graph: A Bipartite graph is one which is having 2 sets of vertices.The set are such that the vertices in the same set will never share an edge between them. Examples: Input: N = 10 Output:
3 min read
Divide given Graph into Bipartite sets
Given a graph G(V, E), divide it into two sets such that no two vertices in a set are connected directly. If not possible print "Not Possible". Examples: Input: V = 7, E = 6, Edge = {{1, 2}, {2, 3}, {3, 4}, {3, 6}, {5, 6}, {6, 7}}Output: 7 5 1 3 6 2 4 Explanation: node {7, 5, 1, 3} are not connected directly and nodes {6, 2, 4} are not connected di
10 min read
Maximize number of edges added to convert given Tree into a Bipartite Graph
Given a tree of N nodes, the task is to find the maximum number of edges that can be added to the tree such that it becomes a bipartite graph. Note: Self loop or multiple edges are not allowed but cycles are permitted. Examples: Input: N = 4, Edges = {{1, 2}, {2, 3}, {1, 4}} 1 / \ 2 4 / 3Output: 1Explanation: An edge between nodes 3 and 4 can be ad
13 min read
Check whether a given graph is Bipartite or not
A Bipartite Graph is a graph whose vertices can be divided into two independent sets, U and V such that every edge (u, v) either connects a vertex from U to V or a vertex from V to U. In other words, for every edge (u, v), either u belongs to U and v to V, or u belongs to V and v to U. We can also say that there is no edge that connects vertices of
34 min read
Maximum number of edges to be added to a tree so that it stays a Bipartite graph
A tree is always a Bipartite Graph as we can always break into two disjoint sets with alternate levels. In other words we always color it with two colors such that alternate levels have same color. The task is to compute the maximum no. of edges that can be added to the tree so that it remains Bipartite Graph. Examples: Input : Tree edges as vertex
6 min read
Minimum Bipartite Groups
Given Adjacency List representation of graph of N vertices from 1 to N, the task is to count the minimum bipartite groups of the given graph. Examples: Input: N = 5 Below is the given graph with number of nodes is 5: Output: 3 Explanation: Possible groups satisfying the Bipartite property: [2, 5], [1, 3], [4] Below is the number of bipartite groups
8 min read
Maximum Bipartite Matching
A matching in a Bipartite Graph is a set of the edges chosen in such a way that no two edges share an endpoint. A maximum matching is a matching of maximum size (maximum number of edges). In a maximum matching, if any edge is added to it, it is no longer a matching. There can be more than one maximum matchings for a given Bipartite Graph. Why do we
16 min read
Check Whether a Linked List is Bipartite or Not
Given a linked list representing a graph with directed edges, check whether the given linked list is a Bipartite graph or not. Examples: Input: 1->2->3->4->NULLOutput: PossibleExplanation: It is possible to color the above linked list using 2 colors. We can color node 1 and 3 with one color and node 2 and 4 with other color. Input: 1-
8 min read
Bipartite Graphs in Python
Bipartite graphs are a special type of graph where the nodes can be divided into two distinct sets, with no edges connecting nodes within the same set. Every edge connects a node from the first set to a node in the second set. What is a Bipartite Graph?A graph where the nodes can be divided into two sets, V1 and V2, such that no edges connect nodes
5 min read
Practice Tags :