def partition(arr, low, high):
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
def quick_sort(arr, low, high):
if low < high:
pivot_index = partition(arr, low, high)
quick_sort(arr, low, pivot_index - 1)
quick_sort(arr, pivot_index + 1, high)
# Example usage
arr = [64, 34, 25, 12, 22, 11, 90]
quick_sort(arr, 0, len(arr) - 1)
print(arr)
Quick Sort is an efficient sorting algorithm with an average time complexity of O(n log n). It follows the divide-and-conquer approach, recursively dividing the array into smaller sub-arrays and sorting them. The choice of the pivot element can affect the performance of the algorithm in certain cases, such as when the array is already sorted or contains many duplicate elements. However, on average, Quick Sort performs well and is widely used in practice.