Divide and Conquer
|
Dynamic Programming
|
Breaks problems into smaller subproblems
|
Breaks problems into overlapping subproblems
|
Solves subproblems independently
|
Reuses solutions of overlapping subproblems
|
Typically uses recursion
|
Typically uses iteration
|
No shared information between subproblems
|
Stores solutions in a table for future reference
|
Subproblems are solved sequentially
|
Subproblems can be solved in any order
|
Often results in redundant computations
|
Avoids redundant computations through memoization
|
Generally has a higher time complexity
|
Generally has a lower time complexity
|
Can be more intuitive for certain problems
|
Can be more efficient for problems with overlapping subproblems
|
Examples: Merge sort, Quick sort
|
Examples: Fibonacci sequence, Shortest path problems
|
May not exploit optimal substructure
|
Exploits optimal substructure to find optimal solutions
|
Requires combining results of subproblems
|
Requires identifying and solving overlapping subproblems
|
May involve merging or combining subproblem solutions
|
May involve selecting or choosing among subproblem solutions
|
Suitable for problems that can be divided into independent parts
|
Suitable for problems that can be solved by breaking them into overlapping subproblems
|
May require additional space for recursive calls
|
May require additional space for storing solutions in a table
|
Can have a higher space complexity
|
Can have a lower space complexity
|
Examples: Binary search, Maximum subarray problem
|
Examples: Longest common subsequence, Knapsack problem
|
Often uses a "divide," "conquer," and "combine" approach
|
Often uses a "divide," "solve," and "combine" approach
|
Requires solving all subproblems
|
Requires solving only necessary subproblems
|
May involve solving subproblems with the same parameters multiple times
|
Avoids redundant computation by storing and reusing solutions
|
May result in a simpler implementation
|
May require careful formulation and identification of subproblems
|
May not be suitable for problems with overlapping subproblems
|
Well-suited for problems with overlapping subproblems
|
No explicit storage of solutions
|
Solutions are explicitly stored in a table or array
|
Examples: Binary exponentiation, Closest pair problem
|
Examples: Matrix chain multiplication, Longest increasing subsequence
|
May have a higher memory overhead
|
May have a lower memory overhead
|
Generally used when the subproblems are independent
|
Generally used when the subproblems overlap
|
Can have a higher number of recursive calls
|
Can have a lower number of recursive calls
|
Examples: Mergesort, Binary search tree operations
|
Examples: Fibonacci series, Travelling salesman problem
|
May require a more detailed analysis of subproblems
|
Requires careful identification of overlapping subproblems
|
Breaks the problem into smaller, non-overlapping parts
|
Breaks the problem into overlapping subproblems
|