0

If this is Bubble sort then what is this?

Do you see the placement of Swap()?

2
  • 2
    The title of your link is 'selection-sort-algorithm'. Isn't that a good hint? Commented Oct 4, 2010 at 20:02
  • I am here to compare my source code to the link. Commented Oct 4, 2010 at 20:04

4 Answers 4

4

It's a Selection sort

Sign up to request clarification or add additional context in comments.

3 Comments

The placement of the action 'Swap' is different. Isn't it? And, it is not finding the min value before a swap. Then how can it be a Selection Sort?
Ok. A selection sort is the closest thing to the code presented I know of. If you insist that it's not it, because it's not a perfect match, then I can't help you. Maybe there is no name for this exact thing.
@JMSA, it's totally finding the min element before swapping. I don't really see much of a difference between the codes myself.
3

The first list is indeed selection sort. It is in essence the same as the algorithm on the link you've provided. But instead of finding the element that has the minimum value, and swapping it with arr[i] once after the j loop, the first code immediately swaps arr[i] with any value it encounters which is smaller.

In both cases, at the end of the i loop, arr[i] will contain the smallest element in a within the range i+1..SIZE.

There are two differences between the two algorithms: the code you show here performs more than one swap per iteration, and it shuffles the data that is not yet sorted (this is not really important, as they will eventually get sorted). So, basically it is less efficient than the code you've linked.

Comments

2

It's a kind of Selection Sort (as Maciej Hehl already said), but very ineffective. You swap way to many times. The effect is that you swap witch the minimum, but on the way there swap with each other that is smaller than the number you are looking at. That is unnecessary.

Comments

0

Maybe I am missing something subtle, but the first link (lorenzod8n.wordpress.com) shows a bubble sort; the second (cprogramminglanguage.net) a selection sort. It even says so in the text.

Edit: I missed/forgot something subtle: Bubble Sort exchanges adjacent entries; the algorithm in the first link doesn't. Hence, it's not Bubble Sort, though it does has Bubble Sort's excessive swapping behavior.

1 Comment

If that is a Bubble Sort, is it comparing adjacent elements?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.