What is a sorting algorithm?
• An algorithm that arranges data into order
What orders are sorting algorithms usually used for?
• Ascending
• Descending
What three sorting algorithms should you know?
• Bubble sort
• Merge sort
• Insertion sort
How does bubble sort work?
• Compare adjacent items
• Swap if they are in the wrong order
• Repeat passes until no swaps are needed
What happens in each pass of a bubble sort?
• Adjacent items are compared
• Swaps are made if needed
• The largest unsorted item moves towards the end
Why are fewer comparisons needed in later passes of bubble sort?
• The largest values have already moved to the end
When does bubble sort stop?
• When a full pass makes no swaps
What are the advantages of bubble sort?
• Easy to understand
• Easy to implement
What are the disadvantages of bubble sort?
• Slow on large lists
• Slow on reverse-ordered lists