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

PYQ GATE 2025

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

fun(int A[0, ... , n-1]){for i=0 to n−2for j=0 to n−i−2if (A[j]>A[j+1])then swap A[j] and A[j+1]}\begin{aligned}&\text{fun(int A[0, ... , n-1])} \\ &\text{\{} \\ &\quad \text{for } i = 0 \text{ to } n-2 \\ &\quad \quad \text{for } j = 0 \text{ to } n-i-2 \\ &\quad \quad \quad \text{if } (A[j] > A[j+1]) \\ &\quad \quad \quad \quad \text{then swap A[j] and A[j+1]} \\ &\text{\}}\end{aligned}

Let 𝐴[0,…,29]𝐴[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()fun() is called with 𝐴[0,…,29]𝐴[0, … ,29] as argument, is __________. (Answer in integer)

Attempted by 259 students.

Sign up free to check your answer

Sign up free

Explore the full course: Algorithms

Loading lesson…