Overview
A data structure is a decision about which operations you want to be cheap. There is no structure
Arrays & Dynamic Arrays
An array is a block of contiguous memory holding equally-sized elements. That one property gives it
Linked Lists
A linked list stores each element in its own node, together with a pointer to the next one. Nothing
Stacks & Queues
Stacks and queues are not new storage — they are restrictions on storage. Both hold a sequence,
Hash Tables
A hash table turns a key into an array index by running it through a hash function, then reads or
Trees & BSTs
A tree is a set of nodes where each node has one parent (except the root) and no cycles. That single
Balanced Trees
A binary search tree is $O(\log n)$ only while it stays short, and nothing in the plain
Heaps & Priority Queues
A priority queue answers one question: what is the most important item right now? A binary
Graphs
A graph is a set of vertices and a set of edges connecting them. That is nearly no structure
Union-Find
Some problems never ask what is in a group. They ask only whether two things have ended up in the
Tries
A hash set answers "is this exact string in the set?" and nothing else. It cannot answer "what strings
Segment Trees & Fenwick
Prefix sums answer range-sum
Deques & Ring Buffers
A stack grows and shrinks at one end; a queue adds
Probabilistic Structures
Every structure so far in this section answers its question exactly, at the cost of storing enough
LRU & LFU Caches
A cache with unlimited capacity is just a hash table. The interesting problem
Cheat Sheet
This page is a reference, not a tutorial — each page in this section explains the reasoning behind the