Tech Jobs Interviews Preparation
GeekGap Webinar #2
Presented by Junior Teudjio @junteudjio
02nd November 2019
Schedule
Algorithms & Data Structures
- What is an recursion?
- How to solve a recursive problem?
- Case study 1: Factorial
- Case study 2: Recursive power
- Case study 3: Recursive sum
- Case study 4: Recursive reverse
- Case study 5: Binary search
- Case study 6: Fibonacci
- Extra: Closing remarks on recursion
Algorithms & Data Structures
What is recursion?
A method of solving a problem where the solution depends on
solutions to smaller instances of the same problem
~wikipedia
Problem:
Find the disk usage of a path.
Algorithms & Data Structures
How to solve a recursive problem?
1. Solve the smallest/easiest instance of the problem
2.
- Break the original problem into subproblems
- Assume you had magical function to solve them
3. Combine the subproblems’ solutions to get the solution
Problem:
Find the disk usage of a path.
Algorithms & Data Structures
How to solve a recursive problem?
CODING TIME
Problem:
Find the disk usage of a path.
Algorithms & Data Structures
How to solve a recursive problem?
SOLUTION
Problem:
Find the disk usage of a path.
Algorithms & Data Structures
Topic: Recursive algorithms
QUESTIONS TIME
Coming next: Case Study 1
‘It's not that I'm so smart,
it's just that
I stay with problems longer.’
Albert Einstein
Algorithms & Data Structures
Case study 1: Factorial
1. Solve the smallest/easiest instance of the problem
2.
- Break the original problem into subproblems
- Assume you had magical function to solve them
3. Combine the subproblems’ solutions to get the solution
Problem:
Write a recursive function to compute the
factorial of a number.
Problem Understanding:
Algorithms & Data Structures
Case study 1: Factorial
Problem:
Write a recursive function to compute the
factorial of a number.
CODING TIME
Algorithms & Data Structures
Case study 1: Factorial
Problem:
Write a recursive function to compute the
factorial of a number.
SOLUTION
Algorithms & Data Structures
Case study 1: Factorial
Problem:
Write a recursive function to compute the
factorial of a number.
MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
‘talent is good
practice is better
passion is best’
Frank Lloyd Wright
Algorithms & Data Structures
Topic: Recursive algorithms
QUESTIONS TIME
Coming next: Case Study 2
Algorithms & Data Structures
Case study 2: Recursive power
1. Solve the smallest/easiest instance of the problem
2.
- Break the original problem into subproblems
- Assume you had magical function to solve them
3. Combine the subproblems’ solutions to get the solution
Problem:
Write a recursive function to compute x to
the power of n (with n>=0)
Problem Understanding:
Algorithms & Data Structures
Case study 2: Recursive power
Problem:
Write a recursive function to compute x to
the power of n (with n>=0)
CODING TIME
Algorithms & Data Structures
Case study 2: Recursive power
Problem:
Write a recursive function to compute x to
the power of n (with n>=0)
SOLUTION
Algorithms & Data Structures
Case study 2: Recursive power
Problem:
Write a recursive function to compute x to
the power of n (with n>=0)
MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
Algorithms & Data Structures
Case study 2: Recursive power
Problem:
Write a recursive function to compute x to
the power of n (with n>=0)
OPTIMIZED SOLUTION
‘The best theory is inspired by
practice.’
Donald Knuth
Algorithms & Data Structures
Topic: Recursive algorithms
QUESTIONS TIME
Coming next: Case Study 3
Algorithms & Data Structures
Case study 3: Recursive reverse
1. Solve the smallest/easiest instance of the problem
2.
- Break the original problem into subproblems
- Assume you had magical function to solve them
3. Combine the subproblems’ solutions to get the solution
Problem:
Write a recursive function to reverse a list
(L) in-place
Problem Understanding:
Algorithms & Data Structures
Case study 3: Recursive reverse
Problem:
Write a recursive function to reverse a list
(L) in-place
CODING TIME
Algorithms & Data Structures
Case study 3: Recursive reverse
Problem:
Write a recursive function to reverse a list
(L) in-place
SOLUTION
Algorithms & Data Structures
Case study 3: Recursive reverse
Problem:
Write a recursive function to reverse a list
(L) in-place
MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
Algorithms & Data Structures
Topic: Recursive algorithms
QUESTIONS TIME
Coming next: Case Study 4
‘stay hungry, stay foolish’
Steve Jobs
Algorithms & Data Structures
Case study 4: binary search
1. Solve the smallest/easiest instance of the problem
2.
- Break the original problem into subproblems
- Assume you had magical function to solve them
3. Combine the subproblems’ solutions to get the solution
Problem:
Write a recursive function to search of k in
A, return True if found, False otherwise
Problem Understanding:
Algorithms & Data Structures
Case study 4: binary search
Problem:
Write a recursive function to search of k in
A, return True if found, False otherwise
CODING TIME
Algorithms & Data Structures
Case study 4: binary search
Problem:
Write a recursive function to search of k in
A, return True if found, False otherwise
VERY BAD SOLUTION
Algorithms & Data Structures
Case study 4: binary search
Problem:
Write a recursive function to search of k in
A, return True if found, False otherwise
SOLUTION
Algorithms & Data Structures
Case study 4: binary search
Problem:
Write a recursive function to search of k in
A, return True if found, False otherwise
MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
Algorithms & Data Structures
Topic: Recursive algorithms
QUESTIONS TIME
Coming next: Case Study 5
‘It's not that I'm so smart,
it's just that
I stay with problems longer.’
Albert Einstein
Algorithms & Data Structures
Case study 5: fibonacci
1. Solve the smallest/easiest instance of the problem
2.
- Break the original problem into subproblems
- Assume you had magical function to solve them
3. Combine the subproblems’ solutions to get the solution
Problem:
Write a recursive function to compute the
fibonacci of a number n.
Problem Understanding:
Algorithms & Data Structures
Case study 5: fibonacci
Problem:
Write a recursive function to compute the
fibonacci of a number n.
CODING TIME
Algorithms & Data Structures
Case study 5: fibonacci
Problem:
Write a recursive function to compute the
fibonacci of a number n.
SOLUTION
Algorithms & Data Structures
Case study 5: fibonacci
Problem:
Write a recursive function to compute the
fibonacci of a number n.
MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
Algorithms & Data Structures
Topic: Recursive algorithms
QUESTIONS TIME
Coming next: Closing remarks on recursion
‘talent is good
practice is better
passion is best’
Frank Lloyd Wright
Algorithms & Data Structures
Closing remarks on recursion
Remark 1:
Beware of RecursionError: maximum recursion depth exceeded
Algorithms & Data Structures
Closing remarks on recursion
Remark 2:
Take advantage of tail recursion
Algorithms & Data Structures
Closing remarks on recursion
Remark 2:
Take advantage of memoization
Algorithms & Data Structures
Topic: Recursive algorithms
QUESTIONS TIME
‘stay hungry, stay foolish’
Steve Jobs
End of GeekGap WEBINAR #2
All the resources (slides, video, code) will be published on the site:
www.geekgap.io
NEXT WEBINAR
16 November 2019 | 17:00 - 20:00 (GMT)
Schedule:
Part 1: Algorithms & Data Structures
- Hash Tables
- Intro to Dynamic programming
Part 2: System Design
- REST APIs
- Case Study: Django Rest Framework
- Caching
- Case Study: Redis
Thanks!

