Computer Science EngineeringHardISRO SC (CS)
Trace this C function. int f(int n){ if(n==0) return 1; return n*f(n-1) - f(n/2); } (integer division) What does f(6) return?
- A. 2636
- B. 0
- C. -301
- D. -359
Correct answer: B. 0
Evaluating the recurrence by hand/computation gives f(6) = 0; the distractors correspond to a changed base case or a changed recurrence term.
Practise more Algorithms, Data Structures & Programming (ISRO CS) questionsAlgorithms, Data Structures & Programming (ISRO CS): notes and key points
More Algorithms, Data Structures & Programming (ISRO CS) questions
- Using the Master theorem (extended form), the solution of T(n) = 27T(n/3) + n^3 is:
- Using the Master theorem (extended form), the solution of T(n) = 2T(n/3) + n is:
- Consider the following C fragment. int c=0; for(int i=200;i>=1;i/=2) for(int j=0;j<i;j++) c++; What is c at the end? (integer division)
- The worst-case number of key comparisons binary search makes on a sorted array of 127 elements (counting one three-way comparison per…
- Consider the following C fragment. int c=0; for(int i=0;i<20;i++) for(int j=i+1;j<20;j++) for(int k=j+1;k<20;k++) c++; What is c at the end?
- Consider the following C fragment. int c=0; for(int i=0;i<10;i++) for(int j=i+1;j<10;j++) for(int k=j+1;k<10;k++) c++; What is c at the end?