Skip to main contentSkip to solution

Given the array [12, 8, 20, 10]

What will be the sequence of the elements in the array after the first pass using bubble sort?

(A) 12

(B) 8

(C) 20

(D) 10

Solution

✅ Correct Option: 2

In one pass of bubble sort, adjacent elements are compared from left to right and swapped if the left one is larger.

ComparisonActionArray after
12 and 8swap8, 12, 20, 10
12 and 20no swap8, 12, 20, 10
20 and 10swap8, 12, 10, 20

The array is 8, 12, 10, 20, which is (B), (A), (D), (C).


Option 3: stops after the first swap and misses the 20 and 10 swap.

Option 4: misses the first swap of 12 and 8.

The largest element (20) always reaches the last position after the first pass.

Keyboard Shortcuts

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