Advanced
Big O Optimization Analysis
Analyze an inefficient sorting algorithm and propose an optimized solution.
📝 Contenu du Prompt
Consider a naive sorting algorithm that iterates through a list and for every element, compares it to every other element, swapping if they are out of order. Analyze the time complexity of this algorithm. Propose a more efficient algorithm (such as Merge Sort or Quick Sort), explain the logic behind it, and describe how it reduces the time complexity in mathematical terms.