Recursion
1.How to approach?
Bottom-Up Approach
Top-Down Approach
Half-and-Half Approach
Dynamic Programming & Memoization
2. What is the best case?
3. What is the recursive case?
4. Examples
1. Binary search
2.Find all subsets of a set (take Θ (2^n) time )
4.Same binary tree (take Θ (n) time )
binary tree
Algorithm
Code
5.Implement the paintfill feature from MS paint
Base case
Recursive case


6.Build a car given all tasks and each task's dependencies
Base case
Recursive case
Complexity
7.Find all anagrams of a given word
8.Find a path a rat can travel
Base case
Recursive case
9.Place 8 queens on a chessboard so they don't kill each other
Rule
Tips
Base case
Recursive case
Implementation
Place the queens
Check if current queen position is safe
Check the row and the column
Check the left diagonal
Check the right diagonal
Complexity
Last updated