Part 1: Multiple choice and True False. Ten, 5-point questions. True or False. A
ID: 3590906 • Letter: P
Question
Part 1: Multiple choice and True False. Ten, 5-point questions. True or False. A Stack is the data structure used by the os to implement recursion? 2. Wh en a recursive method is called to solve a problem, the method actually is capable of solving only the simplest case(s), or a. base case (s). b. recursive call (s). c. recursion step(s). 3. T he following routine/code segment violates which rule(s) of recursion? static int recurse( int n)Iln is a positive int ifn0) return 0: else nnrecurse( n+1 return n; a. No base case b. Fails to make progress towards base case c. Does not call clone / make recursive call d. all of the above · Which of the following is the most likely result of failing to make progress owards a base case in a recursive call? a. compiler enters into an infinite loop . virtual machine throws an exception when running the program . error at compilation time recursive routine enters an infinite loop when it runs In the most common scenario, what happens when method F calls method G? a. An activation record for F is pushed b. An activation record for F is popped c. An activation record for G is pushed . d. An activation record for G is popped e. none of the above Page 1 of 4Explanation / Answer
1)It is true Stack is used for implementing Recursion
2) basecase(s)
3) Fails to make progress towards base case, The reason being is we are returning to infinite loop as n is positive
4) Its option 4 as we may be entering into an infinite loop
5) An activation record for f will be pushed as first we will execute g then f will be executed
6) O(nlogn)
7) Insertion Sort
8) Quick Sort
9) It is option a as we will pick the smallest element and place it at the beginning.
10) Any array that is already sorted
1) Here initially 5 will be pushed
Later the 5 value will be popped and 20 will be pushed.
Later 20 will be popped and 60 will be pushed.
Later 20 will be popped and 120 will be pushed.
Finally 120 will be popped hence the result
2) int i,j=1;
for(i=n;i>=1;i--)
j*=i