Skip to main contentSkip to solution

Consider the following array [8, 7, 13, 1, -9, 4]. After the 4th4^{th} iteration of Bubble sort, how will the array look like?

Solution

✅ Correct Option: 4

Each pass of Bubble sort compares adjacent pairs from the left and swaps any pair that is out of order, so the largest remaining element moves to the end.

PassSwaps madeArray after the pass
18-7, 13-1, 13-(-9), 13-4[7, 8, 1, -9, 4, 13]
28-1, 8-(-9), 8-4[7, 1, -9, 4, 8, 13]
37-1, 7-(-9), 7-4[1, -9, 4, 7, 8, 13]
41-(-9)[-9, 1, 4, 7, 8, 13]

Options 1, 3 and 2 are the arrays after passes 1, 2 and 3 respectively, so each is a result of stopping too early.

Keyboard Shortcuts

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