Skip to main contentSkip to solution

Apply bubble sort technique to sort list of elements given below:

numList2 = [2, 7, 5, 8, 4]

In which pass the last swap happens?

Solution

✅ Correct Option: 3

Bubble sort compares adjacent elements and swaps them if they are out of order.

PassSwaps madeList after the pass
17,57,5 and 8,48,4[2, 5, 7, 4, 8]
27,47,4[2, 5, 4, 7, 8]
35,45,4[2, 4, 5, 7, 8]
4none[2, 4, 5, 7, 8]

The list becomes sorted in Pass 3, so the last swap happens there.


Option 4: Pass 4 is only needed to confirm that the list is sorted. No swap occurs in it.

Keyboard Shortcuts

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