DP

DP Fundamentals

Understand overlapping subproblems, optimal substructure, memoization, and tabulation.

0 Problems2-3 hours

Overview

Dynamic Programming solves problems with overlapping subproblems and optimal substructure by caching results. Two approaches: top-down (memoization) and bottom-up (tabulation).

Complexity Summary

Time Complexity

Usually O(n) or O(n²)

Space Complexity

O(n) or O(n²); often reducible

Key Patterns & Techniques

Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.

1

Overlapping subproblems

Concept

same sub-problem solved multiple times in recursion

Practice questions for this pattern
2

Optimal substructure

Concept

optimal solution built from optimal sub-solutions

Practice questions for this pattern
3

Memoization

Concept

top-down: add a cache to recursion

Practice questions for this pattern
4

Tabulation

Concept

bottom-up: fill a table iteratively

Practice questions for this pattern
5

State definition

Concept

dp[i] = answer to sub-problem of size i

Practice questions for this pattern
6

Recurrence relation

Concept

express dp[i] in terms of earlier dp values

Practice questions for this pattern
7

Base case

Concept

initialize dp for the smallest inputs

Practice questions for this pattern
8

Space optimization

Concept

if dp[i] depends only on dp[i-1], use two variables

Practice questions for this pattern
DSA Practice Online - 150+ Coding Interview Questions | LeetCode Alternative | InstaMock - AI Mock Interview