Skip to main contentSkip to solution

Consider the following numList:

87131-94

Sequence the following output obtained after each pass of comparison using bubble sort.

(A) 7 8 1 -9 4 13

(B) 7 1 -9 4 8 13

(C) -9 1 4 7 8 13

(D) 1 -9 4 7 8 13

Solution

✅ Correct Option: 3

Bubble sort compares adjacent pairs from left to right in each pass and swaps them if they are out of order, so the largest remaining element moves to the end.

Pass 1: 8 7 13 1 −9 48\ 7\ 13\ 1\ -9\ 4 becomes (A) 7 8 1 −9 4 137\ 8\ 1\ -9\ 4\ 13

Pass 2: (A) becomes (B) 7 1 −9 4 8 137\ 1\ -9\ 4\ 8\ 13

Pass 3: (B) becomes (D) 1 −9 4 7 8 131\ -9\ 4\ 7\ 8\ 13

Pass 4: (D) becomes (C) −9 1 4 7 8 13-9\ 1\ 4\ 7\ 8\ 13


Options 1 and 4: (C) is the fully sorted list, so it must come last. (D) still has 11 before −9-9, so it comes just before (C).

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question