Gradient LabSign up free

Home / GATE DA / 2024 / Q.41

GATE DA 2024, Q.41: What a recursive swap function does

ProgrammingRecursion in Python2 marksMCQ

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)

Checking your access…

Source: official GATE DA 2024 question paper and answer key (IISc Bengaluru). The question is lightly reworded; every number and option is kept.