Computer Science EngineeringHardISRO SC (CS)
Quicksort picks the first element as pivot and partitions into smaller/larger lists (each remaining element is compared once with the pivot per call). Sorting [31, 32, 4, 12, 37, 25, 24] makes how many element-to-pivot comparisons in total?
- A. 14
- B. 13
- C. 12
- D. 21
Correct answer: B. 13
Add (size-1) over every recursive call: 13.
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
- 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:
- 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: