Question: ( 2 a ) Write the recurrence relation for the following function. void SingSong ( int n ) { if ( n = = 0

(2a) Write the recurrence relation for the following function.
void SingSong(int n)
{
if(n ==0){
cout <<"No more bottles of Sarsaparilla on the wall!
";
return;
}
for(int i =0; i < n: i++){
cout << "clap ";
}
cout << endl;
cout << n <<" bottles of Sarsaparilla on the wall, "<< n <<" bottles of Sarsaparilla. ";
cout << "You take one down, pass it around. "<< n-1<<" bottles of Sarsaparilla on the wall.
";
SingSong(n-1);
}
2b.) Use repeated substitution to show the what the recurrence looks like after two substitutions.
2c.) Extra Credit. During substitution, don't combine any terms that look like (n-i). Do you notice a series like pattern? See if you can create a series in the equation, solve for it in closed form, and use it to solve for the recurrence.
2d.) Extra Credit. Prove your equation from part (2c) is correct using induction. (As done in our lecture video)

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!