How can I remember which data structures are used by DFS and BFS?

captcadaver picture captcadaver · Oct 14, 2010 · Viewed 67.7k times · Source

I always mix up whether I use a stack or a queue for DFS or BFS. Can someone please provide some intuition about how to remember which algorithm uses which data structure?

Answer

Sai Kumar Battinoju picture Sai Kumar Battinoju · Sep 24, 2015

Queue can be generally thought as horizontal in structure i.e, breadth/width can be attributed to it - BFS, whereas

Stack is visualized as a vertical structure and hence has depth - DFS.