📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      What is the difference between 'BFS' (Breadth-First

      Search) and 'DFS' (Depth-First Search) in graph traversal?
      A BFS uses a stack; DFS uses a queue Correct Answer Incorrect Answer
      B BFS is used only for traversing trees; DFS is used only for traversing graphs Correct Answer Incorrect Answer
      C BFS explores all neighbours at the current depth level before going deeper; DFS explores along each branch before backtracking Correct Answer Incorrect Answer
      D BFS always finds the shortest path in weighted graphs; DFS finds the longest path in weighted graphs Correct Answer Incorrect Answer
      E BFS and DFS produce identical traversal results on all graphs Correct Answer Incorrect Answer

      Solution

      BFS (Queue-based): visits nodes level by level and guarantees shortest path in unweighted graphs. It is used in social networks (degrees of separation), GPS routing, peer-to-peer networks. DFS (Stack/Recursion): explores one path fully before backtracking and is used in topological sorting, detecting cycles, solving mazes, connected components. Time complexity: O(V+E) for both (V = vertices, E = edges). Memory: BFS stores entire frontier (can be large), DFS uses stack depth proportional to path length.

      Practice Next

      Relevant for Exams:

      ask-question