GATE DA 2024, Q.41: What a recursive swap function does
The question
def fun(D, s1, s2): if s1 < s2: swap D[s1] and D[s2], then call fun(D, s1 + 1, s2 − 1). What does fun() do?
def fun(D, s1, s2):
if s1 < s2:
D[s1], D[s2] = D[s2], D[s1]
fun(D, s1+1, s2-1)- (A) Finds the smallest element of D from index s1 to s2
- (B) Performs an in-place merge sort of D between s1 and s2
- (C) Reverses D between indices s1 and s2, both inclusive
- (D) Swaps D[s1] and D[s2] and leaves the rest unchanged
Checking your access…
The answer and full solution are in the GATE DA past-paper pack. All 195 questions from 2024, 2025 and 2026, each solved step by step and checked against the official key. ₹499, lifetime access.
What's in the pack · 60 questions are free to try.
Unlock this solution and every other question. ₹499, one payment, lifetime access.
Could not load the solution. Refresh the page, or email hello@gradientlab.dev.
Source: official GATE DA 2024 question paper and answer key (IISc Bengaluru). The question is lightly reworded; every number and option is kept.