Bubble Sort Process
We are sorting the list: [5, 2, 4, 3, 1].
Number 5 2 4 3 1
Index 0 1 2 3 4
We start the bubble sort:
Comparing index 0 and 1: 5 and 2
Number 5 2 4 3 1
Index 0 1 2 3 4
Since 5 > 2, we swap them:
List after swap: [2, 5, 4, 3, 1]
Number 2 5 4 3 1
Index 0 1 2 3 4
Next, we compare index 1 and 2: 5 and 4:
Comparing index 1 and 2: 5 and 4
Number 2 5 4 3 1
Index 0 1 2 3 4
Since 5 > 4, we swap them:
List after swap: [2, 4, 5, 3, 1]
Number 2 4 5 3 1
Index 0 1 2 3 4
Now we compare index 2 and 3: 5 and 3:
Comparing index 2 and 3: 5 and 3
Number 2 4 5 3 1
Index 0 1 2 3 4
Since 5 > 3, we swap them:
List after swap: [2, 4, 3, 5, 1]
Number 2 4 3 5 1
Index 0 1 2 3 4
Finally, we compare index 3 and 4: 5 and 1:
Comparing index 3 and 4: 5 and 1
Number 2 4 3 5 1
Index 0 1 2 3 4
Since 5 > 1, we swap them:
List after swap: [2, 4, 3, 1, 5]
Number 2 4 3 1 5
Index 0 1 2 3 4
Next Pass
We repeat the process until the entire list is sorted.
Conclusion
We sorted the list to become: [1, 2, 3, 4, 5] using bubble sort.