Which expression represents the action of the followingrecursive method., if onl
ID: 3608230 • Letter: W
Question
Which expression represents the action of the followingrecursive method., if only positive parameters are passed to themethod? public int guess(int a, int b) { if(a == 0) return 1; else return b + guess(a - 1, b); } a)a + b b)a * b c)a^b d)b^a e)b! Which expression represents the action of the followingrecursive method., if only positive parameters are passed to themethod? public int guess(int a, int b) { if(a == 0) return 1; else return b + guess(a - 1, b); } a)a + b b)a * b c)a^b d)b^a e)b!Explanation / Answer
public intguess(int a, int b) { if(a == 0) return 1; // it retunr 0 here,then it will be a*b otherwise it will be a*b+1. else return b + guess(a - 1, b); } public intguess(int a, int b) { if(a == 0) return 1; // it retunr 0 here,then it will be a*b otherwise it will be a*b+1. else return b + guess(a - 1, b); }It will be none of the above, it will be a*b +1
Reason:
Since this will sum b upto the a. .i.e it willcalculate sum of b , a's time. But in termination condition it isreturning 1, that is why it is a*b +1.
If it ruturn 0 then it will be a*b
Related 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.