Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 shows that it is possible to compute x n in O(log N) time. This fact in turn makes it possible to write an

Exercise 1 shows that it is possible to compute x n in O(log N) time. This fact in turn makes it possible to write an implementation of the function fib(n) that also runs in O(log N) time, which is much faster than the traditional iterative version. To do so, you need to rely on the somewhat surprising fact that the Fibonacci function is closely related to a value called the golden ratio, which has been known since the days of Greek mathematics. The golden ratio, which is usually designated by the Greek letter phi (), is defined to be the value that satisfies the equation

Because this is a quadratic equation, it actually has two roots. If you apply the quadratic formula, you will discover that these roots are

In 1718, the French mathematician Abraham de Mover discovered that the nth Fibonacci number can be represented in closed form as

Moreover, because n is always very small, the formula can be simplified to

rounded to the nearest integer. Use this formula and the raiseToPower function from exercise 1 to write an implementation of fib(n) that runs in O(log N) time. Once you have verified empirically that the formula seems to work for the first several terms in the sequence, use mathematical induction to prove that the formula

actually computes the nth Fibonacci number.

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

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

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions

Question

In Problems 3542, find v. v = 6i + 2j

Answered: 1 week ago