Graph Traversals Quiz

Placewit
2 min readJun 29, 2021

Which of the following condition is sufficient to detect cycle in a directed graph?

A. There is an edge from currently being visited node to an already visited node.

B. There is an edge from currently being visited node to an ancestor of currently visited node in DFS forest.

C. Every full binary tree is also a complete binary tree.

D. None of the above

Solution :

B) is correct.

Depth First Traversal can be used to detect a cycle in a Graph. DFS for a connected graph produces a tree. There is a cycle in a graph only if there is a back edge present in the graph. A back edge is an edge that is from a node to itself (self-loop) or one of its ancestors in the tree produced by DFS.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--