Computer Science EngineeringHardISRO SC (CS)
Consider the following C fragment. int c=0; int x=40; while(x>0){ for(int j=0;j<x;j++) c++; x/=3; } What is c at the end? (integer division)
- A. 57
- B. 58
- C. 78
- D. 60
Correct answer: B. 58
Simulating the loops gives 58. 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
- Tower of Hanoi with 10 disks and three pegs needs the minimum number of moves equal to:
- Which data structure follows the Last-In-First-Out principle?
- The height (in edges) of a complete binary tree having n nodes is
- The time needed to build a binary heap from n arbitrary elements using bottom-up heapify is
- The maximum number of nodes in a binary tree of height h (root at height 0) is
- The recurrence T(n) = 2T(n/2) + n log n solves to