Frontend Labs
β‹―

Cheat Sheet: When Do I Use What?

Problem sounds like... Reach for...
"I need instant lookup by a key/name" Hash Map
"First come, first served" Queue
"Undo my last action" Stack
"The list is sorted, find something fast" Binary Search
"Find the shortest path / fewest steps" BFS or Dijkstra
"Explore every possibility, backing up on dead ends" DFS / Backtracking
"This must happen before that" Topological Sort
"I keep recalculating the same sub-answer" Dynamic Programming (memoize)
"Just grab the biggest/cheapest option each time" Greedy
"Always give me the most urgent/smallest/biggest item next" Heap / Priority Queue
"Are these two things in the same group?" Union-Find
"Autocomplete as the user types" Trie
"Organize hierarchical data (folders, org charts)" Tree
"Model relationships between things (people, cities)" Graph

The one-sentence version of everything

  • Array: numbered boxes in a row, instant access by number.
  • String: an array of letters.
  • Linked List: a chain of clues, each pointing to the next.
  • Stack: last in, first out β€” like a pile of pancakes.
  • Queue: first in, first out β€” like a checkout line.
  • Linear Search: check everything, one by one.
  • Bubble Sort: repeatedly swap neighbors until sorted.
  • Binary Search: cut the possibilities in half every guess.
  • Recursion: solve a smaller version of the same problem.
  • Hash Map: instant lookup via a coat-check ticket.
  • Tree: a family tree β€” one path to every relative.
  • BST: a tree where left is always smaller, right is always bigger.
  • Merge/Quick Sort: divide the mess into tiny pieces, then combine/sort smartly.
  • Graph: friendships that can loop around, unlike a family tree.
  • BFS/DFS: explore ring-by-ring, or dive deep-first.
  • Dynamic Programming: remember answers so you never redo work.
  • Greedy: always take the best option available right now.
  • Backtracking: try, and undo if it doesn't work out.
  • Heap: always know the most urgent item instantly.
  • Union-Find: quickly track which friend groups have merged.
  • Trie: a tree of letters, for lightning-fast prefix lookups.
  • Dijkstra: GPS logic β€” always expand the closest place first.
  • Topological Sort: one valid order that respects all the "do this before that" rules.

Generated from real-life-ds-algo-guide.md Β· 8 Oct 2026 16:36