GATE CS 2025 (Forenoon) — Question 33

AlgorithmsSearching, Sorting, Hashing MechanismsNAT1 markMedium

The pseudocode of a function fun( ) is given below:
c
1fun(int A[0, ..., n - 1]) {
2    for i = 0 to n - 2
3        for j = 0 to n - i - 2
4            if (A[j] > A[j + 1])
5                then swap A[j] and A[j + 1]
6}
7
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)
Practise the full 2025-FN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Searching, Sorting, Hashing MechanismsTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group