Is Bipartite Graph Problem

You are provided with an undirected graph having 'N' nodes numbered from 0 to 'N-1'. There is a list 'EDGES' of size 'M', which contains all the edges of this graph. The task is to determine if the graph is Bipartite.

Input:
The input starts with an integer 'T' which represents the number of test cases. Then follow 'T' test cases.
Each test case begins with two integers 'N' and 'M', indicating the number of nodes and edges in the graph.
Subsequently, there are 'M' lines, each containing two integers 'EDGES[i][0]' and 'EDGES[i][1]', denoting an undirected edge between the nodes 'EDGES[i][0]' and 'EDGES[i][1]'.
Output:
For each test case, output 'Yes' if the graph is Bipartite, otherwise output 'No'.
Each result is printed on a new line for each test case.

Example:

Input:
N = 4, M = 5
EDGES = [[0, 1], [0, 3], [1, 2]]

Output:
Yes
Explanation:

The graph can be partitioned into two sets:
setA = [0, 2]
setB = [1, 3]
Each edge connects a node from setA to a node from setB, making it a bipartite graph.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 500
  • 1 <= M <= (N * (N - 1)) / 2

Note: The graph has no self-edges or parallel edges and may not be connected. A bipartite graph can be divided into two sets where each edge connects a node from one set to a node from the other set.

AnswerBot
4mo

Determine if a given undirected graph is Bipartite or not.

  • Check if the graph can be divided into two sets such that each edge connects nodes from different sets.

  • Use BFS or DFS to color nodes alternati...read more

Help your peers!
Select
Add answer anonymously...

MindTickle Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Is Bipartite Graph Problem You are provided with an undirected graph having 'N' ...read more
A Software Developer Intern was asked Q. Can you design an online Chess Board Game?
A Software Developer Intern was asked Q. Topological Sort Problem Statement You have a directed acyclic graph (DAG). The ...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Is Bipartite Graph Problem You are provided with an undirected graph having 'N' ...read more
A Software Developer Intern was asked Q2. Can you design an online Chess Board Game?
A Software Developer Intern was asked Q3. Topological Sort Problem Statement You have a directed acyclic graph (DAG). The ...read more
MindTickle Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits