Advanced_Algorithms icon indicating copy to clipboard operation
Advanced_Algorithms copied to clipboard

An improvement on QuickSort

Open 1170300803 opened this issue 6 years ago • 2 comments

Quick sort algorithm can be optimized in many ways. For example, instead of selecting the last element, the benchmark element can randomly choose one, which avoids the case of an ordered array with the worst time complexity of log (n2).

1170300803 avatar Jul 26 '19 14:07 1170300803

True. Feel free to implement that one change and create a pull-request. Maybe I find time for this change myself otherwise.

MauriceGit avatar Aug 01 '19 07:08 MauriceGit

Just to note: Quicksort always has a worst-case time complexity of O(n²), independent of the implementation detail of pivot element choice. Average runtime changes to log n for special cases.

MauriceGit avatar Aug 01 '19 07:08 MauriceGit