What is the difference between bubble sort and merge sort?
Bubble sort repeatedly swaps neighbouring elements that are out of order, which is simple but slow at O(n squared). Merge sort splits the array in half, sorts each half, then merges them, which is much faster at O(n log n). Bubble sort is only used for teaching, while merge sort is a real world sorting algorithm.
Bubble sort
It passes through the list again and again, swapping any two neighbours in the wrong order, until no swaps are needed. It is easy to understand but does far too much work on large inputs.
Merge sort
It uses divide and conquer. It keeps splitting the array until each piece has one element, then merges the pieces back together in sorted order. The merging is where the sorting really happens.
Quick comparison
- Time: bubble sort is O(n squared), merge sort is O(n log n).
- Space: bubble sort is O(1), merge sort needs O(n) extra space.
- Stability: both can be stable, keeping equal elements in order.
- Use: bubble sort for learning, merge sort for real data and linked lists.
If asked which sort you would use in practice, mention that most languages use a hybrid like Timsort or introsort under the hood, and that merge sort is preferred when stability matters or when sorting linked lists.
Common follow up questions
Related interview questions
Want the full DSA guide?
Read every DSA concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the DSA guide All DSA questions