Skip to main contentSkip to solution

Assume that bubble sort is applied on the array [9,7,14,3,-7,5].

Arrange the following outputs of different passes in their correct order.

A. [-7,3,5,7,9,14]

B. [3,-7,5,7,9,14]

C. [7,3,-7,5,9,14]

D. [7,9,3,-7,5,14]

Solution

✅ Correct Option: 1

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

D: after pass 1, the largest element 14 reaches the end: [7,9,3,−7,5,14][7,9,3,-7,5,14]

C: after pass 2, 9 settles next to 14: [7,3,−7,5,9,14][7,3,-7,5,9,14]

B: after pass 3, 7 settles in place: [3,−7,5,7,9,14][3,-7,5,7,9,14]

A: after pass 4, 3 and -7 swap and the array is sorted: [−7,3,5,7,9,14][-7,3,5,7,9,14]

Keyboard Shortcuts

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