Data Structures & AlgorithmsModerateProduct placement · Amazon/Microsoft

Assertion (A): Quick sort with the last element as pivot takes Θ(n²) time on an array that is already sorted. Reason (R): On sorted input every partition splits the array into parts of sizes n − 1 and 0.

  1. A. Both A and R are true, but R is not the correct explanation of A
  2. B. Both A and R are true, and R is the correct explanation of A
  3. C. A is true, but R is false
  4. D. A is false, but R is true

Correct answer: B. Both A and R are true, and R is the correct explanation of A

With the maximum as pivot each call peels off only one element, giving n + (n − 1) + … = Θ(n²) comparisons; R is exactly why.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic