ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

Which of the following statements about Python's sort is correct for CP problems?

  1. A. Timsort is O(n^2) in the worst case, so it is unsafe for 2 * 10^5 items
  2. B. list.sort() and sorted() use Timsort, which is stable and runs in O(n log n) worst case
  3. C. sorted() sorts in place and returns None
  4. D. list.sort() is always faster than sorted() on the same list

Correct answer: B. list.sort() and sorted() use Timsort, which is stable and runs in O(n log n) worst case

Python's built-in sort is Timsort, which is stable and has O(n log n) worst-case time. sorted() returns a new list, and list.sort() sorts in place and returns None.

More Python Programming questions

Exams that ask this topic