Data Structures & AlgorithmsHardTCS NQT · Infosys pattern

How many of these statements are correct? (i) Merge sort is stable. (ii) Heap sort runs in O(n log n) even in the worst case. (iii) Quick sort with a randomly chosen pivot runs in O(n log n) in the worst case. (iv) Insertion sort runs in O(n) on an already sorted array.

  1. A. Only one
  2. B. Only two
  3. C. Only three
  4. D. All four

Correct answer: C. Only three

(i), (ii) and (iv) are true. (iii) is false: random pivots give O(n log n) expected time, but a run of bad pivots can still cost O(n²), so the worst case is unchanged.

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

Exams that ask this topic