Recursion questions

Q37

GATE CS 2016 CS-2RecursionNAT2 marks
Consider the following program:
int f(int *p, int n)
{
    if (n <= 1) return 0;
    else return max(f(p+1,n-1),p[0]-p[1]);
}

int main()
{
    int a[] = {3,5,2,6,4};
    printf("%d", f(a,5));
}
Note: max(x,y) returns the maximum of x and y.

The value printed by this program is _________.
Show answer without attempting

Answer: 3.0

Q39

GATE CS 2016 CS-2RecursionNAT2 marks
The given diagram shows the flowchart for a recursive function A(n)A(n). Assume that all statements, except for the recursive calls, have O(1)O(1) time complexity. If the worst case time complexity of this function is O(nα)O(n^\alpha), then the least possible value (accurate up to two decimal positions) of α\alpha is _________.
Question figure
Show answer without attempting

Answer: 2.2 to 2.4

0/20 correct0 marks

Related topics in Programming and Data Structures