Interview Cheatsheet
One Line Summary
- Bubble Sort:
Keep Swaping adjacent elements until sorted. - Selection Sort:
Pick the smallest and place it in front. - Insertion Sort:
Insert each element into its correct position. - Merge Sort:
Divide, sort halves, then merge. - Quick Sort:
Place one element correctly, repeat on both sides. - Heap Sort:
Repeatedly take max/min from a heap. - Counting Sort:
Count frequencies instead of comparing. - Radix Sort:
Sort digits one by one using counting sort. - Bucket Sort:
Distribute into ranges, sort locally, merge.
Real-World Use Cases
- Quick Sort:
Default choice in many systems. - Merge Sort:
Databases, linked lists, stable sorting. - Heap Sort:
Priority Queues, guranteed bounds. - Counting/Radix Sort:
IDs, numbers, digits. - Bucket Sort:
Floats, percentages, normalized data.
Decision Questions
- Need fast general sorting:
Quick Sort - Need stable sorting:
Merge Sort - Need guranteed performance:
Heap Sort - Numbers with small range:
Counting Sort - Large integers:
Radix Sort
li>Uniformly distributed floats:
Bucket Sort
Note:
There is no best Sorting Algorithm, best depends on the Input data.
