If you had this array to do a selection sort G B A H C
the first pass would be ABGHC
the 2nd pass would be ABGHC
the 3rd pass would be ABCHG
the 4th pass would be ABCGH
Why is the first and second pass the same?
Printable View
If you had this array to do a selection sort G B A H C
the first pass would be ABGHC
the 2nd pass would be ABGHC
the 3rd pass would be ABCHG
the 4th pass would be ABCGH
Why is the first and second pass the same?
Is there any code associated with your post?
I am just trying to figure out how the sort works
Okay, then how do you know that each pass will be how you said they would? You must be using something to get that data.
yes I do not understand how it is working
Do your notes say anything else about selection sorts? Personally, I don't know what they are. Maybe if you explained it to me a little I would understand.
No
Could you tell me ANY context information here? What kind of notes does the passage appear in? What is the general topic? How exactly is the data set out?
I googled for selection sorting, and I found out the algorithm. The data sequence you showed does not match the selection sort algorithm. Are you sure you copied the data correctly?
selection sort is one of the simplest sorts there is. The concept is simply find the min, store it, find the min, store it and so on. Your example doesn't change in a couple steps because the min already lives in the front of the searched area.
GBAHC
A*BGHC
AB*GHC
ABC*HG
ABCG*H
The asterisk represents a divider between the final area and the searched area. If you know what the algorithm is supposed to do, you can see why it doesn't change between a couple steps
That's the right algorithm FYB, but the data still doesn't follow it. It SHOULD go like this:
GBAHC
A*GBHC
AB*GHC
ABC*GH
ABCG*H
ABCGH
Drew's data seems to be doing more than just selection sorting.
It does actually. You may have found a linked list version of the algorithm? There is not a need to "swap" in the linked list version.Quote:
Originally posted by bennyandthejets
I googled for selection sorting, and I found out the algorithm. The data sequence you showed does not match the selection sort algorithm. Are you sure you copied the data correctly?
yes, based on your output, bennyandthejets I would say that you've found a linked list version. It's quicker to swap then it is to move the entire array down in the array version.
Could you explain further the swapping method? I still don't see how consecutive swapping could get us these results.
Okay, I get it now. It's not consecutive, it just swaps the next min value with the first value left in the array. That's pretty ingenious.
Problem solved I guess.