What is the time complexity of TimSort in the worst case?
TimSortâ€™s worst-case time complexity is O(n log n), but it can degrade to O(n^2) if the data is highly sorted.
Thatâ€™s partially correct. TimSort is designed to maintain O(n log n) in the worst case, even with sorted data, through its adaptive nature.
Can you explain how TimSort handles partially sorted data and how this improves performance?