educative.io

Detecting a cycle in an undirected graph

I might have the wrong intuition here, but in an undirected graph, let’s say we have two nodes (1) and (2) if there is an edge from (1) - (2) then that means it we also have (2) - (1). If that is the case then isn’t any edge in an undirected graph a cycle?

Hi,

This is Maisam Shah from Educative. Thank you for reaching out to us!

In response to your query, a cycled graph is one, in which 3 or more vertices are connected in a closed chain which is not the case for our chosen example. The edges in an undirected graph are not considered cycles according to this definition. The example we have used is also visually displayed in this lesson as well and it can be seen that no three vertices form a connected chain.

If you have any further queries or concerns, please feel free to get in touch again.

Best Regards,
Maisam Shah | Developer Advocate
Educative