GATE Computer ScienceHardNIELIT Scientist B
Quicksort uses the last element of each sub-array as pivot and compares every other element of the sub-array with it once. On [4, 7, 1, 9, 3, 8, 2, 6, 5] how many key comparisons are made in total?
- A. 14
- B. 20
- C. 23
- D. 17
Correct answer: D. 17
Summing (size − 1) over every partitioned sub-array in the recursion gives 17.
More Algorithms questions
- Consider T(n) = T(n/2) + T(n/3) + T(n/6) + n with T(1) = 1. Which bound is tight?
- Dijkstra's algorithm from vertex 0 runs on the undirected graph with edges (0,1,7), (0,2,9), (0,5,14), (1,2,10), (1,3,15), (2,3,11)…
- Top-down merge sort (standard two-way merge, one comparison per element moved while both lists are non-empty) sorts [38, 27, 43, 3, 9, 82…
- A fractional knapsack of capacity 20 can take items with (value, weight) = (40,8), (30,5), (24,6), (50,10), (18,3), (35,7), fractions…
- Keys 41, 22, 8, 30, 19, 52, 33, 63 are inserted in this order into an empty table of size 11 with h(k) = k mod 11 and linear probing. How…
- What is the length of the longest strictly increasing subsequence of [10, 22, 9, 33, 21, 50, 41, 60, 80, 3, 5, 70, 75, 90]?