Quiz Space

May 2021 term · Computational Thinking · BSCS1001

Computational Thinking (CT) Quiz 1: 11 July 2021, Set POD21QZBQPB (May 2021 term)

The IIT Madras BS Computational Thinking (Computational Thinking (CT)) Quiz 1 paper sat on 11 Jul 2021, in the May 2021 term, set POD21QZBQPB: 13 questions for 25 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
13
Marks
25
Duration
120 min
MCQ
12
MSQ
1

Updated

Official paper: IIT M QUIZ EXAM POD21QZAQPA FN 11 July 2021 · No negative marking.

Question 1

+1 markOne correct option

doSomething is a procedure that accepts a list of integers as input.

text
S = doSomething(L)
Procedure doSomething(L)
if (length(L) ≤ 1) {
return(0)
}
else {
return(first(L)-last(L) + doSomething(init(rest(L))))
}
End doSomething

Based on the above data, answer the given subquestions.

What will the value of S at the end of execution when L = [3, 2, 1, 0, 1, 2, 3]?

  1. A

    0

  2. B

    1

  3. C

    12

  4. D

    Error in the pseudocode

Show answer

Correct answer

  • A

    0

Question 2

+1 markOne correct option

doSomething is a procedure that accepts a list of integers as input.

text
S = doSomething(L)
Procedure doSomething(L)
if (length(L) ≤ 1) {
return(0)
}
else {
return(first(L)-last(L) + doSomething(init(rest(L))))
}
End doSomething

Based on the above data, answer the given subquestions.

What will the value of S at the end of execution when L = [3, 2, 1, 0, -1, -2, -3]?

  1. A

    0

  2. B

    1

  3. C

    12

  4. D

    Error in the pseudocode

Show answer

Correct answer

  • C

    12

Question 3

+2 marksOne correct option

The following pseudocode constructs a graph from the "Words" dataset. Each word position (Seq_No) is a node. The matrix M represents the graph. M[i][j] = 1 if there is an edge from node i to node j.

text
A = { }
while (Table 1 has more rows) {
Read the first row X in Table 1
A[X.Seq_No] = [X.LetterCount, X.PartOfSpeech]
Move X to Table 2
}
n = length(keys(A))
M = createMatrix(n, n)
foreach i in keys(A) {
foreach j in keys(A) {
if ((last(A[i]) ≠ last(A[j])) and isCompatible(A[i], A[j])) {
M[i][j] = 1
}
}
}
Procedure isCompatible(P, Q)
if ((first(P) - first(Q)) == 1) {
return (True)
}
else {
return (False)
}
End isCompatible

Study the pseudocode given above and answer the subquestions:

There will be an edge between word i and word j if and only if:

  1. A

    The letter count and part of speech of words i and j are same.

  2. B

    The letter count of word i is more than word j and both have same part of speech.

  3. C

    The letter count of word i is one more than word j and both have same part of speech.

  4. D

    The letter count of word i is one more than word j and both have different part of speech.

Show answer

Correct answer

  • D

    The letter count of word i is one more than word j and both have different part of speech.

Question 4

+1 markOne correct option

The following pseudocode constructs a graph from the "Words" dataset. Each word position (Seq_No) is a node. The matrix M represents the graph. M[i][j] = 1 if there is an edge from node i to node j.

text
A = { }
while (Table 1 has more rows) {
Read the first row X in Table 1
A[X.Seq_No] = [X.LetterCount, X.PartOfSpeech]
Move X to Table 2
}
n = length(keys(A))
M = createMatrix(n, n)
foreach i in keys(A) {
foreach j in keys(A) {
if ((last(A[i]) ≠ last(A[j])) and isCompatible(A[i], A[j])) {
M[i][j] = 1
}
}
}
Procedure isCompatible(P, Q)
if ((first(P) - first(Q)) == 1) {
return (True)
}
else {
return (False)
}
End isCompatible

Study the pseudocode given above and answer the subquestions:

All words in the dataset are connected to each other by edges.

  1. A

    TRUE

  2. B

    FALSE

Show answer

Correct answer

  • B

    FALSE

Question 5

+2.5 marksOne or more correct options

The following pseudocode constructs a graph from the "Scores" dataset. Each student position (Seq_No) is a node. The matrix B represents the graph. B[i][j] = 1 if there is an edge from node i to node j.

text
A = { }
while (Table 1 has more rows) {
Read the first row A in Table 1
A[X.Seq_No] = [X.Mathematics, X.Physics]
Move X to Table 2
}
n = length(keys(A))
B = createMatrix(n, n)
foreach i in keys(A) {
foreach j in keys(A) {
if (isGrouped(A[i], A[j])) {
B[i][j] = 1
}
}
}
Procedure isGrouped(P, Q)
if (first(P) < first(Q) and last(Q) < last(P)) {
return (True)
}
else {
return (False)
}
End isGrouped

Study the pseudocode given above and answer the subquestions:

There will be an edge between students i and j if and only if:
It is a Multiple Select Question (MSQ).

Select all that apply.

  1. A

    The Mathematics marks of i is lower than Mathematics marks of j and Physics marks of i is greater than Physics marks of j

  2. B

    The Mathematics marks of j is greater than Mathematics marks of i and Physics marks of j is lower than Physics marks of i

  3. C

    The Mathematics marks of i is greater than Mathematics marks of j and Physics marks of i is lower than Physics marks of j

  4. D

    The Mathematics marks of j is lower than Mathematics marks of i and Physics marks of j is greater than Physics marks of i

Show answer

Correct answers

  • A

    The Mathematics marks of i is lower than Mathematics marks of j and Physics marks of i is greater than Physics marks of j

  • B

    The Mathematics marks of j is greater than Mathematics marks of i and Physics marks of j is lower than Physics marks of i

Question 6

+2.5 marksOne correct option

The following pseudocode constructs a graph from the "Scores" dataset. Each student position (Seq_No) is a node. The matrix B represents the graph. B[i][j] = 1 if there is an edge from node i to node j.

text
A = { }
while (Table 1 has more rows) {
Read the first row A in Table 1
A[X.Seq_No] = [X.Mathematics, X.Physics]
Move X to Table 2
}
n = length(keys(A))
B = createMatrix(n, n)
foreach i in keys(A) {
foreach j in keys(A) {
if (isGrouped(A[i], A[j])) {
B[i][j] = 1
}
}
}
Procedure isGrouped(P, Q)
if (first(P) < first(Q) and last(Q) < last(P)) {
return (True)
}
else {
return (False)
}
End isGrouped

Study the pseudocode given above and answer the subquestions:

Choose the correct statement based on given pseudocode.

  1. A

    For all i and j, B[i][j] == B[j][i]

  2. B

    For all i, j with i ≠ j, if B[i][j] = 0 then B[j][i] = 1

  3. C

    For all i, j with i ≠ j, if B[i][j] = 1 then B[j][i] = 1

  4. D

    For all i, j with i ≠ j, if B[i][j] = 0 then B[j][i] = 0

  5. E

    For all i, j with i ≠ j, if B[i][j] = 1 then B[j][i] = 0

Show answer

Correct answer

  • E

    For all i, j with i ≠ j, if B[i][j] = 1 then B[j][i] = 0

Question 7

+2.5 marksOne correct option

Consider the given pseudocode. Two positive integers, p and q, are the input parameters of procedure mystery, where p≥q\mathbf{p} \geq \mathbf{q}.

text
A = mystery(p, q)
B = (p * q)/A
Procedure mystery(X, Y)
if (Y≠ 0) {
return(mystery(Y, revealMystery(X, Y)))
}
else {
return(X)
}
End mystery
Procedure revealMystery(U, V)
if (U ≠ V){
C = 0, i = 1
while (C ≤ U){
C = V * i
i = i + 1
}
D = U - V * (i - 2)
return(D)
}
else {
return(0)
}
End revealMystery

Based on the above data, answer the given subquestions.

  1. A
  2. B
  3. C
  4. D
  5. E
Show answer

Correct answer

  • B

Question 8

+1.5 marksOne correct option

Consider the given pseudocode. Two positive integers, p and q, are the input parameters of procedure mystery, where p≥q\mathbf{p} \geq \mathbf{q}.

text
A = mystery(p, q)
B = (p * q)/A
Procedure mystery(X, Y)
if (Y≠ 0) {
return(mystery(Y, revealMystery(X, Y)))
}
else {
return(X)
}
End mystery
Procedure revealMystery(U, V)
if (U ≠ V){
C = 0, i = 1
while (C ≤ U){
C = V * i
i = i + 1
}
D = U - V * (i - 2)
return(D)
}
else {
return(0)
}
End revealMystery

Based on the above data, answer the given subquestions.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 9

+1 markOne correct option

Consider the given pseudocode. Two positive integers, p and q, are the input parameters of procedure mystery, where p≥q\mathbf{p} \geq \mathbf{q}.

text
A = mystery(p, q)
B = (p * q)/A
Procedure mystery(X, Y)
if (Y≠ 0) {
return(mystery(Y, revealMystery(X, Y)))
}
else {
return(X)
}
End mystery
Procedure revealMystery(U, V)
if (U ≠ V){
C = 0, i = 1
while (C ≤ U){
C = V * i
i = i + 1
}
D = U - V * (i - 2)
return(D)
}
else {
return(0)
}
End revealMystery

Based on the above data, answer the given subquestions.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 10

+2.5 marksOne correct option

The following table contains the information regarding the players from the "Olympics" dataset. Each row in the table corresponds to a player and number of medals won by him/her. There are n players, each player is being assigned to a unique index between 0 and n−1.

S.NoPlayer NameNumber of Medals
0Karnam Malleswari1
...........
n - 1Michael Phelps28

The table is represented by a dictionary named players, with Player Name as keys and Number of Medals as values. Assume that players has already been computed. For example, we have: players[Karnam Malleswari] = 1

A graph G is generated from this table. Each node corresponds to a player. There is an edge between players i and j if and only if the player i has won more number of medals than player j.

text
matrix = createMatrix (n, n)
foreach i in keys (players) {
foreach j in keys (players) {
if (players[i] ≠ players[j] and players[i] < players[j]) {
matrix[i][j] = 1
}
}
}
A = { }
foreach i in rows (matrix) {
count = 0
foreach j in columns (matrix) {
if (i ≠ j and matrix [i][j] > 0) {
count = count + 1
}
}
A[i]= count
}

What will A[i] represent at the end of execution of above pseudocode?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 11

+2.5 marksOne correct option

The following pseudocode is executing using the "Scores" dataset. At the end of the execution, M represents a matrix generated from the "Scores" dataset.

text
D = { }
while (Table 1 has more rows) {
Read the first row X in Table 1
D[X.Seq_No] = {"P": X.Physics, "C": X.Chemistry, "M": X.Mathematics}
Move X to Table 2
}
matrixPh = getAdjMatrix(D, "P")
matrixCh = getAdjMatrix(D, "C")
matrixMa = getAdjMatrix(D, "M")
Procedure getAdjMatrix(D, Subject)
n = length(keys(D))
M = createMatrix(n,n)
foreach i in rows(M) {
foreach j in columns(M) {
if (i ≠ j) {
diff = D[i][Subject] - D[j][Subject]
if (10 ≤ diff and diff ≤ 20) {
M[i][j] = 1
}
}
}
}
return (M)
End getAdjMatrix

Choose the correct statement based on above pseudocode.

  1. A
  2. B
  3. C
  4. D
  5. E
Show answer

Correct answer

  • B

Question 12

+2.5 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 13

+2.5 marksOne correct option

The following table contains information regarding sports from the "Olympics" dataset. Each entry in the table corresponds to a sport and is played by at least three players. There is a pool of n players, each player being assigned a unique index between 0 and n−1. There are M sports in total.

S.NoPlayers List
0[4, 5, 6]
......
M - 1[1, 2, 3, 4]

The table is represented by a dictionary named sports, with the keys as serial numbers and values as the corresponding list of players. Assume that sports has already been computed. For example, we have: sports[0] = [4, 5, 6].

The following pseudocode constructs a matrix M from sports whose rows and columns correspond to players. Each entry M[i][j] denotes the number of sports played by both player i and player j. Choose the correct fragment to complete the pseudocode.

text
M = createMatrix(n, n)
foreach i in keys(sports) {
foreach j in sports[i] {
foreach k in sports[i] {
********************
* Fill the code *
********************
}
}
}
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B