Bubble sort is applied to [5, 1, 4, 2] in ascending order. What is the list after the first pass?
- [1, 4, 2, 5]
- [1, 5, 4, 2]
- [5, 4, 2, 1]
- [1, 2, 4, 5]
Answer
A) [1, 4, 2, 5]
Compare neighbours and swap if needed: (5,1)→swap, (5,4)→swap, (5,2)→swap. The largest value bubbles to the end. SLO CS-11-B-02 · Application
Computer Science MCQ · More Unit 2: Computational Thinking and Algorithms MCQs · Practise