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.
Similar Questions
A palindrome is a word that reads the same forwards and backwards. In a game
of words, a player has the following two plates painted with letters.
From...
Which number does not belong in the series below?
2, 5, 10, 17, 26, 37, 50, 64
Choose the word that is opposite in meaning to the word “coherent”.
Total Unique Visitors
Loading......