Data Structures and Algorithms
Core data structures, algorithmic techniques, and graph algorithms for technical interview prep and equivalent undergraduate coursework.
Take a quick diagnostic
All 32 topics
Every skill the diagnostic can check, grouped the way the map is. Open any topic to start a lesson on it.
Foundations
- Complexity analysis: Describing how an algorithm's running time or memory grows as input size grows, using Big-O.
- Recursion: A function solving a problem by calling itself on a smaller version of the same problem.
Linear structures
- Arrays: A fixed-layout, contiguous block of memory where any index is reached in constant time.
- Linked lists: Nodes scattered in memory, each pointing to the next, trading fast indexing for cheap insertion.
- Stacks and queues: Two restricted-access orderings, last-in-first-out and first-in-first-out.
Searching and sorting
- Binary search: Repeatedly halving a sorted range to find a target in logarithmic time.
- Elementary comparison sorts: The simple O(n squared) sorts, bubble, insertion, selection, that compare and swap pairs of elements.
- Divide-and-conquer sorting: Divide-and-conquer sorts, merge sort and quicksort, that beat O(n squared) by splitting the problem.
- Non-comparison sorting: Sorting by exploiting known structure in the values themselves, counting or radix, instead of comparisons.
Hashing
- Hash tables: Mapping keys to array slots via a hash function for near-constant-time lookup.
Trees
- Binary trees: A hierarchical structure where each node has at most two children.
- Binary search trees: A binary tree kept ordered so each node's left subtree is smaller and right subtree is larger.
- Balanced search trees: A BST that actively rebalances itself, AVL rotations or red-black coloring, so it never degrades into a line.
- Heaps and priority queues: A tree-shaped structure that always keeps the smallest, or largest, element quick to find.
- Tries: A tree where each path from the root spells out a prefix, built for fast string lookup.
Graphs
- Graph representations: Storing a graph's vertices and edges as an adjacency matrix or adjacency list.
- Graph traversal (BFS and DFS): Visiting every reachable vertex, either level by level (BFS) or by diving deep first (DFS).
- Topological sort: Ordering the vertices of a directed acyclic graph so every edge points forward.
- Union-find: A structure that tracks which elements belong to the same group and merges groups quickly.
- Dijkstra's algorithm: Finding the cheapest path from one vertex to all others when no edge weight is negative.
- Bellman-Ford algorithm: Finding shortest paths that still works when some edge weights are negative, at the cost of speed.
- Minimum spanning trees: The cheapest set of edges that connects every vertex with no cycles.
Advanced structures
- Segment trees: A binary tree over an array that answers range queries, like sum or minimum, in logarithmic time.
- Fenwick trees: A compact array-based structure that answers prefix-sum queries in logarithmic time.
Techniques
- Divide and conquer: Splitting a problem into independent smaller copies of itself, solving each, then combining.
- Greedy algorithms: Making the locally best choice at every step and trusting it leads to a globally best answer.
- Dynamic programming: Solving a problem by caching answers to overlapping subproblems instead of recomputing them.
- Backtracking: Trying a choice, recursing, and undoing it if it leads nowhere, to explore all possibilities.
- Two pointers: Walking two indices through a sequence at once to avoid a nested loop.
- Sliding window: Growing and shrinking a contiguous range over a sequence to track a running condition in one pass.
- Bit manipulation: Using a number's individual binary bits directly, for example to represent a small set or toggle a flag.
Strings