GATE CSE 2025 Session 1 Q33: Swaps made by bubble sort on a reversed array of 30
- Algorithms
- 1 mark
- NAT
- No negative marking
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 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 as argument, is __________. (Answer in integer)
Try it: numerical answer: type the value
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: .
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
Source: official GATE 2025 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key
More Algorithms PYQs
- 2026 Session 1 · Q17Solve nested recurrences T1 = 4T1(n/2) + T2, T2 = 5T2(n/4) + log n
- 2026 Session 1 · Q41Shortest paths with at most k edges: two statements
- 2026 Session 1 · Q47Condition forcing a vertex into every minimum vertex cover
- 2026 Session 1 · Q49Cycle and cut properties of MSTs with distinct weights
- 2026 Session 1 · Q50Impossible DFS discovery/finish orderings for a DAG edge
- 2026 Session 1 · Q55Properties of 2-colorable (bipartite) graphs