To avoid infinite loops in DFS, it's essential to implement _______ to track visited nodes.

  • A counter for visited nodes
  • A queue for visited nodes
  • A set or array marking visited nodes
  • A stack for visited nodes
To avoid infinite loops in DFS, it's essential to implement a set or array to mark visited nodes. This ensures that each node is visited only once during the traversal, preventing the algorithm from getting stuck in infinite loops and exploring the same nodes repeatedly.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *