Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part VII: Recursion & Iterators (16 points) 1. Write an algorithm which would re

ID: 3699682 • Letter: P

Question

Part VII: Recursion & Iterators (16 points) 1. Write an algorithm which would recursively calculate a Fibonacci series. Remember that each number is the sum of the prior 2 numbers. (4 points) 2. Show how the algorithm would process Fib(4). (2 points) 3. How many base cases are there and what are the base cases? 4. Assume there is a list, L, (singly-linked) which supports an iterator, p. Each node contains an integer value. Using the iterator, write a routine, in either pseudocode or C++, to add all of the (4 points) values in all of the nodes.

Explanation / Answer

If you post more than 1 question, as per chegg guidelines I have to solve only first question.

Ques 1.

function fibonacci(n)

BEGIN

    // first two terms in the series are 1

    if n == 1 or n == 2

    BEGIN

         return 1

    END

    // recursively get the (n-1) th and (n-2)th term

    return fibonacci( n - 1 ) + fibonacci( n - 2 )


END

Ques 3.

There are two base cases, when n = 1 and when n = 2. It is because the first two terms in the series are 1.