Which of the following is not an advantage of optimised bubble sort over other…
2025
Which of the following is not an advantage of optimised bubble sort over other sorting techniques in case of sorted elements?
- A.
It is faster
- B.
Consumes less memory
- C.
Detects whether the input is already sorted
- D.
Consumes less time
Attempted by 15 students.
Show answer & explanation
Correct answer: B
Concept: The optimisation added to bubble sort is an early-termination check — a boolean “swapped” flag: if a full pass makes zero swaps, the array is already sorted, so the algorithm stops immediately instead of running every remaining pass. This changes ONLY the algorithm's behaviour when the input happens to be sorted (best-case time drops from O(n²) to O(n)) — a purely TIME-side gain that appears precisely “in case of sorted elements”. Adding the flag costs just one constant extra variable — it does not change the algorithm's auxiliary-space complexity, which was already O(1) (bubble sort has always needed only a temporary swap variable) and stays O(1) after this optimisation too — so memory usage cannot be an advantage that is conditional on the elements being sorted.
Application — trace it on a sorted array:
Take an already-sorted array, e.g. [2, 5, 7, 9].
Pass 1 compares (2,5), (5,7), (7,9) — none needs a swap, so the “swapped” flag stays false through the whole pass.
A pass with zero swaps means the array is already sorted, so the algorithm exits right there — this is exactly how it detects the sorted state.
Only one pass (n-1 comparisons) ran instead of the usual n-1 passes, so total work is O(n) — genuinely faster, and it consumes genuinely less time than always running every pass.
Memory used for this run: one “swapped” boolean plus (at most) one temporary swap variable — a constant addition that keeps the algorithm's auxiliary space at O(1), the same complexity class it already had; sortedness of the input changes nothing about this.
Cross-check: Insertion sort, selection sort, and heap sort are also O(1)-extra-space, in-place algorithms, so bubble sort's memory was never uniquely large to begin with — and more importantly, that footprint does not shrink just because this run's input happens to be sorted. (Some of these, like plain insertion sort, are themselves adaptive and can also run in O(n) on sorted data — but that changes only how much faster one technique is relative to another, not whether speed/time gains are conditional on sortedness; memory never is, for any of them.) The three time-related options (faster / less time / detecting the sorted state), by contrast, are gains that exist ONLY because the elements are sorted — exactly what the question is asking about. So among the four statements, memory is the one advantage NOT tied to the sorted-elements condition.
Hence, “Consumes less memory” is the one statement that is not an advantage specifically tied to sorted input — the correct answer.