37. Graphs-3 (cycle undir)
# Cycle detection in undirected graphs-
- if during traversal, we find a visited non-parent node as a neighbour of a node,
then cycle is present
- in dfs, take: int par, as another argument
- in bfs, modify queue to store parent for each node
then cycle is present
- in dfs, take: int par, as another argument
- in bfs, modify queue to store parent for each node
------------------------
1. using BFS
------------------------------------------------
2. using DFS
-------------------------------------------------------------------------------------------------------------
1. Bipartite graph check
-----------------------------
1. using BFS:
- instead of visited array we will take colour array
- also here we do not need parent node info, as colour array has enough info
--------------------------------------------------------- also here we do not need parent node info, as colour array has enough info
2. using DFS



Comments
Post a Comment