Skip to content

Algorithms Overview

First PublishedByAtif Alam

Guides to algorithms and data structures. Topics are ordered by learning priority (easy + high ROI first).

Algorithm problems often take one or more of these input shapes; recognizing them helps you choose the right technique. Input types here mean the form of the problem input (what you’re given). Data structures include both those forms and the structures we use while solving (e.g. stacks, heaps, hash maps). For the full picture of structures and where they appear, see Data structures.

  • Scalars — Single numbers (e.g. n, k, target).
  • Arrays / lists — Sequences of numbers or objects (e.g. arr, nums, intervals).
  • Strings — Text (e.g. s, text); sometimes treated as a sequence of characters.
  • Graphs — Usually given as an edge list (pairs or triplets), adjacency list (e.g. dict or list of neighbors), or adjacency matrix; often for undirected or directed graphs.
  • Trees — Often represented like graphs (e.g. adjacency list or parent pointers) or in an array form (e.g. heap).
  • Matrix / grid — 2D array (e.g. for grids, images).
  • Stream / online — Input arrives over time (e.g. dynamic connectivity).
AlgorithmOther common names
Two PointersTwo-pointer technique, dual pointers
Sliding WindowFixed-size / variable-size window (when distinguishing)
Prefix SumCumulative sum, running sum, scan
Breadth-First SearchBFS, level-order traversal (on trees)
Depth-First SearchDFS, depth-first traversal
Binary SearchBinary search on the answer (for search-space use)
HeapPriority queue (abstract), binary heap, min-heap / max-heap
BacktrackingRecursive backtracking, DFS + undo
Dynamic ProgrammingDP, memoization (top-down + cache)
Divide and ConquerD&C, recursive divide; merge sort, quicksort; insertion sort (baseline)
TriePrefix tree, digital tree, radix tree (when compressed)
Union FindDisjoint Set Union (DSU), disjoint sets, merge-find
GreedyGreedy algorithm, myopic strategy
orderTitleDifficultyROI
1Two PointersEasyHigh
2Sliding WindowEasyHigh
3Prefix SumEasyHigh
4Breadth-First SearchEasyHigh
5Depth-First SearchMediumHigh
6Binary SearchEasyMedium
7HeapMediumMedium
8BacktrackingHighHigh
9Dynamic ProgrammingHighMedium
10Divide and ConquerMediumLow
11TrieMediumLow
12Union FindMediumLow
13GreedyHighLow