Computer Science EngineeringHardISRO SC (CS)
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?
- A. 111
- B. 103
- C. 133
- D. 102
Correct answer: A. 111
Simulating the loops gives 111. 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 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…
- 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?
- 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: