Question: The solution strategy in recursion is to break up the problem and solve smaller instances of the same problem. Suppose you want to write the

  • The solution strategy in recursion is to break up the problem and solve smaller instances of the same problem. Suppose you want to write the recursive function eat for eating a sandwich, the parameter to the eat function is the sandwich.

void eat (sandwich)

{

If no sandwich left

print (done) // the base case ( termination condition)

else

{

Take a bite

eat (sandwich- bite) //repeat the same task on a smaller input

}

}

To ensure you understand the recursion, think of a task or an operation and clearly state it, then write a recursive function to complete the task

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!