Skip to main contentSkip to solution

Consider the following array 'numList':

numList87131-94
Index012345

Arrange the following outputs of various passes as they occur when we apply 'Bubble sort' on the given array numList.

A. -9, 1, 4, 7, 8, 13

B. 7, 8, 1, -9, 4, 13

C. 1, -9, 4, 7, 8, 13

D. 7, 1, -9, 4, 8, 13

Solution

✅ Correct Option: 4

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

Starting array: 8, 7, 13, 1, -9, 4

Pass 1: 7, 8, 1, -9, 4, 13 (B)

Pass 2: 7, 1, -9, 4, 8, 13 (D)

Pass 3: 1, -9, 4, 7, 8, 13 (C)

Pass 4: -9, 1, 4, 7, 8, 13 (A)

Keyboard Shortcuts

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