c - Verify if an undirected graph has cycles -
i know question has been asked times. can't understand yet , questions old reply...
i read kahn's algorithm
dfs
plus tarjan's connected components algorithm
can't understand process make work.
i've done far initialized , feed graph.
, found shortest path vertéx b.
a simple dfs little modification do.
hint: dfs traversal of given graph. every visited vertex ‘v’, if there adjacent ‘u’ such u visited , u not parent of v, there cycle in graph.
also note: cycles detection in undirected graphs follow algorithm totally different directed graphs. cycle in directed graphs diffent.
(hope comfortable dfs).
Comments
Post a Comment