Skip to main content
PreparationZone Logo
PreparationZone
Back to Fundamentals

Fundamentals · Easy · Free

Explain bubble sort and selection sort — complexity and when NOT to use them.

FresherFundamentalsData Structures & Algorithms
Model answer

Bubble & selection sort

Both O(n²). Bubble swaps adjacent out-of-order pairs; selection picks min each pass and swaps to front.

BubbleSelection
PassesMany swapsFewer swaps
Best caseO(n) if optimizedAlways O(n²)
UseTeaching onlyTeaching only
java
// Interview: know complexity; use Arrays.sort / TimSort in real code
Say you'd never use these in prod except tiny n—shows judgment.