Sorting · Class 12 · CBSE · Science Computer Science

A single left-to-right pass of bubble sort is performed in ascending order on the list [7, 2, 5, 3, 1]. What will the list be after this pass?

Practice question from Sorting (Class 12 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

medium · MCQ · Q-BE9757

A single left-to-right pass of bubble sort is performed in ascending order on the list [7, 2, 5, 3, 1]. What will the list be after this pass?

  1. A.[1, 2, 3, 5, 7]
  2. B.[2, 5, 3, 1, 7]Correct answer
  3. C.[2, 3, 5, 1, 7]
  4. D.[7, 2, 5, 3, 1]

Solution

Compare adjacent elements from left to right: [7,2,5,3,1] becomes [2,7,5,3,1], then [2,5,7,3,1], then [2,5,3,7,1], and finally [2,5,3,1,7]. Thus, the largest element moves to the last position after one pass.

More from Sorting

All of Sorting

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed