Question: Write a program in C++ which compares the execution time of Recursive and Iterative algorithms using the stl stack template of the Fibonacci sequence using

Write a program in C++ which compares the execution time of Recursive and Iterative algorithms using the stl stack template of the Fibonacci sequence using a function pointer. The Fibonacci sequence is defined as follows:

fn = fn-1 + fn-2 where n > 1

f1= 1

f0 = 0.

Compare the execution time of the above approaches for n = 25.

The output should look as follows:

Your name

CIS 5

Spring, 2018

The sequence

0, 1, 1, 2, 3, 5 ......

Recursive 0.001

Iterative .0.002

Use the following high resolution Windows 32 API timer in linked library winmm.lib.

#include

#include

#include

int main (void)

{

float time;

//defines start, finish, duration

DWORD start, finish, duration, pause;

//start the timer

if(timeBeginPeriod(1) = TIMERR_NOERROR)

{

//get the starting time

start = timeGetTime();

//write iterative code here using stack template class library to get the fibonacci sequence

//Get the ending time

finish = timeGetTime();

//calculate duration

duration = finish - start;

}

//stop the timer

timeEndPeriod(1);

//calculate the time in seconds

time = (float)duration/1000;

//print the time and pause

cout << "process took" <

cin>>pause;

return 1;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!