kittyK's blog

By kittyK, history, 4 years ago, In English

It might be silly question for pro coders. It is very basic question .I actually googled but could not understand well.

So the question is why the way of finding cycle is different for directed and undirected graph ?

  • Vote: I like it
  • +11
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In undirected graph, you have to keep track of parent node also. Example given an undirected graph as:

2 1

1 2

if you apply directed graph cycle check method then it would give you a cycle (1-2-1) which is not the case

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

There are more than one ways to find cycles and they don't have to be different for the two types of graphs. For example, DFS will work for both.