Data Structures & AlgorithmsHardAccenture · Infosys OA
Problem: Which traversal order is guaranteed to visit nodes level by level in a tree or graph?
- A. Post-order traversal
- B. In-order traversal
- C. Depth-first search (DFS), using a stack or recursion
- D. Breadth-first search (BFS), using a queue
Correct answer: D. Breadth-first search (BFS), using a queue
BFS processes all nodes at distance k from the source before any node at distance k+1, which is exactly level-by-level order; DFS instead dives deep along one branch first.
More Coding Interview Problems questions
- Problem: For a weighted graph with all non-negative edge weights, which algorithm finds shortest paths from a single source, and in what…
- Problem: A graph may contain negative edge weights but no negative cycle. Which single-source shortest path algorithm handles this…
- Problem: What is the time complexity of the Floyd-Warshall algorithm for finding shortest paths between every pair of nodes in a graph…
- Problem: Which of these best describes why Kruskal's MST algorithm needs a Union-Find (disjoint set) structure?
- Problem: Between Kruskal's and Prim's MST algorithms, which is typically preferred for a dense graph represented with an adjacency matrix?
- Problem: Which statement correctly contrasts 0/1 knapsack and fractional knapsack?