Data Structures & Algorithms

15 patterns — learn the technique, solve dozens of problems

Backtracking

Explore all possibilities by building solutions incrementally and abandoning paths that fail constraints.

Binary Search

Divide search space in half each step. Applies to sorted arrays, rotated arrays, and search-space reduction problems.

Binary Trees

Traversal, construction, validation, and path problems on binary trees and BSTs.

Bit Manipulation

XOR tricks, bitmasks, counting bits, and power-of-two checks for low-level optimization.

Dynamic Programming

Break problems into overlapping subproblems. Memoization, tabulation, and state transition design.

Graphs

BFS, DFS, topological sort, shortest path, union-find, and connected components.

Greedy

Make locally optimal choices at each step. Interval scheduling, activity selection, and optimization problems.

#

Hash Maps & Sets

Use hash-based data structures for O(1) lookups to solve counting, grouping, and duplicate detection problems.

Heaps & Priority Queues

Efficiently track min/max elements. Top-K problems, merge K sorted lists, and scheduling.

├─┤

Intervals

Merge, insert, intersect, and schedule intervals. Sorting by start/end and sweep line techniques.

Linked Lists

Pointer manipulation on singly and doubly linked lists — reversal, cycle detection, merge, and partitioning.

Sliding Window

Maintain a window over a contiguous subarray or substring, expanding and shrinking to find optimal solutions.

Stacks & Queues

LIFO and FIFO structures for parsing, monotonic patterns, BFS traversal, and expression evaluation.

T

Tries

Prefix trees for string search, autocomplete, word dictionaries, and IP routing.

Two Pointers

Use two pointers moving toward each other or in the same direction to solve array and string problems in O(n).