ProgrammingHardCodeforces-style · placement coding round

A program sorts the whole list again for each of 10^5 queries on a list of 10^5 items. Which statement about running it in CPython is correct?

  1. A. Yes, sorting is O(n) in Python
  2. B. Yes, sorted results are cached per list
  3. C. No, about 10^5 sorts of 10^5 items is far beyond one second
  4. D. Only if the list is already sorted

Correct answer: C. No, about 10^5 sorts of 10^5 items is far beyond one second

Each sort costs about n log n, which is roughly 1.7 x 10^6 steps, and repeating it 10^5 times gives about 10^11 steps. The fix is to sort once and answer the queries from that order.

More Python Programming questions

Exams that ask this topic