Quick sort algorithm with ruby
A fast sorting algorithm that uses a divide-and-conquer strategy to sort elements, ruby version.
Complexity
- Time:
- Best Case: (Ω(n log n)): The pivot element divides the array into two equal halves.
- Average Case (θ(n log n)): The pivot divides the array into two parts, but not necessarily equal.
- Worst Case: (O(n²)): The smallest or largest element is always chosen as the pivot (e.g., sorted arrays)
- Space: O(n) due to recursive call stack
Advantages
- Divide-and-conquer algorithm;
- Efficient on large data sets;
- Low overhead, requires a small amount of memory to function;
Disadvantages
- Worst-case time complexity of O(n2);
- Not a good choice for small data set;
- Not a stable sort, if two elements have the same key, their relative order will not be preserved