Filter by year

Programming in Python questions

Q38

GATE DA 2024 DAProgramming in PythonMCQ2 marks−2/3 if wrong

Report a problem with Q38

What is wrong?
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?
Show answer without attempting

Loading the answer…

Q39

GATE DA 2024 DAProgramming in PythonMCQ2 marks−2/3 if wrong

Report a problem with Q39

What is wrong?
Consider the function computeS(X) whose pseudocode is given below:
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]?
Show answer without attempting

Loading the answer…

Q41

GATE DA 2024 DAProgramming in PythonMCQ2 marks−2/3 if wrong

Report a problem with Q41

What is wrong?
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.
Show answer without attempting

Loading the answer…

0/30 correct0 marks

Related topics in Programming Data Structures and Algorithms