Computer Science EngineeringHardISRO SC (CS)
Consider the following C fragment. int c=0; for(int i=1;i<=18;i++) for(int j=1;j<=i;j++) if((i+j)%3==0) c++; What is c at the end?
- A. 57
- B. 51
- C. 114
- D. 29
Correct answer: A. 57
Simulating the loops gives 57. 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
- Keys [86, 35, 42, 13, 17, 29] are hashed into 11 buckets by h(k) = k mod 11 using separate chaining. The length of the longest chain is:
- Keys [47, 90, 61, 44, 17, 67, 89, 45] are hashed into 11 buckets by h(k) = k mod 11 using separate chaining. The length of the longest…
- The number of distinct spanning trees of the graph with vertices 1..5 and edges 1-2, 2-3, 3-1, 2-4, 3-4, 4-5 is:
- The worst-case number of key comparisons binary search makes on a sorted array of 5000 elements (counting one three-way comparison per…
- Keys [19, 9, 59, 90, 32, 4, 28] are inserted into an empty binary search tree (no balancing). The height of the tree in edges is:
- The max-heap [95, 84, 54, 64, 16, 43, 42, 24] undergoes one extract-max (last element moved to the root, then sifted down). The resulting…