Skip to main contentSkip to solution

Arrange the following in order related to bubble sort for a list of elements:

4-9123026

(A).

-94123026

(B).

-94122306

(C).

-94212630

(D).

-94122630

Solution

✅ Correct Option: 1

(A) -9, 4, 12, 30, 2, 6: in the first pass, 4 and -9 are compared and swapped.

(B) -9, 4, 12, 2, 30, 6: 30 and 2 are swapped, since 4 < 12 and 12 < 30 need no swap.

(D) -9, 4, 12, 2, 6, 30: 30 and 6 are swapped, so the largest element 30 reaches its final place and the first pass ends.

(C) -9, 4, 2, 12, 6, 30: in the second pass, 12 and 2 are swapped (4 and 12 needed no swap).

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

Keyboard Shortcuts

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