Page 2 of 2

Re: QuickSort: any thoughts to improve this?

Posted: 09 May 2019, 03:17
by evilC
Mine does not quite work like that, it does it all in one pass
If it swaps, it moves left until it doesn't swap, then resumes where it left off

6 5 3 1 8 7 2 4
5 6
5 3 6
3 5 6
3 5 1 6
3 1 5 6
1 3 5 6
1 3 5 6 8
1 3 5 6 7 8
1 3 5 6 7 2 8
1 3 5 6 2 7 8
1 3 5 2 6 7 8
1 3 2 5 6 7 8
1 2 3 5 6 7 8
1 2 3 5 6 7 4 8
1 2 3 5 6 4 7 8
1 2 3 5 4 6 7 8
1 2 3 4 5 6 7 8

Re: QuickSort: any thoughts to improve this?

Posted: 09 May 2019, 08:14
by nnnik
Then I guess its a mix between insertion sort and bubble sort.

Re: QuickSort: any thoughts to improve this?

Posted: 09 May 2019, 08:30
by freespacing
Either way I believe it's O(n-squared), as opposed to O(n.log(n)) for quick-sort and merge-sort. Can be efficient for small arrays (in fact the hybrid Tim Sort -- Python standard -- uses Insertion Sort at some stage) but you'll feel a large difference as the set grows. Which takes nothing away from the fun of experimenting and thrill of writing something that works. That's a feeling of pure magic. :)