Aptitude · Tech basics

Data structures and Big O, made easy

💡 The idea

Pick the structure by how you need to get things out: last-in-first-out (stack), first-in-first-out (queue), by key (hash table), in order (sorted array or tree), or by connections (graph).

How do I take items out?→Pick the structure→How fast? (Big O)
Choosing a data structure

🧭 The method: 3 steps

  1. Stack = pile of plates (LIFO). Queue = line at a counter (FIFO).
  2. Hash table = instant lookup by key. Graph = things connected to things.
  3. Big O = how the work grows as n grows: O(1) < O(log n) < O(n) < O(n log n) < O(n²).

🎬 Every kind of question, in pictures

Pick a kind. Guess the answer first, then watch the picture work it out. Tap any step to see it in the picture.

Loading the pictures…

✏️ Worked examples

Example 1. push 1, push 2, pop, push 3. What is on top?

  1. [1] → [1, 2] → pop → [1] → [1, 3]

⚡ Shortcut: 3

⚠️ Where people go wrong

  • Mixing up stack (last in, first out) and queue (first in, first out).
  • Binary search only works on SORTED data.
  • O(log n) is faster than O(n), not slower.

📌 Remember

  • Stack LIFO, queue FIFO
  • Hash table: O(1) lookup
  • Binary search: log₂ n steps

🎯 Now you try

Fresh questions every time, with the full solution. Pick a level and go.

Loading questions…

⏱️ Take a 10-question timed test: Data structures and Big O