Question: Write recursive and iterative functions to compare by execution time. Use the below sample code to complete your implementation. #include // needed to perform C++

Write recursive and iterative functions to compare by execution time. Use the below sample code to complete your implementation.

#include // needed to perform C++ I/O

#include

#include //use clock_t start, stop;

using namespace std;

int rabbit(int n);

int IterativeRabbit(int n);

void writeBackward(string s);

void IterativewriteBackward(string s);

int binarySearch(const int anArray[], int first, int last, int target);

int IterativeBinarySearch(int array[], int size, int target);

const int SIZE = 40, SIZE2 = 100000;

int main()

{

cout

int res, array[SIZE2] = {};

//for binary search tree

for (int i = 0; i

{

array2[i] = 2 * i + 1;

}

string s = "recursive function calls by itself ";

clock_t start, stop;

//rabbit functions

start = clock();

res = rabbit(SIZE);

stop = clock();

cout

cout

cout

Write recursive and iterative functions to compare by execution time. Use the

***Part 1 The return value of the rabbit function is 102334155 Running time for the function is 4080 The return value of the IterativeRabbit function is 102334155 Running time for the function is writeBackaward("recursive function calls by itself ") returns | flesti yb sllac noitcnuf evisrucer Running time for the function is 2 Iterative writeBackaward("recursive function calls by itself ") returns flesti yb sllac noitcnuf evisrucer Running time for the function is 3 The return value of the binarySearch function is 1630 Running time for the function is o The return value of the IterativeBinarySearch function is 1630 Running time for the function is o

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!