levo

Recursion and Modular Programming

Recursive algorithms: factorial and Fibonacci

  • 3 things to know
  • Component 1
Start revising · £5/month

Overview

Fibonacci sequence recursively and why the towers of Hanoi puzzle is naturally recursive.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

State the value of 5 factorial.

Process

Define the Fibonacci sequence recursively.

Process

List the first seven terms of the Fibonacci sequence starting from 1.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    State the value of 5 factorial.

    Model answer

    The value of 5 factorial is 120. The product is 5 × 4 × 3 × 2 × 1.

  2. 2

    Define the Fibonacci sequence recursively.

    Model answer

    The first two Fibonacci numbers are both 1. Every later term is the sum of the two terms before it.

  3. 3

    List the first seven terms of the Fibonacci sequence starting from 1.

    Model answer

    The first seven terms are 1, 1, 2, 3, 5, 8 and 13. Each term after the second is the sum of the previous two.

  4. 4

    Using base cases fib(1) = 1 and fib(2) = 1, how many calls in total does the simple recursive Fibonacci function make to evaluate fib(5)?

    Model answer

    Nine calls are made in total. The value returned is 5.

  5. 5

    Why is the simple recursive Fibonacci function inefficient?

    Model answer

    The same subproblems are recalculated many times because the two branches overlap. The number of calls grows exponentially with n.

  6. 6

    How can the repeated work in a recursive Fibonacci function be avoided?

    Model answer

    Results already calculated can be stored in an array and looked up when needed again. Memoisation is the name given to this technique.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Data Structures: Arrays, Records and Hash Tables
Stacks, Queues, Linked Lists and Trees
Boolean Logic and Simplification
Algorithms, Pseudo-Code and Programming Constructs

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

KDW to HAT.
decryptsencryptscompresses

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

Backup means the copy of the data.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Recursion and Modular Programming, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.