I have put ??? where I need the answers. Thanks for ANY help. int new_largest(co
ID: 3616472 • Letter: I
Question
I have put ??? where I need the answers.Thanks for ANY help.
int new_largest(const int list[], int lowerIndex, intupperIndex)
{
int max1, max2, half_items;
if (lowerIndex == upperIndex)
return list[lowerIndex];
half_items = (upperIndex - lowerIndex + 1) / 2;
max1 = new_largest(list, lowerIndex, lowerIndex +half_items-1);
max2 = new_largest(list, lowerIndex + half_items,upperIndex);
if (max1 > max2)
return max1;
else
returnmax2;
}
Function largest() is invoked ??? times when largest(list, 0, 7) isexecuted,
whereas function new_largest() is invoked ??? times whennew_largest(list, 0, 7) is executed.
Max recursion depth reached while computing largest(list, 0, 63) is???,
whereas max recursion depth reached while computingnew_largest(list, 0, 63) is ???.
Explanation / Answer
now it's complete please rate - thanks #include #include using namespace std; int new_largest(const int list[], int lowerIndex, intupperIndex,int &count) { int max1, max2, half_items; count++; if (lowerIndex == upperIndex) return list[lowerIndex]; half_items = (upperIndex - lowerIndex + 1) / 2; max1 = new_largest(list, lowerIndex, lowerIndex +half_items-1,count); max2 = new_largest(list, lowerIndex + half_items,upperIndex,count); if (max1 > max2) return max1; else returnmax2; } int largest(const int list[], int lowerIndex, int upperIndex,int&count) { int max; count++; if(lowerIndex == upperIndex) // the size of the sublist is 1 return list[lowerIndex]; else { max = largest(list, lowerIndex + 1,upperIndex,count); if(list[lowerIndex] >= max) return list[lowerIndex]; else return max; } } int main() {int count,i; int list[100]; srand(time(0)); for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.