Correct answer: A. To avoid infinite loops caused by cycles in the graph
Explanation
Tracking visited nodes prevents infinite loops when a graph contains cycles, unlike trees which have no cycles by definition.
Practise 3 questions on this topic
Take Trees & Graphs — Timed Test (3 questions) — scored instantly, explanation for every question, no login.