Recursive algorithms in depth - Geek gap webinar #2

  • 1.
    Tech Jobs InterviewsPreparation GeekGap Webinar #2 Presented by Junior Teudjio @junteudjio 02nd November 2019
  • 2.
    Schedule Algorithms & DataStructures - What is an recursion? - How to solve a recursive problem? - Case study 1: Factorial - Case study 2: Recursive power - Case study 3: Recursive sum - Case study 4: Recursive reverse - Case study 5: Binary search - Case study 6: Fibonacci - Extra: Closing remarks on recursion
  • 3.
    Algorithms & DataStructures What is recursion? A method of solving a problem where the solution depends on solutions to smaller instances of the same problem ~wikipedia Problem: Find the disk usage of a path.
  • 4.
    Algorithms & DataStructures How to solve a recursive problem? 1. Solve the smallest/easiest instance of the problem 2. - Break the original problem into subproblems - Assume you had magical function to solve them 3. Combine the subproblems’ solutions to get the solution Problem: Find the disk usage of a path.
  • 5.
    Algorithms & DataStructures How to solve a recursive problem? CODING TIME Problem: Find the disk usage of a path.
  • 6.
    Algorithms & DataStructures How to solve a recursive problem? SOLUTION Problem: Find the disk usage of a path.
  • 7.
    Algorithms & DataStructures Topic: Recursive algorithms QUESTIONS TIME Coming next: Case Study 1 ‘It's not that I'm so smart, it's just that I stay with problems longer.’ Albert Einstein
  • 8.
    Algorithms & DataStructures Case study 1: Factorial 1. Solve the smallest/easiest instance of the problem 2. - Break the original problem into subproblems - Assume you had magical function to solve them 3. Combine the subproblems’ solutions to get the solution Problem: Write a recursive function to compute the factorial of a number. Problem Understanding:
  • 9.
    Algorithms & DataStructures Case study 1: Factorial Problem: Write a recursive function to compute the factorial of a number. CODING TIME
  • 10.
    Algorithms & DataStructures Case study 1: Factorial Problem: Write a recursive function to compute the factorial of a number. SOLUTION
  • 11.
    Algorithms & DataStructures Case study 1: Factorial Problem: Write a recursive function to compute the factorial of a number. MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
  • 12.
    ‘talent is good practiceis better passion is best’ Frank Lloyd Wright Algorithms & Data Structures Topic: Recursive algorithms QUESTIONS TIME Coming next: Case Study 2
  • 13.
    Algorithms & DataStructures Case study 2: Recursive power 1. Solve the smallest/easiest instance of the problem 2. - Break the original problem into subproblems - Assume you had magical function to solve them 3. Combine the subproblems’ solutions to get the solution Problem: Write a recursive function to compute x to the power of n (with n>=0) Problem Understanding:
  • 14.
    Algorithms & DataStructures Case study 2: Recursive power Problem: Write a recursive function to compute x to the power of n (with n>=0) CODING TIME
  • 15.
    Algorithms & DataStructures Case study 2: Recursive power Problem: Write a recursive function to compute x to the power of n (with n>=0) SOLUTION
  • 16.
    Algorithms & DataStructures Case study 2: Recursive power Problem: Write a recursive function to compute x to the power of n (with n>=0) MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
  • 17.
    Algorithms & DataStructures Case study 2: Recursive power Problem: Write a recursive function to compute x to the power of n (with n>=0) OPTIMIZED SOLUTION
  • 18.
    ‘The best theoryis inspired by practice.’ Donald Knuth Algorithms & Data Structures Topic: Recursive algorithms QUESTIONS TIME Coming next: Case Study 3
  • 19.
    Algorithms & DataStructures Case study 3: Recursive reverse 1. Solve the smallest/easiest instance of the problem 2. - Break the original problem into subproblems - Assume you had magical function to solve them 3. Combine the subproblems’ solutions to get the solution Problem: Write a recursive function to reverse a list (L) in-place Problem Understanding:
  • 20.
    Algorithms & DataStructures Case study 3: Recursive reverse Problem: Write a recursive function to reverse a list (L) in-place CODING TIME
  • 21.
    Algorithms & DataStructures Case study 3: Recursive reverse Problem: Write a recursive function to reverse a list (L) in-place SOLUTION
  • 22.
    Algorithms & DataStructures Case study 3: Recursive reverse Problem: Write a recursive function to reverse a list (L) in-place MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
  • 23.
    Algorithms & DataStructures Topic: Recursive algorithms QUESTIONS TIME Coming next: Case Study 4 ‘stay hungry, stay foolish’ Steve Jobs
  • 24.
    Algorithms & DataStructures Case study 4: binary search 1. Solve the smallest/easiest instance of the problem 2. - Break the original problem into subproblems - Assume you had magical function to solve them 3. Combine the subproblems’ solutions to get the solution Problem: Write a recursive function to search of k in A, return True if found, False otherwise Problem Understanding:
  • 25.
    Algorithms & DataStructures Case study 4: binary search Problem: Write a recursive function to search of k in A, return True if found, False otherwise CODING TIME
  • 26.
    Algorithms & DataStructures Case study 4: binary search Problem: Write a recursive function to search of k in A, return True if found, False otherwise VERY BAD SOLUTION
  • 27.
    Algorithms & DataStructures Case study 4: binary search Problem: Write a recursive function to search of k in A, return True if found, False otherwise SOLUTION
  • 28.
    Algorithms & DataStructures Case study 4: binary search Problem: Write a recursive function to search of k in A, return True if found, False otherwise MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
  • 29.
    Algorithms & DataStructures Topic: Recursive algorithms QUESTIONS TIME Coming next: Case Study 5 ‘It's not that I'm so smart, it's just that I stay with problems longer.’ Albert Einstein
  • 30.
    Algorithms & DataStructures Case study 5: fibonacci 1. Solve the smallest/easiest instance of the problem 2. - Break the original problem into subproblems - Assume you had magical function to solve them 3. Combine the subproblems’ solutions to get the solution Problem: Write a recursive function to compute the fibonacci of a number n. Problem Understanding:
  • 31.
    Algorithms & DataStructures Case study 5: fibonacci Problem: Write a recursive function to compute the fibonacci of a number n. CODING TIME
  • 32.
    Algorithms & DataStructures Case study 5: fibonacci Problem: Write a recursive function to compute the fibonacci of a number n. SOLUTION
  • 33.
    Algorithms & DataStructures Case study 5: fibonacci Problem: Write a recursive function to compute the fibonacci of a number n. MEMORY COMPLEXITY ANALYSISTIME COMPLEXITY ANALYSIS
  • 34.
    Algorithms & DataStructures Topic: Recursive algorithms QUESTIONS TIME Coming next: Closing remarks on recursion ‘talent is good practice is better passion is best’ Frank Lloyd Wright
  • 35.
    Algorithms & DataStructures Closing remarks on recursion Remark 1: Beware of RecursionError: maximum recursion depth exceeded
  • 36.
    Algorithms & DataStructures Closing remarks on recursion Remark 2: Take advantage of tail recursion
  • 37.
    Algorithms & DataStructures Closing remarks on recursion Remark 2: Take advantage of memoization
  • 38.
    Algorithms & DataStructures Topic: Recursive algorithms QUESTIONS TIME ‘stay hungry, stay foolish’ Steve Jobs
  • 39.
    End of GeekGapWEBINAR #2 All the resources (slides, video, code) will be published on the site: www.geekgap.io NEXT WEBINAR 16 November 2019 | 17:00 - 20:00 (GMT) Schedule: Part 1: Algorithms & Data Structures - Hash Tables - Intro to Dynamic programming Part 2: System Design - REST APIs - Case Study: Django Rest Framework - Caching - Case Study: Redis Thanks!