Question: Using Java.Find the non-recursive version of the following recursive function. Is a recursive approach better than a non-recursive approach? What is the time complexity of
Using Java.Find the non-recursive version of the following recursive function. Is a recursive approach better than a non-recursive approach? What is the time complexity of both functions, explain.
static long tough(int x, int y) {
if (x < y) return tough(y,x);
else if (y <= 0) return 1;
else { if (x > y) return tough(x - 1, y) + tough (x-1, y-1);
else //it means x == y return tough(x-1, y-1); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
