Binary search on a sorted array of n elements is:
Recursion
Factorial, the English ruler, binary search and its analysis, linear, tail, binary and multiple recursion, recursive squaring, and Fibonacci (bad vs. good).
How to read this page
Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.
All 31 slides
- 1 Recursion
- 2 when we loop
- 3 forward calls
- 4 runtime
- 5 Example: English Ruler
- 6 Using Recursion
- 7 Recursive Drawing Method
- 8 A Recursive Method for Drawing Ticks on an English Ruler
- 9 17
- 10 Visualizing Binary Search
- 11 Slide 11
- 12 Analyzing Binary Search
- 13 Linear Recursion
- 14 linear I
- 15 Example of Linear Recursion
- 16 swap www
- 17 Defining Arguments for Recursion
- 18 I
- 19 i
- 20 Recursive Squaring Method
- 21 Analysis
- 22 Tail Recursion
- 23 Binary Recursion
- 24 n
- 25 Computing Fibonacci Numbers
- 26 Analysis
- 27 A Better Fibonacci Algorithm
- 28 Jan
- 29 Algorithm for Multiple Recursion
- 30 Example
- 31 Visualizing PuzzleSolve
Example: English Ruler
Notes
English ruler: drawInterval(L) = drawInterval(L−1), a tick of length L, drawInterval(L−1).
Visualizing Binary Search
Notes
Binary search halves the search range each call.
Analyzing Binary Search
Exam angle
Linear Recursion
Notes
Linear recursion: at most one recursive call per invocation (sum, reverse array).
Recursive Squaring Method
Notes
Recursive squaring: xⁿ = (x^(n/2))² → O(log n) multiplications.
Computing Fibonacci Numbers
Notes
Naïve Fibonacci (binary recursion) is exponential: it recomputes the same values.
Exam angle
The naïve recursive Fibonacci runs in linear time.
- Exponential: about φⁿ calls.