Recall & Review
beginner
What is a cycle in an undirected graph?
A cycle is a path that starts and ends at the same vertex, with all edges and vertices distinct except the first and last vertex.
Click to reveal answer
beginner
Which data structure is commonly used to detect cycles in an undirected graph?
Depth-First Search (DFS) is commonly used to detect cycles by checking if a visited vertex is encountered again and is not the parent of the current vertex.
Click to reveal answer
intermediate
In cycle detection using DFS, why do we keep track of the parent node?
To avoid falsely detecting a cycle when revisiting the immediate parent node, since the parent is connected to the current node by an edge.
Click to reveal answer
intermediate
What is the time complexity of cycle detection in an undirected graph using DFS?
The time complexity is O(V + E), where V is the number of vertices and E is the number of edges, because each vertex and edge is visited once.
Click to reveal answer
advanced
How does the Union-Find (Disjoint Set) data structure help in cycle detection?
Union-Find helps detect cycles by grouping connected vertices. If two vertices of an edge belong to the same group, adding that edge creates a cycle.
Click to reveal answer
What indicates a cycle during DFS in an undirected graph?
✗ Incorrect
A cycle is detected if DFS visits a vertex that has already been visited and is not the immediate parent.
What is the role of the 'parent' parameter in DFS cycle detection?
✗ Incorrect
The parent parameter helps avoid false cycle detection by ignoring the edge back to the parent.
Which of these is NOT a valid method for cycle detection in undirected graphs?
✗ Incorrect
Topological Sort is used for cycle detection in directed graphs, not undirected graphs.
What is the initial state of the 'visited' array in DFS cycle detection?
✗ Incorrect
Initially, all vertices are unvisited before DFS starts.
In Union-Find, what does it mean if two vertices have the same root?
✗ Incorrect
Same root means vertices are in the same set; connecting them again forms a cycle.
Explain how DFS can be used to detect a cycle in an undirected graph.
Think about revisiting nodes and how parent helps avoid false positives.
You got /4 concepts.
Describe how the Union-Find data structure detects cycles in an undirected graph.
Focus on grouping vertices and checking if an edge connects vertices in the same group.
You got /4 concepts.