Bipartite Graph
A graph of two disjoint sets
What is a bipartite graph?
A bipartite graph is a graph whose vertices can be partitioned into two sets, such that no two adjacent vertices belong to the same set.
A bipartite graph is a graph whose vertices can be partitioned into two sets, such that no two vertices in the same set are connected by an edge. In other words, a bipartite graph is a graph that does not contain any odd cycles.
A bipartite graph is a graph which can be divided into two disjoint sets

The adjacent nodes (direct neighbours) cannot have same colour
Properties of bipartite graph
Vertex Partition: A bipartite graph can be partitioned into two disjoint sets of vertices, say U and V, such that every edge in the graph connects a vertex from set U to a vertex from set V. This partition of vertices is called a bipartition.
No Edges within Sets: In a bipartite graph, there are no edges that connect vertices within the same set. In other words, all edges in the graph go from vertices in set U to vertices in set V, or vice versa.
Coloring: A bipartite graph can be colored using two colors, such that no two adjacent vertices have the same color. This is known as a proper vertex coloring.
Independent Sets: In a bipartite graph, the vertices in each set form an independent set, which means that there are no edges between vertices in the same set.
No Odd Cycles: A bipartite graph does not contain any odd-length cycles. All cycles in a bipartite graph have an even number of vertices.
Maximum Bipartite Matching: In a bipartite graph, the maximum matching (the largest possible set of mutually non-adjacent edges) can be found efficiently using algorithms such as the Hopcroft-Karp algorithm or the Ford-Fulkerson algorithm.
Algorithm
This type of problems come up in graphs. Depth First Search is used to solve the problem.
Create a list to keep track of colours
Iterate it through total number of nodes
In DFS, mark the initial node with colour
1Then visit its neighbouring nodes and toggle
1using a negative sign.If we encounter a node, which has same colour as colour it is being assigned, then graph is not bipartite
Code
Problems
Last updated