How many passes does a Bubble sort algorithm require for sorting a given list of 'n' items?

This question was previously asked in
ESE Electronics 2011 Paper 2: Official Paper
View all UPSC IES Papers >
  1. n2
  2. √n
  3. n + 1
  4. n - 1

Answer (Detailed Solution Below)

Option 4 : n - 1
Free
ST 1: UPSC ESE (IES) Civil - Building Materials
6.4 K Users
20 Questions 40 Marks 24 Mins

Detailed Solution

Download Solution PDF

Concept:

Bubble sort:

It is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order.

Compare the neighbours, if greater, swap.

E.g. Let’s i / p is 70, 20, 35, 90, 15, 11, 24

No. of elements (n) = 7

Pass – 1: 20, 35, 70, 15, 11, 24, } 90 → 6 comparison

Pass – 2: 20, 35, 15, 11, 24, } 70, 90 → 5 comparison

Pass – 3: 20, 15, 11, 24, } 35, 70, 90 → 4 comparison

Pass – 4: 15, 11, 20, } 24, 35, 70, 90 → 3 comparison

Pass – 5: 11, 15, } 20, 24, 35, 70, 90 → 2 comparison

Pass – 6: 11, 15, 20, 24, 35, 70, 90 → 1 comparison

No. of passes = 6

Note: Bubble sort with n element required n - 1 passes.

Total comparisons: (n1)n2

Latest UPSC IES Updates

Last updated on Jul 2, 2025

-> ESE Mains 2025 exam date has been released. As per the schedule, UPSC IES Mains exam 2025 will be conducted on August 10. 

-> UPSC ESE result 2025 has been released. Candidates can download the ESE prelims result PDF from here.

->  UPSC ESE admit card 2025 for the prelims exam has been released. 

-> The UPSC IES Prelims 2025 will be held on 8th June 2025.

-> The selection process includes a Prelims and a Mains Examination, followed by a Personality Test/Interview.

-> Candidates should attempt the UPSC IES mock tests to increase their efficiency. The UPSC IES previous year papers can be downloaded here.

More Sorting Questions

Get Free Access Now
Hot Links: teen patti rich lucky teen patti teen patti rummy