Consider the function computeS() whose pseudocode is given below:
Which ONE of the following values is returned by the function computeS() for = [6, 3, 5, 4, 10]?
code
- A[1, 1, 2, 3, 4]
- B[1, 1, 2, 3, 3]
- C[1, 1, 2, 1, 2]
- D[1, 1, 2, 1, 5]
Programming, Data Structures and AlgorithmsProgramming in PythonMCQ2 marks · −2/3 if wrongEasy
1computeS(X)
2 S[1] ← 1
3 for i ← 2 to length(X)
4 S[i] ← 1
5 if X[i − 1] ≤ X[i]
6 S[i] ← S[i] + S[i − 1]
7 end if
8 end for
9 return S
10A GATE question every morning
One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.