Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That is Bubble Sort, not surprising.


If you read elsewhere in the discussion you will see many people explaining why this is not a Bubble Sort. One of the defining characteristics of Bubble Sort, as defined in TAoCP and many, many other places, is that it's only ever the elements in adjacent locations that are compared.


Yes, but the way to traverse the array is the same as Bubble Sort.

With that so specific definitions, I could just get any other sorting algorithm and change it with different ways of comparing the elements to create "new" sorting algorithms.


I disagree.

The second loop runs from 1 to n, whereas in Bubble Sort it runs from 1 to n-1.

The comparison here is between A[i] and A[j], whereas in Bubble Sort it's always only between A[i] and A[i+1].

This one always performs n^2 comparisons, whereas Bubble Sort never performs n^2 comparisons.

This one compares elements to themselves, whereas Bubble Sort never compares and element with itself.

If you sort the array [1,2,3], the first thing this routine does is swap the 1 and 2, giving [2,1,3], whereas Bubble Sort runs along the array, makes no swaps, and exits.

This is not Bubble Sort.

It's true that if you take an existing sorting algorithm and change things around you can get other sorting algorithms. The question is then one of just how different it is.

If you choose to believe this is "just Bubble Sort" then that's up to you, but I disagree.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: