Skip to main contentSkip to solution

Identify the number of swaps required in the first pass of bubble sort for the following list :-

list= [8, 7, 13, 1, -9, 4]

Solution

✅ Correct Option: 2

In the first pass, bubble sort compares each adjacent pair from left to right and swaps the pair whenever the left element is larger.

ComparisonSwap?List after comparisonSwaps so far
8 and 7Yes[7, 8, 13, 1, -9, 4]1
8 and 13No[7, 8, 13, 1, -9, 4]1
13 and 1Yes[7, 8, 1, 13, -9, 4]2
13 and -9Yes[7, 8, 1, -9, 13, 4]3
13 and 4Yes[7, 8, 1, -9, 4, 13]4

The largest element, 13, moves to the end in this pass.

Keyboard Shortcuts

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