I've come up with my own sorting algorithm, implemented in Python: http://ideone.com/iAxDB Does an algorithm like mine exist in the wild? What is it called?
Btw the default test I put in there is the worst case of my algorithm. Uncomment the 'shuffle' line to test a random case. it seems to be O(n^2), and performs n swaps for the first iteration, n-1 swaps for the second iteration, ..., 1 swap for the nth iteration... so it isn't completely bad
Is it selection sort, or bubble sort?
how is this different from bubble sort?
I think you're right... it is bubble sort. but it looks a little different from the implementation here: http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort#Python
Yeah, bubble sort itself is a bad sort. You can make even worse by essentially checking and swapping n values n times. :)
you may have more optimised bubble sort and even slightly different versions of bubble sort
Join our real-time social learning platform and learn together with your friends!