Download presentation
Presentation is loading. Please wait.
1
Intro to Recursion
2
Fibonacci Numbers (1) f0 = 1 f1 = 1 f2 = 1 + 1 = 2 f3 = 2 + 1 = 3
In general: fn = fn-1 + fn-2 for n ≥ 2
3
Fibonacci Numbers (2) The Fibonacci number problem has the recursive property The problem fibonacci(n) (= fn) can be solved using the solution of two smaller problem: The base (simple) cases n = 0 and n = 1 of the Fibonacci problem can be solved readily:
4
Fibonacci Numbers (3) 1. Which smaller problem do we use to solve fibonacci(n):
5
Fibonacci Numbers (4) 2. How do we use the solution sol1 to solve fibonacci(n) 3. Because we used fibonacci(n−2), we will need the solution for 2 base cases:
6
Fibonacci Numbers (5)
7
The recursive binary search algorithm(1)
You are given a sorted array (of numbers) Locate the array element that has the value x
8
The recursive binary search algorithm(2)
Locate the array element that has the value 27
9
The recursive binary search algorithm(3)
Locate the array element that has the value 28
10
The recursive binary search algorithm(4)
11
The recursive binary search algorithm(5)
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.