Added the program to check Bipartite Graph #1095
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for PyVerse 💡
Requesting to submit a pull request to the PyVerse repository.
Issue Title
Please enter the title of the issue related to your pull request.
Bipartite graph
Info about the Related Issue
What's the goal of the project?
Given an adjacency list / matrix representing a graph with V vertices indexed from 0, the task is to determine whether the graph is bipartite or not. You can use queue data structure to check the graph.
Name
Please mention your name.
Shuvojit Samanta
GitHub ID
Please mention your GitHub ID.
shuvojitss
Email ID
Please mention your email ID for further communication.
shuvojitsamanta15@gmail.com
Identify Yourself
Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC, SWOC).
GSSOC
Closes
Enter the issue number that will be closed through this PR.
Closes: #1078
Describe the Add-ons or Changes You've Made
Give a clear description of what you have added or modified.
Algorithm Steps to Check if a Graph is Bipartite:
Initialize Colors: Create an array
color
of size V (number of vertices) and initialize all elements to -1, indicating that no vertices have been colored.BFS for Each Component: For each vertex
start
from 0 to V-1:color[start]
is not -1, continue to the next vertex (this vertex is already colored).Start BFS:
start
vertex into it.start
with color 0.Process the Queue:
Completion: If all vertices are processed without conflicts, return true (the graph is bipartite).
Type of Change
Select the type of change:
How Has This Been Tested?
Describe how your changes have been tested.
I have tested it in all python editors and its working. I am providing a sample input output to describe it.
Sample Input:
Enter the number of vertices: 5
Enter the adjacency matrix:
0 1 1 0 0
1 0 0 1 0
1 0 0 1 0
0 1 1 0 1
0 0 0 1 0
Sample Output:
The graph is bipartite.
Explainataion of Sample:
Diagrammatic representation of the above input:
To determine if the graph is bipartite, we can attempt to color the vertices using two colors. The following coloring can be used:
Since we can assign colors such that no two adjacent vertices share the same color, the graph is confirmed to be bipartite.
Checklist
Please confirm the following: