You are on page 1of 1

Shuttle Sort

What is shuttle sort?


Shuttle sort is an algorithm for sorting numbers into ascending order. You could be asked to trace the algorithm and/or compare how efficient it is.

Shuttle Sort
What is shuttle sort?
Shuttle sort is an algorithm for sorting numbers into ascending order. You could be asked to trace the algorithm and/or compare how efficient it is.

Shuttle Sort Algorithm


1 Pass: Compare first and second and swap if necessary. 2nd Pass: Compare second and third and swap if necessary, if a swap occurred compare 1st and 2nd numbers and swap if necessary. 3rd Pass: Compare 3rd and 4th numbers and swap if necessary, if a swap occurred compare 2nd and 3rd, and so up the list The numbers shuttle back, saving on unnecessary comparisons.
st

Shuttle Sort Algorithm


1st Pass: Compare first and second and swap if necessary. 2nd Pass: Compare second and third and swap if necessary, if a swap occurred compare 1st and 2nd numbers and swap if necessary. 3rd Pass: Compare 3rd and 4th numbers and swap if necessary, if a swap occurred compare 2nd and 3rd, and so up the list The numbers shuttle back, saving on unnecessary comparisons.

Example Use shuttle sort to sort 6, 4, 8, 3, 7, 4 into ascending order Pass Start Pass 1 Pass 2 Pass 3 List 6 4 4 4 4 3 Pass 4 Pass 5 3 3 3 3 3 3 Comparisons: 11 Swaps: 8 Same number of swaps, but less comparisons! 4 6 6 6 3 4 4 4 4 4 4 4 8 8 8 3 6 6 6 6 6 6 4 4 3 3 3 8 8 8 7 7 7 4 6 6 7 7 7 7 7 7 8 8 4 7 7 7 4 4 4 4 4 4 4 4 8 8 8 8 Swap 6 and 4 Dont swap 6 and 8 Swap 8 and 3 Swap 6 and 3 Swap 4 and 3 Swap 8 and 7 Dont swap 6 and 7 Swap 8 and 4 Swap 7 and 4 Swap 6 and 4 Dont swap 4 and 4 Notes

Example Use shuttle sort to sort 6, 4, 8, 3, 7, 4 into ascending order Pass Start Pass 1 Pass 2 Pass 3 List 6 4 4 4 4 3 Pass 4 Pass 5 3 3 3 3 3 3 Comparisons: 11 Swaps: 8 Same number of swaps, but less comparisons! 4 6 6 6 3 4 4 4 4 4 4 4 8 8 8 3 6 6 6 6 6 6 4 4 3 3 3 8 8 8 7 7 7 4 6 6 7 7 7 7 7 7 8 8 4 7 7 7 4 4 4 4 4 4 4 4 8 8 8 8 Swap 6 and 4 Dont swap 6 and 8 Swap 8 and 3 Swap 6 and 3 Swap 4 and 3 Swap 8 and 7 Dont swap 6 and 7 Swap 8 and 4 Swap 7 and 4 Swap 6 and 4 Dont swap 4 and 4 Notes

How does this compare to bubble sort with number of comparisons and swaps?

How does this compare to bubble sort with number of comparisons and swaps?

You might also like