Computer Science EngineeringHardISRO SC (CS)
Consider the following C fragment. int c=0; int x=100; while(x>0){ for(int j=0;j<x;j++) c++; x/=3; } What is c at the end? (integer division)
- A. 148
- B. 147
- C. 197
- D. 150
Correct answer: A. 148
Simulating the loops gives 148. 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 number of distinct permutations of 1..7 that can be produced as output by pushing 1,2,...,7 in order onto a stack and popping at any…
- How many structurally distinct binary trees (left and right children distinguished) with exactly 6 nodes have height exactly 4 edges?
- Using the Master theorem (extended form), the solution of T(n) = 2T(n/4) + n is:
- The keys [10, 14, 40, 49, 41, 19, 38] are inserted in this order into an initially empty AVL tree. Its preorder traversal is:
- A connected simple undirected graph has 8 vertices and 12 edges. The minimum number of edges that must be removed to obtain a spanning…
- A connected simple undirected graph has 10 vertices and 17 edges. The minimum number of edges that must be removed to obtain a spanning…