RK DSA Studio

Undirected cycle

An edge to an already visited vertex other than the DFS parent reveals a cycle in a simple undirected graph.

Remember: Ignore the parent edge; check other visited neighbors.

Example: Edges A—B, B—C, C—A form a cycle.

Time: O(V + E). Auxiliary space: O(V).

Formula: Directed: edge to visiting node. Undirected: ignore the parent edge.

Up to 8 unique integer vertex labels and 16 edges. Edges: from,to; separate edges with semicolons. Undirected simple graph; self-loops allowed. Check all components. Graph storage O(V + E) is excluded from auxiliary space.

Complexities describe the underlying algorithm; tutorial snapshots and rendering can use additional resources.

The interactive workspace loads here when JavaScript is available. You can still browse the learning notes and links above without it.