Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Recursive Algorithm for Fibonacci Numbers. procedure fibonacci(n: nonnegative integer) if n = 0 then return 0 else if n = 1 then return 1

image text in transcribedimage text in transcribedimage text in transcribed

A Recursive Algorithm for Fibonacci Numbers. procedure fibonacci(n: nonnegative integer) if n = 0 then return 0 else if n = 1 then return 1 else return fibonacci(n - 1) + fibonacci(n - 2) {output is fibonacci(n)} An Iterative Algorithm for Computing Fibonacci Numbers. procedure iterative fibonacci(n: nonnegative integer) if n = 0 then return 0 else x: = 0 y: = 1 for i:= 1 to n - 1 z: = x + y x:= y y:= z return y {output is the nth Fibonacci number} Consider Algorithm 7 on page 365 which finds the nth Fibonacci number, f_n, recursively, for n greaterthanorequalto 0. Let T(n) be the number of additions done by the algorithm to compute f_n. Do the following: (a) Give a recursive definition for T(n). (b) Use Strong Induction to establish that T(n) = f_n + 1 - 1, for n greaterthanorequalto 0. (c) Determine the number of additions done by Algorithm 7 to compute f_10 and compare this to the number of additions done by Algorithm 8. A Recursive Algorithm for Fibonacci Numbers. procedure fibonacci(n: nonnegative integer) if n = 0 then return 0 else if n = 1 then return 1 else return fibonacci(n - 1) + fibonacci(n - 2) {output is fibonacci(n)} An Iterative Algorithm for Computing Fibonacci Numbers. procedure iterative fibonacci(n: nonnegative integer) if n = 0 then return 0 else x: = 0 y: = 1 for i:= 1 to n - 1 z: = x + y x:= y y:= z return y {output is the nth Fibonacci number} Consider Algorithm 7 on page 365 which finds the nth Fibonacci number, f_n, recursively, for n greaterthanorequalto 0. Let T(n) be the number of additions done by the algorithm to compute f_n. Do the following: (a) Give a recursive definition for T(n). (b) Use Strong Induction to establish that T(n) = f_n + 1 - 1, for n greaterthanorequalto 0. (c) Determine the number of additions done by Algorithm 7 to compute f_10 and compare this to the number of additions done by Algorithm 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago