Comparison Mode
Side-by-side: use case, requirements, complexity, strengths, weaknesses, example problems, and a clear “choose this when…”.
BFS vs DFSDijkstra vs Bellman-FordKruskal vs PrimMerge Sort vs Quick SortHeap vs Priority QueueHash Map vs Tree MapBFS vs DijkstraSliding Window vs Two PointersPrefix Sum vs Segment TreeGreedy vs Dynamic ProgrammingMemoization vs TabulationTarjan vs KosarajuSegment Tree vs Fenwick TreeArray vs Linked ListStack vs QueueQuick Sort vs Heap SortKMP vs Rabin-KarpUnion-Find vs DFSTrie vs Hash MapAVL Tree vs Red-Black Tree
BFSGraph Algos | DijkstraGraph Algos | |
|---|---|---|
| Use case | Shortest paths when every edge costs the same. | Shortest paths with arbitrary non-negative weights. |
| Requirements | A FIFO queue; unweighted (or uniformly weighted) graph. | A min-heap keyed by tentative distance; weights >= 0. |
| Time complexity | O(V + E). | O((V + E) log V). |
| Space complexity | O(V). | O(V + E) including heap entries. |
| Strengths | Linear time; trivial to implement; first visit is provably optimal. | Handles any non-negative weights; degenerates gracefully to BFS order on unit weights. |
| Weaknesses | Incorrect the moment edge weights differ; cannot prioritize cheaper edges. | Logarithmic overhead per edge; fails on negative edges. |
| Example problems | Word ladder, shortest path in binary matrix, rotting oranges. | Network delay time, path with minimum effort, swim in rising water. |
| Choose this when | Choose BFS when all moves cost 1; it is Dijkstra without the heap and strictly faster. | Choose Dijkstra as soon as edges carry different non-negative costs; consider 0-1 BFS if the only weights are 0 and 1. |