Greedy choice property and backtracking
Optimal substructure and overlapping subproblems
Recursive structure and high time complexity
A clear base case and a linear state transition
Divide and conquer is used for optimization problems, while DP is used for sorting problems.
Dynamic programming breaks problems into smaller pieces, but divide and conquer does not.
Dynamic programming stores the results of subproblems to avoid re-computation, whereas divide and conquer does not.
Divide and conquer is always implemented iteratively, while DP is always recursive.
A greedy algorithm
An iterative, loop-based solution
A standard recursive solution
It solves the problem by first identifying and solving the smallest possible subproblems, then using those results to build up solutions to larger subproblems until the main problem is solved.
It solves the problem by starting at the main problem and breaking it down recursively, storing results along the way.
It always uses less memory than the top-down approach.
It randomly explores the solution space and saves the best result found.
dp[i][w]
The minimum weight required to achieve a value of w using exactly i items.
w
i
A boolean indicating if it's possible to achieve a total weight of w using i items.
The maximum value that can be obtained using only the first i items.
The maximum value that can be obtained using a subset of the first i items with a total weight capacity of w.
True
False
Subsets or permutations of a small set of elements, where the state needs to track which elements have been used.
Sequences of characters where the goal is to find the longest common subsequence.
Finding the shortest path in a very large, dense graph.
A large number of items with fractional values.
Operations Research
Finance
Computer Graphics
Bioinformatics
Make the C++ code shorter and more readable.
Reduce the space complexity by representing a multi-dimensional DP state in a more compact form, such as a single integer.
Reduce the time complexity of the algorithm by performing fewer calculations.
Solutions can require a large amount of memory to store the results of subproblems, which can be prohibitive.
It only works for problems with a single, unique solution.
It is often difficult to parallelize because subproblems are interdependent.
It cannot solve optimization problems.
Finding all nodes reachable from a starting node.
Finding the shortest path between two specific nodes.
Checking if a path exists between two nodes.
Finding the number of different paths of exactly length k from a source to a destination.
k
Tabulation always has a better time complexity than memoization.
Memoization can be more intuitive as it directly follows the recursive problem definition.
Memoization avoids the risk of stack overflow errors associated with deep recursion.
Tabulation solves only the subproblems that are absolutely necessary to solve the main problem.
All done? Get your grade