GATE Assistant

Past questions › Data Science and Artificial Intelligence › GATE 2024

GATE 2024 · DA · MCQ · 2 marks · Programming, Data Structures and Algorithms › Python Programming

GATE 2024 Data Science and Artificial Intelligence question: Consider the following Python function: code What does this Python function fun() do?…

Consider the following Python function:

def fun(D, s1, s2):
       if s1 < s2:
          D[s1], D[s2] = D[s2], D[s1]
          fun(D, s1+1, s2-1)

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.

Show answer

Official answer: C

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion