Data structures and algorithms
Choose structures, trace their state, and defend time and memory costs.
Learn what each structure remembers
A set remembers which IDs have appeared. A queue remembers which task comes next. A heap keeps the next priority available without sorting everything again. This chapter makes those differences visible with small inputs and state traces before asking you to solve a full problem.
Read the structures in order, trace each operation by hand, and name the invariant that remains true. You are learning to choose a tool and account for time and memory. The next chapter combines those tools into complete solutions.
Parts group related chapters. Each lesson has a chapter.lesson address, such as 4.07. Open a title below, or use Next to follow the reading sequence. Within a lesson, On this page lists its sections.
- 1.01
Cost: count the work and the memory
Cost and basic collections
- 1.02
Arrays and strings: keep order and boundaries
Cost and basic collections
- 1.03
Sets: remember membership
Cost and basic collections
- 1.04
Maps: remember earlier work
Cost and basic collections
- 1.05
Stacks: keep unresolved work
Order and linked structures
- 1.06
Queues and deques: control who goes next
Order and linked structures
- 1.07
Linked lists: preserve the reachable chain
Order and linked structures
- 1.08
Trees: carry context down, combine answers up
Order and linked structures
- 1.09
Heaps: keep the next best candidate
Order and linked structures
- 1.10
Tries: share prefixes without losing whole words
Order and linked structures
- 1.11
Graphs: visit once, then track prerequisites
Connections
- 1.12
Union-find: track components as links arrive
Connections
- 1.13
- 1.14
Sorting: pay once to expose order
Algorithms that narrow the work
- 1.15
Sorted data: binary search and intervals
Algorithms that narrow the work
- 1.16
Two pointers: discard work with a reason
Algorithms that narrow the work
- 1.17
Windows: move boundaries, avoid rescanning
Algorithms that narrow the work
- 1.18
Prefix sums: count possible starts
Algorithms that narrow the work
- 1.19
Greedy choices: prove the local step is safe
Algorithms that narrow the work
- 1.20
Search: choose, recurse, undo
Search, reuse, and selection
- 1.21
Dynamic programming: define a smaller problem
Search, reuse, and selection
- 1.22
Bit operations: represent independent flags
Search, reuse, and selection
- 1.23
Choose the structure from the repeated question
Search, reuse, and selection