Advanced
Algorithm Optimization Challenge
Optimize a provided sorting algorithm for specific constraints.
📝 提示内容
Analyze the following QuickSort implementation written in Python. Identify the specific bottlenecks when applied to nearly sorted datasets with unique integers. Rewrite the algorithm to optimize for this specific case, focusing on minimizing recursive depth and stack memory usage. Provide the refactored code and a time complexity analysis comparing Big-O of the original versus the new version.