Reputation: 65
I would just like to know the key differences between these two sorting methods because they are very similar and have got me confused.
For example, if I had a sorted array:
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
What would be some differences in the number of comparisons and movements between using selection and bubble sort on this sorted list.
Upvotes: 3
Views: 5168
Reputation: 6936
Take a look at this, its a visual and audio representation of the behavior of different sorting algorithms. Very entertaining and educational to give you an idea how they behave.
http://www.youtube.com/watch?v=t8g-iYGHpEA
Since your list you provided is already perfectly sorted we are dealing with best case scenario for both algorthms, which is O(n) for bubble and O(n^2) for selection sort.
Upvotes: 1