Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Assignment

Part 1

The Fibonacci sequence is defined as follows. If Fib(k) denotes the kth number in the Fibonacci sequence, then, for non-negative positions in the sequence,

Fib(1) = 1

Fib(2) = 1

Fib(n) = Fib(n-1) + Fib(n-2)

In English, we may say that a Fibonacci number is ***** sum of its two immediate predecessors, except for the first two Fibonacci numbers, which are both 1.

Implement a class called Fibonacci. This class should provide a single class method (static) with the following signature:

double Fibonacci::getNthFibonacciRecursively(int n)

which should do exactly that. It calculates and returns the nth Fibonacci number and does so recursively, by invoking itself for certain input values of n. Note that its parameter n is an integer, but its return value is a double. Why? Answer this question in a single short sentence within the header comment of this method.

From your main(), issue calls to Fibonacci for various values of n in the range 1 to 10 and make sure that the output concurs with your paper-and-pencil calculation. Handle the case for n <= 0 by returning an invalid value and note it in the documentation of the function (within comments). For example you'd say that the function will return -1 for n <= 0. That's perfectly acceptable.

Part 2

In this part of the answer you are going to profile your function. But rather than use the system profiler which was not part of this course's instruction, you will build and use a very simple measurement tool.

Windows users:

The following function returns a timestamp in milliseconds since the system started.

double getMillis() {

return (double) getTickCount();

}

To use it in your code, include the system header "WinSock2.h" as follows, immediately following your standard header declarations:

#include

The exact value returned by getMillis() doesn't matter for the purposes of this question. What matters is the difference in the return value between two successive calls to the function. If you call it at times A and B, then the difference between the two return values is the number of milliseconds elapsed. You are going to call this function to measure something about your Fibonacci function.

In your main(), you must call Fibonacci::getNthFibonacciRecursively(n) in a loop with progressively increasing values of n from 1 to 40. You must call getMillis() both immediately before and after your call for the nth Fibonacci number. E.g.

double timeStamp1 = getMillis();

Fibonacci::getNthFibonacci(n);

double timeStamp2 = getMillis();

double millisToCompute = timeStamp2 - timeStamp1;

•For each n, you must print the time taken to compute your result.

•You must study the relation between n and the time taken and predict the time it will take to calculate Fibonacci(100). It is important that you don't actually calculate the 100th Fibonacci number (especially not using your recursive function). You must simply study the time taken to calculate the first 40 numbers in the sequence and predict the time it will take to calculate the 100th number. Report this time in the most intuitive and appropriate time unit (whether it's microseconds, milliseconds, minutes or hours is up to you, but don't say it will take********** milliseconds. Convert this into a time unit humans can naturally relate to.

•You can use a method of your choice to do the prediction - Eyeballing and intuiting, plotting on a sheet of graph paper, using a spreadsheet program if you have one, or using WolframAlpha.com. For example, at wolframalpha.com, you can enter the "Exponential fit: num1, num2, num3, ..." and it will try to infer an exponential equation to calculate the numbers as a function of its position in the input sequence.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92019160
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Programming Language

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As