Dynamic Programming
30 cards · 🇺🇸 English
Memoization, tabulation, and classic dynamic programming patterns.
Study all 30 cards for free
Flashcards, quizzes, pixel-art games and a daily review that remembers for you.
Try the first 10 cards
1 / 10Dynamic programming
Tap the card for the answer · swipe right if you knew it, left if not
Already have an account? Sign in
Cards
- 1Dynamic programmingAlgorithmic paradigm solving complex problems by breaking them into simpler subproblems, storing results to avoid redundant computation
- 2Two key properties needed for dynamic programming1) Optimal substructure: optimal solution contains optimal solutions to subproblems. 2) Overlapping subproblems: same subproblems solved multiple times
- 3Memoization (top-down DP)Recursively solve problem, storing results in cache (e.g., hash map, array) to avoid recomputing; lazy evaluation approach
- 4Tabulation (bottom-up DP)Iteratively solve subproblems in order, building up solution from base cases; typically uses array/table; avoids recursion overhead
- 5Fibonacci sequence as a DP problemClassic example: F(n) = F(n-1) + F(n-2); naive recursion O(2ⁿ), DP reduces to O(n) time, O(1) space with optimization
- 60/1 Knapsack problemGiven items with weights and values, maximize value in knapsack with weight capacity W; each item taken 0 or 1 time; O(nW) DP solution
- 7Recurrence relation for 0/1 Knapsackdp[i][w] = max(dp[i-1][w], dp[i-1][w-wᵢ] + vᵢ) - either skip item i or include it
- 8Longest Common Subsequence (LCS) problemFind longest subsequence common to two sequences (not necessarily contiguous); O(mn) DP solution using 2D table
- 9LCS recurrence relationIf X[i]==Y[j]: dp[i][j] = 1 + dp[i-1][j-1]; else: dp[i][j] = max(dp[i-1][j], dp[i][j-1])
- 10Longest Increasing Subsequence (LIS) problemFind length of longest strictly increasing subsequence; O(n²) DP or O(n log n) with binary search
- 11Edit Distance (Levenshtein) problemMinimum operations (insert, delete, substitute) to transform one string to another; O(mn) DP solution
- 12Coin Change problemFind minimum coins to make amount, or count ways to make amount; classic DP problem with O(n×amount) complexity
- 13Matrix Chain Multiplication problemFind optimal order to multiply chain of matrices to minimize scalar multiplications; O(n³) DP solution
- 14Rod Cutting problemGiven rod of length n and prices for each length, maximize profit by cutting rod; similar to unbounded knapsack
- 150/1 vs unbounded knapsack0/1: each item used once. Unbounded: infinite supply of each item; recurrence and solution differ
- 16Subset Sum problemDetermine if subset of numbers sums to target; O(n×sum) DP; variation: count subsets with given sum
- 17Space optimization in DPReduce space from O(n²) to O(n) or O(1) by observing that often only previous row/column needed; common in knapsack, LCS
- 18Partition Equal Subset Sum problemCan array be partitioned into two subsets with equal sum? Reduces to subset sum with target = total_sum/2
- 19House Robber problemMaximize money robbed from houses in a line/circle without robbing adjacent houses; O(n) DP with state transitions
- 20Maximum Subarray Sum (Kadane's) problemFind contiguous subarray with largest sum; O(n) solution: dp[i] = max(nums[i], dp[i-1] + nums[i])
- 21Climbing Stairs problemCount ways to reach top of n-step staircase taking 1 or 2 steps; equivalent to Fibonacci: dp[n] = dp[n-1] + dp[n-2]
- 22Palindrome Partitioning problemMinimum cuts to partition string into palindromes; O(n²) DP with precomputed palindrome check
- 23DP on treesDP where states depend on tree structure; examples: tree diameter, max independent set on tree; often use DFS with memoization
- 24Digit DPTechnique for counting numbers with specific properties in a range; uses digit-by-digit construction with tight bound tracking
- 25Bitmask DPDP where state includes bitmask representing subset; used in TSP, assignment problems; state space O(2ⁿ × n)
- 26Traveling Salesman Problem (TSP) DP solutionO(2ⁿ × n²) using bitmask DP; dp[mask][i] = min cost to visit cities in mask ending at city i
- 27State transition in DPThe recurrence relation showing how current state depends on previous states; defines how to build solution from subproblems
- 28Identify if a problem can use DPCheck for: overlapping subproblems, optimal substructure, ability to define state, clear recurrence relation
- 29Time complexity trade-off in DPDP trades space (storing results) for time (avoiding recomputation); typically achieves polynomial time from exponential naive solutions
- 30DP vs greedy algorithmsGreedy: makes locally optimal choices, may not give global optimum. DP: considers all subproblems, guarantees global optimum when applicable
Articles about this deck
More Programming decks
See all- 🧱
Data Structures
95 cards · 🇺🇸 English
Arrays, linked lists, trees, graphs, hash tables and their core operations.
- 🧱
Estructuras de Datos
95 cards · 🇺🇸 English
Arrays, listas enlazadas, árboles, grafos, tablas hash y sus operaciones fundamentales.
- 🏗️
Design Patterns & OOP/SOLID Principles
60 cards · 🇺🇸 English
The Gang of Four design patterns plus object-oriented and SOLID principles.
- ⏱️
Notación Big O
44 cards · 🇺🇸 English
Análisis de la complejidad temporal y espacial de algoritmos y operaciones comunes.
- ✅
Testing: Unit & Integration
40 cards · 🇺🇸 English
Unit testing, integration testing, mocking, and testing best practices.
- 🧱
Datenstrukturen
95 cards · 🇺🇸 English
Arrays, verkettete Listen, Bäume, Graphen, Hash-Tabellen und ihre wichtigsten Operationen.
