Detect Cycle in a Undirected Graph

Hard
0/120
Average time to solve is 50m
18 upvotes
Asked in company
Adobe

Problem statement

Given an undirected graph, check whether the graph contains a cycle or not. Your function should return true if the given graph contains at least one cycle, else return false.

Detailed explanation ( Input/output format, Notes, Images )
Input format :
Line 1 : Graph of type graph class
Output Format :
return true or false
Sample Input 1:
for graph with edges
(0,1);(1,2);(0,3);(3,4);(0,2)
Sample Output 1:
True 
Detect Cycle in a Undirected Graph
Full screen
Console