Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

How many additions are used by the recursive and iterative algorithms given in Algorithm 7 and 8, respectively, to find the Fibonacci numberf7 ?

Short Answer

Expert verified

Algorithm 7 will do 20 additions and algorithm 8 will do 7 additions.

Step by step solution

01

Algorithms 7 and 8

Algorithm 7 is given as,

Procedure Fibonacci ( n : nonnegative integer)

If n = 0 then return 0

Else if n = 1then return 1

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

{Output is fibonacci (n) }.

Algorithm 8 is given as:

Procedure iterative Fibonacci (n : nonnegative integer)

If n = 0 then return 0

Else

x : = 0

y : = 1

For i : = 0 to n - 1

z : = x + y

y : = z

Return y

{Output is nth the Fibonacci number}.

02

Finding the number of addition in algorithm 7 to find the Fibonacci number f7

Aim: To find the Fibonacci number.

By using Algorithm 7,

f7=f6+f5=f5+f4+f4+f3=f4+f3+2f3+2f2+f2+f1=f4+3f3+3f2+f1

Further simplified as,

f7=f3+f2+3f3+3f2+f1=4f3+4f2+f1=4f2+f1+4f1+f0+f1=4f2+9f1+4f0f7=4f1+f0+9f1+4f0=13f1+8f0

So, there are 21 terms.

Therefore, Algorithm 7 will do 20 addition.

03

Finding the number of addition in algorithm 8 to find the Fibonacci number f7

Now, algorithm 8 is an iterative process.

So, to find f7, we have to create the loop at least 7 times.

Therefore, Algorithm 8 will do 7 addition.

Hence, algorithm 7 will do 20 addition and algorithm 8 will do 7 addition.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

See all solutions

Recommended explanations on Math Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free