Question

Problem Statement

Read and understand “The Bigger Picture” section on page 337. Be ready to explain why or how the various solutions are different. After you get the code for “public class FibTester”, which starts on page 341 to work, experiment with different numbers (I recommend keeping n<=50). Copy paste your programs printed result into Excel. Use Excel to subtract the start time from the end time and calculate the time each version took. Sample is shown below. Explain how everything works step by step.

millsec n 40 millsec n-45 millsec millsec n-50 1.51181E+12 n30 2 3 fib1 832040 4 5 fib3 832040 1.51181E+12 1.51181E+12 1.51181E+12 0 fib1 102334155 0 fib1 1134903170 1 fib1 12586269025 1 1.51181E+12 1.51181E+12 1.51181E+12 1.51181E+12 0 fib3 102334155 0 fib3 1134903170 0 fib3 12586269025 1 1.51181E+12 1.51181E+12 1.51181E+12 1.51181E+12 7 fib2 832040 12 ib2 102334155 2,650 ib2 1134903170 20,824 fib2 12586269025 227,800 1.51181E+12 1.51181E+12 1.51181E+12 1.51181E+12

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

Algo 1 explanation:

It all starts with number 1 and 2.

1 + 2 = 3 is the next fib number achieved by initializing the first 2 numbers.

Thereafter previous 2 numbers are stored in variableshighest (3) and next_highest (2)and then sum of those two will be calculated in a loop for desired number of times. 2 + 3 = 5 (next fib number).

Similary 5 + 3 = 8 (next fib number).

Here, we are making use of results of previous fib number (which are already computed) and avoiding any recomputation (except 1 addition per fib number).

Algo3 - it is a recursive version of algo1.

Algo2 (fib2), it essentially calculates fib of a number by summing up fib of previous number and fib of 2nd previous number. A point to note here is that every time it calculates fib of a number, it needs to calculate fib of previous 2 numbers which also uses the same fib alogrithm.

Suppose we want to calcualte fib(6), logic is

fib(6) = fib(5) + fib(4)

fib(5) = fib(4) + fib(3) will be calculated separately for fib(5) (1st parameter) and

for fib(4) = fib(3) + fib(2) will be calculated separately for fib(4) (2nd parameter)

Note: Even though we have computed fib(4) for 2nd parameter, it again needs to be recomputed for fib(5) as well since we are not storing any fib computation values. Now imagine this for larger numbers ! This is the reason, the time taken for larger numbers increases exponentially.

Add a comment
Know the answer?
Add Answer to:
Problem Statement Read and understand “The Bigger Picture” section on page 337. Be ready to explain...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone help and explain this?? Workshop 3 Problems Student Q Search Sheet Calibri (Body) ,...

    Can someone help and explain this?? Workshop 3 Problems Student Q Search Sheet Calibri (Body) , 12 - A- A = = = 0 5p Wrap Text Σ AutoSum' ΑΡ. General $ % Merge & Center ) 0.00 Conditional Format Formatting as Table Cell Styles Insert Delete Format Clear Sort & Filter Home Insert Page Layout Formulas Data Review View Xcut Copy Paste Format BI U DA = = G24 x fx A B C D E F G H...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

  • You are required to prepare the following financial statements using Excel. USE EXCEL EFFICIENTLY AND EFFECTIVELY...

    You are required to prepare the following financial statements using Excel. USE EXCEL EFFICIENTLY AND EFFECTIVELY TO COMPLETE THIS PROJECT (cell references, formulas, etc.). File Home Insert Draw Page Layout Formulas Data Review View Help Share Comments + X I = n - A A ab Wrap Text General AY Arial 10 BIUS AutoSum Film Clear Paste A Merge Center $ -% -3 LI Conditional Format as Cell Formatting Table Styles Styles Insert Delete Format Ideas Sort & Find &...

  • AutoSave Off HD Unit 1 Project Fall 2020 (2) - Protected View - Excel guada gucci...

    AutoSave Off HD Unit 1 Project Fall 2020 (2) - Protected View - Excel guada gucci GG File Home Insert Draw Page Layout Formulas Data Review View Help O Search Share Comments i PROTECTED VIEW Be careful—files from the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View. Enable Editing X H16 fox 1 J к L N O P P Q R S т U A B с D E F G...

  • 1 L, as a dynamical system (Notes from Assignment #2) We take our definition of dynamical system ...

    1 L, as a dynamical system (Notes from Assignment #2) We take our definition of dynamical system to be an "object" along with a specific set of modifications that can be performed (dynamically) upon this object. In this case, the object is a bi-infinite straight road with a lamp post at every street corner and a marked lamp (the position of the lamplighter). There are two possible types of modifications: the lamplighter can walk any distance in either direction from...

  • just one example/demonstration! Data needed to be calculated is in highlighted in green boxes. And I...

    just one example/demonstration! Data needed to be calculated is in highlighted in green boxes. And I highlighted in red an equation (not sure if thats what you use to calculate it) And ignore the lab instructions on completeing a graph!! I already know how to do that in excel, just curious how Ln (relative rate) and 1/T in K^-1 is calculated by hand* here is the rest of that lab leading up to the question as I know its typically...

  • Read the attached article and answer the following questions. 1. What is the role of potassium...

    Read the attached article and answer the following questions. 1. What is the role of potassium in blood pressure? 2. Looking back at last weeks Super Tracker report - do you meet the 4700mg daily target for potassium? 3. Do you meet the 400mg daily target for magnesium? 4. Research shows that hypertension and type 2 diabetes can be prevented by dietary choices. List 3 ways that employers, government, doctors, etc. (you can use another group ) can either motivate...

  • Please read the article bellow and discuss the shift in the company's approach to genetic analysis....

    Please read the article bellow and discuss the shift in the company's approach to genetic analysis. Please also discuss what you think about personal genomic companies' approaches to research. Feel free to compare 23andMe's polices on research with another company's. Did you think the FDA was right in prohibiting 23andMe from providing health information? These are some sample talking points to get you thinking about the ethics of genetic research in the context of Big Data. You don't have to...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

  • Please answer all the blanks (volume if H2 and everything in analysis). TIA! Data 5 1...

    Please answer all the blanks (volume if H2 and everything in analysis). TIA! Data 5 1 oong 0.00 10.5ml 2 o.olag 0.00 11.0 Trial 3 o.org 0.00 12.00 o Daag o.albg 0.00 10.0 ml 11.5ml Mass of Mg (g) Initial volume of Syringe (mL) Final volume of Syringe (mL) Volume of H (mL) Barometric pressure (torr) Ambient temperature (°C) Vapor pressure of H2O (torr) 779.314har 23. Oi 21.0 forr TA.314tar 23.0c 179.3 14ton 23.0¢ 779.314 ton 23.0c 779.31472 23.0c 21.0...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT