Computer Science EngineeringHard
What does g(48, 18) return for int g(int a,int b){ return b==0 ? a : g(b, a%b); }
- A. 6
- B. 12
- C. 3
- D. 18
Correct answer: A. 6
g(48,18)->g(18,12)->g(12,6)->g(6,0)=6, the gcd.
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
- What does this fragment print? int a[]={3,1,4,1,5}; int s=0; for(int i=0;i<5;i++) s ^= a[i]; printf("%d", s);
- A binary tree with n nodes stored with left and right pointers has how many NULL pointers in total?
- How many times does c++ execute in: int c=0; for(int i=1;i<=100;i=3) c++;
- The height (in edges) of a binary heap that stores 1000 elements is
- For void f(int n){ if(n>0){ f(n-1); printf("%d ",n); f(n-1); } }, how many numbers are printed by the call f(4)?
- The array [4, 10, 3, 5, 1] is converted into a max-heap by the standard bottom-up build-heap procedure. The resulting array is