TOPIC: Quick Sort DEFINITION: Quick Sort is a popular sorting algorithm that efficiently arranges elements in an array in ascending or descending order by selecting a pivot element, partitioning the array around it, and recursively sorting the sub-arrays. This process solves the problem of sorting large datasets by breaking it down into smaller, more manageable chunks. It's a divide-and-conquer algorithm that's widely used due to its simplicity and performance. TIME_COMPLEXITY: The time complexity of Quick Sort is O(n^2) in the worst case, O(n log n) on average, and O(n log n) in the best case, depending on the choice of pivot and the initial order of the elements, with the average case being the most common scenario due to the randomization of pivot selection. SPACE_COMPLEXITY: The space complexity of Quick Sort is O(log n), as it uses recursive function calls to sort the sub-arrays, which can go up to a depth of log n in the call stack. USE_WHEN: Quick Sort is the right tool when you need to sort large datasets efficiently, especially when memory is limited, as it only requires a small amount of extra memory for the recursive call stack. It's also suitable for datasets that are partially sorted or have a mix of ordered and random elements. AVOID_WHEN: Quick Sort is a poor choice when the dataset is already sorted in reverse order or has a specific pattern that can cause the worst-case scenario, in which case other algorithms like Merge Sort or Heap Sort might be more suitable. EXAMPLE: Initial array: [5, 2, 8, 3, 1] Select pivot: 5 Partition: [2, 3, 1] | 5 | [8] Recursively sort left: [1, 2, 3] Recursively sort right: [8] Combine: [1, 2, 3] | 5 | [8] Result: [1, 2, 3, 5, 8] REAL_WORLD_ANALOGY: Quick Sort is similar to how you would sort a stack of papers by selecting a pivot paper, putting all the papers with a lower value to its left and all the papers with a higher value to its right, and then recursively sorting the two piles. SOURCE_NOTE: Concepts referenced from general knowledge of algorithms and data structures.