Put the steps in the correct order
Sorting is the process of arranging data into a specific order (e.g., ascending or descending). Sorting algorithms take an unordered list and rearrange the elements. Different algorithms have different approaches — some are simple but slow, others are more complex but faster.
Bubble Sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. This continues until no more swaps are needed.
It's called "bubble" sort because larger elements gradually "bubble up" to the end of the list with each pass, like bubbles rising in water.
✅ Advantages: Simple to understand and implement, requires no extra memory, detects if already sorted.
❌ Disadvantages: Very slow for large lists, inefficient compared to other algorithms.
Insertion Sort builds the sorted list one element at a time. It takes each element and inserts it into its correct position among the already-sorted elements, like sorting playing cards in your hand.
Imagine sorting cards in your hand: you pick up each new card and slide it into the right place among the cards you've already sorted. That's exactly how Insertion Sort works!
✅ Advantages: Simple to implement, efficient for small lists, works well when data is nearly sorted, sorts "in place" (no extra memory needed).
❌ Disadvantages: Slow for large lists, requires many shifts if data is in reverse order.
Merge Sort is a "divide and conquer" algorithm that divides the list into smaller sublists, sorts them, then merges them back together. It's more efficient than Bubble Sort and Insertion Sort for large datasets.
When merging two sorted sublists:
✅ Advantages: Consistent performance, stable sort (preserves order of equal elements), excellent for large datasets.
❌ Disadvantages: Requires additional memory for merging, more complex to implement than Bubble Sort.