Fundamentals · Easy · Free
Explain bubble sort and selection sort — complexity and when NOT to use them.
FresherFundamentalsData Structures & Algorithms
Bubble & selection sort
Both O(n²). Bubble swaps adjacent out-of-order pairs; selection picks min each pass and swaps to front.
| Bubble | Selection | |
|---|---|---|
| Passes | Many swaps | Fewer swaps |
| Best case | O(n) if optimized | Always O(n²) |
| Use | Teaching only | Teaching only |
java
// Interview: know complexity; use Arrays.sort / TimSort in real codeSay you'd never use these in prod except tiny n—shows judgment.