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
#include
#include
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
***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 oStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started