Array
A contiguous block of slots in memory. Access by index is O(1) — the runtime computes start + i × size. Insert / delete in the middle costs O(n) because everything to the right has to shift.
Linked list (singly)
A chain of nodes; each node stores its value and a pointer to the next. No contiguous memory, no shifting on insert — but you can\'t jump to the middle, you have to walk from the head.
Stack & queue
Two restricted access patterns built on top of arrays or linked lists. Stack is LIFO (last-in, first-out). Queue is FIFO (first-in, first-out).
Stack — push / pop
Queue — enqueue / dequeue
Hash table
A clever array. Run the key through a hash function to get an index, store the value at that slot. Average O(1) for insert / lookup / delete — but collisions can slow you down. We resolve collisions by chaining: each slot is a small list.
Binary search tree
Each node has up to two children. The invariant: every left descendant is less than the node, every right descendant is greater. Insert / search by walking left or right based on comparison — O(log n) when the tree is balanced, O(n) when it degenerates into a chain.
Which structure should I use?
Pick the structure that makes your most-frequent operation fast.
Need fast index access
→ Array. Constant time, cache-friendly. Use a dynamic array (Python list, JS Array, Java ArrayList).
Need fast insert / delete in the middle
→ Linked list. Just rewire two pointers. Doubly-linked if you need backward traversal.
Need last-in, first-out
→ Stack. Function calls, undo histories, expression evaluation, depth-first search.
Need first-in, first-out
→ Queue. Task scheduling, breadth-first search, fair turn-taking.
Need fast lookup by key
→ Hash table. O(1) average for put / get / delete. Beware ordering — most hash tables don\'t preserve insertion order (Java HashMap), though some do (Python dict 3.7+).
Need lookup AND sorted order
→ BST (Red-Black or AVL). O(log n) for everything; in-order walk gives sorted output for free. C++ std::map, Java TreeMap.
Need to find min / max repeatedly
→ Heap (priority queue). O(log n) insert and extract-min. Used in Dijkstra\'s shortest path, A*, scheduling.
Need set membership only
→ Hash set or Bloom filter. Hash set is exact O(1); Bloom is probabilistic (false positives possible) but uses a fraction of the memory.