Computer Science EngineeringVery hardISRO SC (CS)
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)
- A. 397
- B. 396
- C. 400
- D. 1600
Correct answer: A. 397
Simulating the loops gives 397. The distractors come from the usual slips: off-by-one at a boundary (< vs <=), dropping a loop level, or using a cruder asymptotic estimate instead of the exact count.
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
- 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?
- Consider the following C fragment. int c=0; for(int i=1;i<=30;i++) for(int j=i;j<=30;j+=i) c++; What is c at the end?
- The Levenshtein edit distance (insert, delete and substitute each cost 1) between "bddbccb" and "eedbaba" is:
- Quicksort picks the first element as pivot and partitions into smaller/larger lists (each remaining element is compared once with the…