levo

Recursion and Modular Programming

Recursive algorithms: factorial and Fibonacci

  • 3 things to know
  • Component 1

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

KDW to HAT.
decryptsencryptscompresses

Blank Blitz makes facts automatic

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

AThe two are not the same.
BOpen source refers to the availability of the code.
CMuch open source software is free of charge.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Backup means the copy of the data.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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