Recursive
Section titled “Recursive”A recursive algorithm or function is the one that calls itself to solve a smaller version of its task. Terminating or base conditions are required.
Divide & Conquer
Section titled “Divide & Conquer”- Divide: Split a problem into smaller sub-problems
- Conquer: Solve a subset of smaller sub-problems recursively
- Combine: Combine the solutions to solve the initial problem
Examples:
Analysis
Section titled “Analysis”Recurrence relation
Section titled “Recurrence relation”A mathematical equation that defines the overall cost of solving a problem in terms of the cost of solving its smaller sub-problems. It provides a way to express the time complexity of recursive algorithms.
3 common methods are used to solve a recurrence relation.
Substitution method
Section titled “Substitution method”The form of the solution is guessed and verified by induction. Then the constants are solved for.
Iteration method
Section titled “Iteration method”Aka. recursion-tree method. The recurrence is expanded step-by-step to identify patterns and dervice a solution. Good for generating guesses for substituion method but can be unreliable.
Master theorem
Section titled “Master theorem”For decreasing functions
Section titled “For decreasing functions”Applies to below form:
Where and .
Here are the cases:
- If then
- If then
- If then
For dividing functions
Section titled “For dividing functions”Applies to recurrences of the below form:
Where , and .
Here are the cases:
- If then .
- If and then .
- If and then .
- If and then .
- If and then .
- If and then .