Computer Sciences > GATE 2025 SET-1 > Sorting
The pseudocode of a function fun () is given below:
Let A[0,...,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] as argument, is ______ (Answer in integer)

Correct : 435
Explanation:
The code is bubble sort using adjacent swaps whenever A[j] > A[j+1]. For an array of length n = 30 in strict descending order every pair (i,j) with i < j is an inversion. The number of inversions is n(nโ1)/2, so total swaps = 30ร29/2 = 435.
Total Unique Visitors
Loading......