Consider the following recursive function: public static int mystery(int a, int b) { if (b == 0)

Question:

Consider the following recursive function:
public static int mystery(int a, int b)
{
if (b == 0) return 0;
if (b % 2 == 0) return mystery(a+a, b/2);
return mystery(a+a, b/2) + a;
}
What are the values of mystery(2, 25) and mystery(3, 11)? Given positive
integers a and b, describe what value mystery(a, b) computes. Then answer the
same question, but replace + with * and return 0 with return 1.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: