CBSE Class 12

Computer Science

05 Sorting

30
Total
0
Attempted
0
Correct
0
Wrong
00:00:00
Q-1
Consider the following Bubble Sort pass on the list [5, 1, 4, 2]. What will be the list after the first complete pass?
Medium Bubble Sort
Reference Code
```python
arr = [5,1,4,2]
for i in range(len(arr)-1):
    if arr[i] > arr[i+1]:
        arr[i], arr[i+1] = arr[i+1], arr[i]
print(arr)
A [1, 4, 2, 5]
B [1, 5, 2, 4]
C [1, 4, 5, 2]
D [5, 1, 2, 4]
Answer: [1, 4, 2, 5]
Explanation: Largest element moves to the end during the first pass → [1,4,2,5].