Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

***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

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

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

Students also viewed these Databases questions

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago