Which among the following search algorithms requires the least memory?
2025
Which among the following search algorithms requires the least memory?
- A.
Optimal Search
- B.
Linear Search
- C.
DFS
- D.
BFS
Attempted by 36 students.
Show answer & explanation
Correct answer: B
The memory a search technique needs is decided by the extra bookkeeping data structure it must maintain besides the input itself — a stack, a queue, a priority queue, or nothing at all. Comparing “memory” means comparing the size of that extra structure, not how fast each method runs.
Linear Search checks the elements one after another using only a single position marker — it keeps no separate stack, queue, or frontier, so its extra memory use stays fixed (constant) no matter how big the list is.
DFS explores by going as deep as possible along one branch before backtracking, so it must remember the entire chain of ancestor nodes on a stack — this stack grows with the depth of the search.
BFS explores level by level, so it must hold every node of the current frontier in a queue before moving to the next level — this queue can grow very large, tied to the branching factor.
A search approach designed to guarantee the optimal solution (an optimal / uniform-cost style search) commonly needs to retain the cost of multiple candidate paths as it works, typically using some form of priority-queue bookkeeping — this ties its memory use to how many paths are being tracked, not to a single fixed amount.
It is true that DFS typically needs less memory than BFS (a stack that grows with depth is smaller than a frontier that grows with the branching factor) — but DFS still needs a stack that grows with depth, and an approach built to guarantee the optimal solution still needs to track multiple candidate paths as it works. Only Linear Search needs no such growing structure at all.
Since Linear Search is the only one of the four that needs no extra data structure at all, it is the one that requires the least memory.