>
Exams
>
Data Science and Artificial Intelligence
>
Programming in Python
>
consider the following python function def fun d s
Question:
Consider the following Python function :
def fun (D, s1, s2) :
if s1 s2:
D[s1], D[s2] = D[s2], D[sl]
fun (D, s1+1, s2-1)
What does this Python function fun () do? Select the ONE appropriate option below.
GATE DA - 2024
GATE DA
Updated On:
Jan 30, 2026
It finds the smallest element in D from index s1 to s2, both inclusive.
It performs a merge sort in-place on this list D between indices s1 and s2, both inclusive.
It reverses the list D between indices s1 and s2, both inclusive.
It swaps the elements in D at indices s1 and s2, and leaves the remaining elements unchanged.
Show Solution
Verified By Collegedunia
The Correct Option is
C
Solution and Explanation
The correct option is (C) : It reverses the list D between indices s1 and s2, both inclusive..
Download Solution in PDF
Was this answer helpful?
0
0
Top GATE DA Data Science and Artificial Intelligence Questions
Consider performing depth-first search (DFS) on an undirected and unweighted graph G starting at vertex s. For any vertex u in G, d[u] is the length of the shortest path from s to u. Let (u, v) be an edge in G such that d[u] < d[v]. If the edge (u, v) is explored first in the direction from u to v during the above DFS, then (u, v) becomes a _____ edge.
GATE DA - 2024
Data Science and Artificial Intelligence
Database Concepts
View Solution
Three fair coins are tossed independently. T is the event that two or more tosses result in heads. S is the event that two or more tosses result in tails. What is the probability of the event T ∩ S?
GATE DA - 2024
Data Science and Artificial Intelligence
Probability
View Solution
Consider the matrix
\(M=\begin{bmatrix} 2 & -1 \\ 3 & 1 \end{bmatrix}\)
.
Which ONE of the following statements is TRUE ?
GATE DA - 2024
Data Science and Artificial Intelligence
Matrix
View Solution
For any twice differentiable function ƒ: R → R, if at some x* ∈ R, f'(x*) = 0 and f'(x*) > 0, then the function f necessarily has a ______ at x = x*.
Note : R denotes the set of real numbers.
GATE DA - 2024
Data Science and Artificial Intelligence
Differential Equations
View Solution
Match the items in Column 1 with the items in Column 2 in the following table :
Column 1
Column 2
(p)
First In First Out
(i)
Stacks
(q)
Lookup Operation
(ii)
Queues
(r)
Last In First Out
(iii)
Hash Tables
GATE DA - 2024
Data Science and Artificial Intelligence
Hashing
View Solution
View More Questions
Top GATE DA Programming in Python Questions
Consider the following Python code :
def count (child_dict, i) :
if i not in child_dict.keys() :
return 1
ans = 1
for j in child_dict[i] :
ans += count (child_dict, j)
return ans
child_dict = dict()
child_dict [0] = [1, 2]
child_dict [1] = [3, 4, 5]
child_dict [2] = [6, 7, 8]
print (count(child_dict,0))
Which ONE of the following is the output of this code ?
GATE DA - 2024
Data Science and Artificial Intelligence
Programming in Python
View Solution
Consider the function computes (X) whose pseudocode is given below :
\(\frac{\text{computeS (X)}}{S[1] ←1}\)
for i ← 2 to length(X)
S[i] ← 1
if X[i-1] ≤ X[i]
S[i] ← S[i] + S[i - 1]
end if
end for
return S
Which ONE of the following values is returned by the function computeS (X) for X= [6, 3, 5, 4, 10] ?
GATE DA - 2024
Data Science and Artificial Intelligence
Programming in Python
View Solution
Top GATE DA Questions
Consider performing depth-first search (DFS) on an undirected and unweighted graph G starting at vertex s. For any vertex u in G, d[u] is the length of the shortest path from s to u. Let (u, v) be an edge in G such that d[u] < d[v]. If the edge (u, v) is explored first in the direction from u to v during the above DFS, then (u, v) becomes a _____ edge.
GATE DA - 2024
Database Concepts
View Solution
Three fair coins are tossed independently. T is the event that two or more tosses result in heads. S is the event that two or more tosses result in tails. What is the probability of the event T ∩ S?
GATE DA - 2024
Probability
View Solution
Consider the matrix
\(M=\begin{bmatrix} 2 & -1 \\ 3 & 1 \end{bmatrix}\)
.
Which ONE of the following statements is TRUE ?
GATE DA - 2024
Matrix
View Solution
For any twice differentiable function ƒ: R → R, if at some x* ∈ R, f'(x*) = 0 and f'(x*) > 0, then the function f necessarily has a ______ at x = x*.
Note : R denotes the set of real numbers.
GATE DA - 2024
Differential Equations
View Solution
Match the items in Column 1 with the items in Column 2 in the following table :
Column 1
Column 2
(p)
First In First Out
(i)
Stacks
(q)
Lookup Operation
(ii)
Queues
(r)
Last In First Out
(iii)
Hash Tables
GATE DA - 2024
Hashing
View Solution
View More Questions