Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

As sugggested by its name, the efficiency of the fl bS 1 ow function in Exercise 18.17 is suspect. (a) Try mm1ing fi bSl ow(

As sugggested by its name, the efficiency of the fl bS 1 ow function in Exercise 18.17 is suspect.

(a) Try mm1ing fi bSl ow( 25) and then fi bSl ow( 50) on your system and see how long these computations take. What causes this inefficiency?

(b) An alternative definition of the Fibonacci calculation can be made in the following way. Define a function fib P a i r that generates a two-element pair that contains the nth Fibonacci number and its successor. Define another function fi bNext that generates the next such tuple from the cmTent one. Then the Fibonacci function itself, optimistically named fi bFast, can be defined by selecting the first member of the nth fib P a i r. In Haskell, this is written as follows:

image

Tty mnnmg the function fib Fast to compute the 25th and 50th Fibonacci numbers. It should be considerably more efficient than fi bSl ow. Explain.

(c) Prove by induction that Vn 2: 0 :fibFast(n) =fihSlow(n).

> fibPair n 10-0 > In>0 > > fibNext (n.n) (n.afn) >fibfast nfst(fibPair(n)) - (1.1) fibNext(fibPair(n-1))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

a The efficiency of the Fibonacci function can be affected by the implementation method and the algorithm used Running the functions fibSlow25 and fib... 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

Step: 3

blur-text-image

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Explain why global financial markets are so important to Canadians.

Answered: 1 week ago