Skip to content
Exercises · Q1

Q.Consider a list of 10 elements:
numList =[7,11,3,10,17,23,1,4,21,5].
Display the partially sorted list after three complete passes of Bubble sort.

Punjab PsebTextbookSubjective· 3mImportance★★★★★
42% · 5/12 Questions
✓ Free question

Bubble sort repeatedly swaps adjacent out-of-order elements; after each complete pass the largest unsorted element "bubbles" to its correct position at the end. After three passes, the three largest numbers are in place at the right end.

Why Bubble Sort Passes?

Bubble sort works by making multiple passes through the list. In each pass, it compares adjacent elements and swaps them if they are in the wrong order. The key insight: after the first complete pass, the largest element ends up at the last position. After the second pass, the second-largest ends up at the second-last position, and so on. So after three passes, the three largest numbers are correctly placed at the end of the list.

Let's trace the passes step by step.

Initial list: [7, 11, 3, 10, 17, 23, 1, 4, 21, 5]

Pass 1 (largest element 23 bubbles to position 9)

ComparisonActionList after swap
7 vs 11No swap[7, 11, 3, 10, 17, 23, 1, 4, 21, 5]
11 vs 3Swap[7, 3, 11, 10, 17, 23, 1, 4, 21, 5]
11 vs 10Swap[7, 3, 10, 11, 17, 23, 1, 4, 21, 5]
11 vs 17No swap[7, 3, 10, 11, 17, 23, 1, 4, 21, 5]
17 vs 23No swap[7, 3, 10, 11, 17, 23, 1, 4, 21, 5]
23 vs 1Swap[7, 3, 10, 11, 17, 1, 23, 4, 21, 5]
23 vs 4Swap[7, 3, 10, 11, 17, 1, 4, 23, 21, 5]
23 vs 21Swap[7, 3, 10, 11, 17, 1, 4, 21, 23, 5]
23 vs 5Swap[7, 3, 10, 11, 17, 1, 4, 21, 5, 23]

After Pass 1: [7, 3, 10, 11, 17, 1, 4, 21, 5, 23]

Pass 2 (second-largest 21 bubbles to position 8)

ComparisonActionList after swap
7 vs 3Swap[3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
7 vs 10No swap[3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
10 vs 11No swap[3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
11 vs 17No swap[3, 7, 10, 11, 17, 1, 4, 21, 5, 23]
17 vs 1Swap[3, 7, 10, 11, 1, 17, 4, 21, 5, 23]
17 vs 4Swap[3, 7, 10, 11, 1, 4, 17, 21, 5, 23]
17 vs 21No swap[3, 7, 10, 11, 1, 4, 17, 21, 5, 23]
21 vs 5Swap[3, 7, 10, 11, 1, 4, 17, 5, 21, 23]

After Pass 2: [3, 7, 10, 11, 1, 4, 17, 5, 21, 23]

Pass 3 (third-largest 17 bubbles to position 7)

ComparisonActionList after swap
3 vs 7No swap[3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
7 vs 10No swap[3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
10 vs 11No swap[3, 7, 10, 11, 1, 4, 17, 5, 21, 23]
11 vs 1Swap[3, 7, 10, 1, 11, 4, 17, 5, 21, 23]
11 vs 4Swap[3, 7, 10, 1, 4, 11, 17, 5, 21, 23]
11 vs 17No swap[3, 7, 10, 1, 4, 11, 17, 5, 21, 23]
17 vs 5Swap[3, 7, 10, 1, 4, 11, 5, 17, 21, 23]

After Pass 3: [3, 7, 10, 1, 4, 11, 5, 17, 21, 23]

Watch out

A common mistake is to stop after three comparisons rather than three complete passes. Each pass goes through the unsorted portion of the list — which shrinks by one element after each pass because the largest remaining element is already in place.

Tip

You can verify your answer by checking that the three largest numbers (23, 21, 17) are at the last three positions, and that the remaining seven elements are in some partially sorted order.

✓Final answer

After three complete passes of Bubble sort, the partially sorted list is: [3, 7, 10, 1, 4, 11, 5, 17, 21, 23]

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.