Practice mode Data Structures

What does the array look like after the first pass of bubble sort in ascending order?

Correct answer D. [3, 7, 1, 5, 9]

Explanation

One pass compares adjacent pairs from left to right and swaps any that are out of order: 7 and 3 swap, 7 and 9 stay, 9 and 1 swap, then 9 and 5 swap, giving [3, 7, 1, 5, 9]. After each pass the largest remaining value has bubbled to its final position at the end; the array is not fully sorted after one pass.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.