Dynamic Programming
Dynamic programming (DP) is an algorithmic technique for solving problems by breaking them into overlapping subproblems, solving each subproblem once, and storing (caching) its result to avoid redundant recomputation.
49 resources across 3 libraries
Glossary Terms(3)
Dynamic Programming
Dynamic programming (DP) is an algorithmic technique for solving problems by breaking them into overlapping subproblems, solving each subproblem once, and stor…
Graph Algorithm
A graph algorithm is a procedure that operates on a graph — a set of nodes (vertices) connected by edges — to solve problems such as finding shortest paths, de…
Memoization
Memoization is an optimization technique that caches the results of expensive function calls so that when the same inputs occur again, the cached result is ret…
Cheat Sheets(1)
Interview Questions(45)
What is Dynamic Programming?
Dynamic programming is a technique for solving problems by breaking them into overlapping subproblems and storing each subproblem’s result so it is computed on…
What is Memoization?
Memoization is an optimization technique that caches the results of expensive function calls keyed by their arguments, so repeated calls with the same inputs r…
Greedy vs Dynamic Programming: What is the Difference?
Greedy algorithms make the locally optimal choice at each step and never reconsider it, while dynamic programming explores overlapping subproblems and combines…
What is Kadane's Algorithm?
Kadane's algorithm finds the maximum sum of a contiguous subarray in O(n) time and O(1) space by scanning once and, at each position, deciding whether to exten…
0/1 Knapsack Problem: How Would You Solve It?
The 0/1 knapsack problem is solved with dynamic programming: build a table dp[i][w] representing the best value achievable using the first i items within capac…
Unbounded Knapsack Problem: How Is It Different?
The unbounded knapsack problem allows each item type to be picked an unlimited number of times, so the DP recurrence becomes dp[w] = max(dp[w], value[i] + dp[w…
Coin Change Problem: How Would You Solve It?
The coin change problem (minimum coins to make an amount) is solved with dynamic programming: dp[a] holds the fewest coins needed to make amount a, computed as…
Edit Distance Problem: How Would You Solve It?
Edit distance (Levenshtein distance) is solved with dynamic programming: dp[i][j] holds the minimum number of insertions, deletions, and substitutions to turn…
How Do You Find the Longest Common Subsequence?
The longest common subsequence (LCS) of two strings is the longest sequence of characters that appears in both strings in the same relative order but not neces…
How Do You Find the Longest Increasing Subsequence?
The longest increasing subsequence (LIS) is the longest subsequence of an array in which elements strictly increase, solvable in O(n^2) with straightforward dy…
How Do You Find the Longest Common Substring?
The longest common substring is the longest contiguous block of characters that appears identically in both strings, found with a 2D dynamic programming table…
How Do You Solve the Subset Sum Problem?
Subset sum asks whether some subset of a given set of numbers adds up exactly to a target value, solved with a 2D (or space-optimized 1D) dynamic programming t…
How Do You Solve Partition Equal Subset Sum?
Partition equal subset sum asks whether an array can be split into two subsets with equal totals, which is only possible if the overall sum is even, and then r…
What is the Bellman-Ford Algorithm?
Bellman-Ford finds shortest paths from a single source to every other vertex in a weighted graph by relaxing all edges repeatedly for V-1 rounds, and unlike Di…
What is the Floyd-Warshall Algorithm?
Floyd-Warshall is a dynamic programming algorithm that computes the shortest path between every pair of vertices in a weighted graph in O(V^3) time by progress…
What is Manacher's Algorithm?
Manacher's algorithm finds the longest palindromic substring in a string in O(n) time by reusing previously computed palindrome-radius information from a mirro…
What is the Divide and Conquer Strategy?
Divide and conquer is an algorithm design strategy that breaks a problem into smaller independent subproblems of the same type, solves each subproblem recursiv…
How Do You Count the Number of Set Bits in an Integer Efficiently?
The fastest general technique counts set bits in O(k) time, where k is the number of set bits, using Brian Kernighan’s trick: repeatedly apply n = n & (n - 1),…
What is the Traveling Salesman Problem?
The Traveling Salesman Problem (TSP) asks for the shortest possible route that visits every city exactly once and returns to the start, and it is NP-hard, mean…
What is the All-Pairs Shortest Path Problem?
All-pairs shortest path (APSP) computes the minimum-cost route between every pair of vertices in a graph at once, typically solved with the Floyd-Warshall algo…
How Do You Find the Longest Palindromic Substring?
The expand-around-center approach finds the longest palindromic substring in O(n²) time and O(1) extra space by treating every index (and every gap between ind…
How Do You Solve the Palindrome Partitioning Problem?
Palindrome partitioning — splitting a string into the minimum number of cuts so every resulting piece is a palindrome — is solved with dynamic programming in O…
How Does Matrix Chain Multiplication Work?
Matrix chain multiplication finds the cheapest order to parenthesize a chain of matrix multiplications — not the product itself — using dynamic programming in…
What is the Rod Cutting Problem?
The rod cutting problem asks for the maximum revenue obtainable by cutting a rod of length n into pieces and selling each piece at a given price, and it is sol…
Showing 24 of 45.