GATE DA 2024 — Question 41

Programming, Data Structures and AlgorithmsProgramming in PythonMCQ2 marks · −2/3 if wrongEasy

Consider the following Python function:
python
1def fun(D, s1, s2):
2    if s1 < s2:
3        D[s1], D[s2] = D[s2], D[s1]
4        fun(D, s1+1, s2-1)
5
What does this Python function fun() do? Select the ONE appropriate option below.
  1. A
    It finds the smallest element in D from index s1 to s2, both inclusive.
  2. B
    It performs a merge sort in-place on this list D between indices s1 and s2, both inclusive.
  3. C
    It reverses the list D between indices s1 and s2, both inclusive.
  4. D
    It swaps the elements in D at indices s1 and s2, and leaves the remaining elements unchanged.
Practise the full 2024 paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Programming in PythonTimed, 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