Please explain why you chose your answer. 11) Insert the missing code in the fol
ID: 3835192 • Letter: P
Question
Please explain why you chose your answer.
11) Insert the missing code in the following code fragment. This fragment is intended to recursively compute x where x and n are both non-negative integers publas int power (int x, int n) (n 0) 8e Return power (x, n 1); a return 1 b) return X c) turn power (x, n 1) Power (x, n 1); return X 12) How many recursive calls to the fib method shown below would be made from an original call to Eib 4) o not count the original call) public int fib (int n) assumes n 0 if (n 1) retur n. 8e 1) fib (n 2)); retur (fib a 1 b 2. c) 4 d 8Explanation / Answer
11)answer: A) return 1
explanation:-
let take x=4, n=3
now
x^n = 4^3 = 4*4*4
means for 4^3 is we are multiplying 4 by itself 3 times
in the above recursive function...
in the return statement where the recursive call is present, every time the value returned is multiplied by x..
this is breaks when n==0..
s0
the recursive calls are..
n=3
n=2
n=1
n=0// this is fourth one..(so we have already 3 calls.. and in every call is multiplied by x, so we have to return 1)
12)answer:D ) 8
explanation:
fib(4)
/
fib(3) fib(2)
/ /
fib(2) fib(1) fib(1) fib(0)
/
fib(1) fib(0)
total 8 calls
excluding the original call fib(4)
13)Answer : A ) return 1
explanation : siimilarly as 11
14)Answer : D)
explanation:
you need to decrement the value that is passed as parameter throught the recursive call...otherwise it will lead to infinte loop..
15)Answer : C
explanation:
traversing variable i starting at 1, missing the index 0, means missing first element