Skip to content
GATEiit

GATE CSE 2025 Session 1 Q33: Swaps made by bubble sort on a reversed array of 30

Question

The pseudocode of a function fun() is given below:

fun(int A[0,…,n-1]){
    for i=0 to n-2
        for j=0 to n-i-2
            if (A[j]>A[j+1])
                then swap A[j] and A[j+1]
}

Let A[0,…,29]A[0, \ldots, 29] be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun() is called with A[0,…,29]A[0, \ldots, 29] as argument, is __________. (Answer in integer)

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 435 (official GATE 2025 final answer key)

Concept used: Bubble sort makes one swap per inversion; a reversed array has every pair inverted.

First step: Count the inversions of 30 distinct numbers in descending order: (302)\binom{30}{2}.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2025 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key