Sorting Algorithms Flashcards
What are the three steps to the Bubble Sort Algorithm?
- If there is only one number, stop
- Make one pass, swapping as necessary
- If no swaps have occurred, stop, otherwise, restart
What are the first three passes of the Shuttle Sort Algorithm like?
Pass 1. Compare the 1st and 2nd numbers. Swap if necessary
Pass 2. Compare the 2nd and 3rd numbers. Swap if necessary. If a swap has occurred, compare the 1st and 2nd numbers again. Swap if necessary
Pass 3. Compare the 3rd and 4th numbers. Swap if necessary. If a swap has occurred, compare the 2nd and 3rd numbers again. Swap if necessary. If a swap has occurred, compare the 1st and 2nd numbers again. Swap if necessary.
etc.
In what ways might the shuttle sort be more efficient than the bubble sort? In what ways might in not?
Shuttle sort can successfully sort a set of numbers with fewer comparisons than bubble sort (not always)
Both sorting methods must use the exact same number of swaps, as both have to sort the same number set into the same order.
How does the first fit algorithm work?
Each object is placed into the first available space in which it will fit
How does the first fit decreasing algorithm work?
Sort numbers into descending order, then use the first fit algorithm