Greedy Algorithms

Make the locally best choice at each step and never look back, useful when local optima add up to a global optimum.

Related concepts

TopicDescription
Dynamic ProgrammingBreak a problem into overlapping subproblems and reuse their answers to avoid recomputing the same work.
Sliding WindowSolve fixed-window problems: maximum sum of k elements, moving averages, and O(n) updates as the window slides.
Two PointersScan a sorted array or string from both ends at once to find pairs, remove duplicates, or reverse data in O(n).
Binary SearchCut a sorted range in half on every step to find a value or boundary in O(log n) instead of checking one by one.
Depth-First SearchExplore as far as possible down one path before backtracking, used to walk trees, graphs, and grids.
Breadth-First SearchExplore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph.