Quiz Space

January 2023 term · Computational Thinking · BSCS1001

Computational Thinking (CT) End Term: 30 April 2023, Set QPF1-S2 (January 2023 term)

The IIT Madras BS Computational Thinking (Computational Thinking (CT)) End Term paper sat on 30 Apr 2023, in the January 2023 term, set QPF1-S2: 25 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
25
Marks
100
Duration
180 min
MCQ
15
Numerical
6
MSQ
4

Updated

Official paper: IIT M FOUNDATION ET1 EXAM QPF1 S2 30 Apr 2023 · No negative marking.

Question 1

+3 marksOne correct option

The following pseudocode is executed using the "Scores" dataset. What will count represent at the end of the execution?

text
1 count = 0
2 while(Table 1 has more rows){
3 flag1 = False, flag2 = False
4 Read the first row X in Table 1
5 if(X.Gender == 'F'){
6 flag1 = True
7 }
8 if(X.CityTown == "Chennai"){
9 flag2 = True
10 }
11 if(flag1 == flag2){
12 count = count + 1
13 }
14 Move X to Table 2
15 }
  1. A

    Number of students who are either female or are from Chennai.

  2. B

    Number of female students from other than Chennai.

  3. C

    Number of female students from Chennai + number of male students from other than Chennai.

  4. D

    Number of all students except female students from other than Chennai.

Show answer

Correct answer

  • C

    Number of female students from Chennai + number of male students from other than Chennai.

Question 2

+3 marksOne correct option

The following pseudocode is executed using the "Words" dataset. What will B represent at the end of the execution?

text
1 A = 0, B = 0
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(X.LetterCount > 4){
5 A = A + 1
6 }
7 else{
8 if(X.PartOfSpeech == "Noun"){
9 B = B + 1
10 }
11 }
12 Move X to Table 2
13 }
  1. A

    Number of nouns with letter count more than 4.

  2. B

    Number of words other than nouns with letter count more than 4.

  3. C

    Number of nouns with letter count less than or equal to 4.

  4. D

    Number of words other than nouns with letter count less than or equal to 4.

Show answer

Correct answer

  • C

    Number of nouns with letter count less than or equal to 4.

Question 3

+4 marksOne correct option

The following pseudocode is executed using the "Words" dataset. The variable count stores the number of words which are either nouns or have letter count at most 5, but not both. Choose the correct code fragment to complete the pseudocode.

text
1 count = 0
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(checkSomething(X)){
5 count = count + 1
6 }
7 Move X to Table 2
8 }
9
10 Procedure checkSomething(Y)
11 A = False, B = False
12 if(X.PartOfSpeech == "Noun"){
13 A = True
14 }
15 if(X.LetterCount <= 5){
16 B = True
17 }
18 **********************
19 *** Fill the code ***
20 **********************
21 End checkSomething
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 4

+4 marksOne correct option

The following pseudocode is executed using the "Library" dataset. At the end of the execution, N captures the name of a book written in a language other than English with the maximum number of pages, and A captures the number of pages in the book.

text
1 A = 0, N = "None"
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(X.Language != "English" and X.Pages => A){
5 A = X.Pages
6 N = X.Name
7 }
8 Move X to Table 2
9 }

Assume that the rows of the table are shuffled in any random order, choose the correct option.

  1. A

    There might be some change in the values of both A and N, based on the order of rows

  2. B

    There might be a change in the value of N, based on the order of rows

  3. C

    There will be NO change in the values of both A and N, based on the order of rows

  4. D

    There might be a change in the value of A, based on the order of rows

Show answer

Correct answer

  • B

    There might be a change in the value of N, based on the order of rows

Question 5

+4 marksOne correct option

The following pseudocode is executed using the "Scores" dataset. What will B represent at the end of the execution?

text
1 B = 0
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(X.Gender == 'M'){
5 if(X.Physics < 90){
6 B = B + 1
7 }
8 else{
9 if(X.Mathematics > 90){
10 B = B + 1
11 }
12 }
13 }
14 Move X to Table 2
15 }
  1. A

    Number of female students with Physics marks less than 90 and Mathematics marks more than 90

  2. B

    Number of male students with either Physics marks less than 90 or with Mathematics marks more than 90

  3. C

    Number of male students with Physics marks less than 90 and Mathematics marks more than 90

  4. D

    Number of female students with either Physics marks less than 90 or with Mathematics marks more than 90

Show answer

Correct answer

  • B

    Number of male students with either Physics marks less than 90 or with Mathematics marks more than 90

Question 6

+4 marksOne correct option

The following pseudocode is executed using the "Olympics" dataset. What will dict represent at the end of the execution?

text
1 dict = {}
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(isKey(dict, X.Name)){
5 if(not member(dict[X.Name], X.Medal)){
6 dict[X.Name] = dict[X.Name] ++ [X.Medal]
7 }
8 }
9 else{
10 dict[X.Name] = [X.Medal]
11 }
12 Move X to Table 2
13
14 }
  1. A

    A dictionary with player's names as keys mapped to the list of all the medals won by the player

  2. B

    A dictionary with player's names as keys mapped to the list of distinct medal types won by the player

  3. C

    A dictionary with medal types as keys mapped to the list of players who have won that medal

  4. D

    A dictionary with medal types as keys mapped to the list of unique players who have won that medal

Show answer

Correct answer

  • B

    A dictionary with player's names as keys mapped to the list of distinct medal types won by the player

Question 7

+4 marksOne correct option

The following pseudocode is executed using the "Scores" dataset. What will first(D[i]) - last(D[i]) represent for a given key i ?

text
1 D = {}
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(isKey(D, X.TownCity)){
5 if(first(D[X.TownCity]) < X.Mathematics){
6 D[X.TownCity] = [X.Mathematics, last(D[X.TownCity])]
7 }
8 if(last(D[X.TownCity]) > X.Mathematics){
9 D[X.TownCity] = [first(D[X.TownCity]), X.Mathematics]
10 }
11 }
12 else{
13 D[X.TownCity] = [X.Mathematics, X.Mathematics]
14 }
15 Move X to Table 2
16 }
  1. A

    The difference between highest and lowest Mathematics marks of the city i

  2. B

    The difference between overall highest and lowest Mathematics marks of the dataset

  3. C

    The difference between highest and second highset Mathematics marks of the city i

  4. D

    It will be always 0

Show answer

Correct answer

  • A

    The difference between highest and lowest Mathematics marks of the city i

Question 8

+6 marksOne correct option

The following pseudocode is executed using the “Words” dataset. What will wordCount represent at the end of the execution?

text
1 wordCount = 0
2 while(Table 1 has more rows){
3 Read the first row X in Table 1
4 if(checkSomething(X) == 1){
5 wordCount = wordCount + 1
6 }
7 Move X to Table 2
8 }
9
10 Procedure checkSomething(Y)
11 i = 1, C = 0
12 A = False, B = False
13 while(i <= Y.LetterCount){
14 if(ith letter of Y.Word is vowel){
15 if(A and not B){
16 C = 1
17 }
18 A = True, B = False
19 }
20 else{
21 if(not A and B){
22 C = 1
23 }
24 A = False, B = True
25 }
26 i = i + 1
27 }
28 return(C)
29 End checkSomething
  1. A

    Number of words in which vowels occur consecutively

  2. B

    Number of words in which no two vowels occur consecutively

  3. C

    Number of words in which either vowels or consonants occur consecutively

  4. D

    Number of words in which no two vowels and no two consonants occur consecutively

Show answer

Correct answer

  • C

    Number of words in which either vowels or consonants occur consecutively

Question 9

+6 marksOne correct option

Consider the following graph with six nodes. M is the 6 × 6 adjacency matrix corresponding to the graph below. Assume that M has already been computed.

What will the value of L be after executing the following pseudocode?

text
1 D = {}
2 L = []
3 D[2] = -1
4 D, L = searchPath(M, D, L, 2)
5
6 Procedure searchPath(graph, P, S, i)
7 S = S ++ [i]
8 foreach j in columns(graph){
9 if(graph[i][j] == 1 and not (isKey(P, j))){
10 P[j] = i
11 P, S = searchPath(graph, P, S, j)
12 }
13 }
14 return(P, S)
15 End searchPath
  1. A

    L = [2, 0, 1, 3, 4, 5]

  2. B

    L = [2, 0, 1, 3, 5, 4]

  3. C

    L = [2, 0, 1, 5, 4, 3]

  4. D

    L = [2, 0, 1, 5, 3, 4]

Show answer

Correct answer

  • B

    L = [2, 0, 1, 3, 5, 4]

Question 10

+4 marksNumerical answer

Consider the procedure given below where A and B are two rows in the "Words" dataset. Let procedure getSomething(A) returns a dictionary with characters of A.Word as keys mapped to their frequency in A.Word.

text
1 Procedure doSomething(A, B)
2 count = 0
3 dictA = getSomething(A)
4 dictB = getSomething(B)
5 foreach letter in keys(dictA){
6 if(iskey(dictB, letter)){
7 if(dictA[letter] == dictB[letter]){
8 count = count + 1
9 }
10 }
11 }
12 return(count)
13 End doSomething

Let X.Word = "developer" and Y.Word = "designer", then, what will doSomething(X, Y) return?

Show answer

Correct answer: 2

Question 11

+5 marksNumerical answer

What will the value of S be at the end of the execution of the following pseudocode?

text
L1 = [1, -1, 5]
L2 = [3, 1, 2]
S = doSomething(L1, L2) - doSomething(L2, L1)
Procedure doSomething(X, Y)
if(length(X) != length(Y)){
return(0)
}
if(length(X) == 1 and length(Y) == 1){
return(first(X) * first(Y))
}
return(first(X) * last(Y) + doSomething(rest(X), init(Y)))
End doSomething
Show answer

Correct answer: 0

Question 12

+3 marksOne or more correct options

Let D be a dictionary. Choose the correct statement(s) about the dictionary D. It is a Multiple Select Question (MSQ).

Select all that apply.

  1. A

    keys(D) is an ordered list

  2. B

    keys(D) is a list of distinct elements

  3. C

    All the values of D must be of the same datatype

  4. D

    Value of a key in D can be another dictionary

Show answer

Correct answers

  • B

    keys(D) is a list of distinct elements

  • D

    Value of a key in D can be another dictionary

Question 13

+4 marksOne or more correct options

reverse is a recursive procedure to reverse a list. Select the correct code fragment to complete the pseudocode given below. It is a Multiple Select Question (MSQ).

text
1 Procedure reverse(L)
2 if(length(L) <= 1){
3 return(L)
4 }
5 ********************
6 * Fill the code *
7 ********************
8 End reverse

Select all that apply.

  1. A

    return(reverse(rest(L)) ++ [first(L)])

  2. B

    return([last(L)] ++ reverse(rest(L)))

  3. C

    return([last(L)] ++ reverse(rest(init(L))) ++ [first(L)])

  4. D

    return([first(L)] ++ reverse(rest(init(L))) ++ [last(L)])

Show answer

Correct answers

  • A

    return(reverse(rest(L)) ++ [first(L)])

  • C

    return([last(L)] ++ reverse(rest(init(L))) ++ [first(L)])

Question 14

+5 marksOne or more correct options

The procedure visitedShop(B) returns the list of names of customers who have visited shop B in the "Shopping Bills" dataset. Additionally, each customer must be represented exactly once in the returned list. The following pseudocode may have mistakes. Identify all such mistakes(if any). Assume that all statements not listed in the options below are free of errors. It is a Multiple Select Question (MSQ).

text
1 Procedure visitedShop(shop)
2 S = {}
3 while(Pile 1 has more cards){
4 Read the top card X from Pile 1
5 if(X.ShopName == shop){
6 if(not(checkMember(S, X.CustomerName))){
7 S = [X.ShopName] ++ S
8 }
9 }
10 Move X to Pile 2
11 }
12 return(S)
13 End visitedShop
14
15 Procedure checkMember(L, name)
16 present = True
17 foreach x in L{
18 if(x == name){
19 present = True
20 exitloop
21 }
22 }
23 return(present)
24 End checkMember

Select all that apply.

  1. A

    Line 2: Incorrect initialization of S

  2. B

    Line 6: Incorrect condition to update S

  3. C

    Line 7: Incorrect update of S

  4. D

    Line 16: Incorrect initialization of present

  5. E

    No error

Show answer

Correct answers

  • A

    Line 2: Incorrect initialization of S

  • C

    Line 7: Incorrect update of S

  • D

    Line 16: Incorrect initialization of present

Question 15

+6 marksOne or more correct options

The following pseudocode is executed using the "Shopping Bills" dataset. At the end of the execution, L stores the list of distinct shops from which only one category of items have been bought. But the pseudocode may have mistakes. Identify all such mistakes (if any). Assume that all statements not listed in the options below are free of errors. It is a Multiple Select Question (MSQ).

text
1 A = {}
2 L = []
3 while(Pile 1 has more cards){
4 Read the top card X from Pile 1
5 if(not isKey(A, X.ShopName)){
6 A = updateDict(A, X)
7 }
8 else{
9 A[X.ShopName] = []
10 A = updateDict(A, X)
11 }
12 Move X to Pile 2
13 }
14 foreach k in keys(A){
15 if(length(A[k]) == 1){
16 L = L ++ [k]
17 }
18 }
19 Procedure updateDict(D, Y)
20 foreach Z in Y.ItemList{
21 if(not member(D, Z.Category)){
22 D[Y.ShopName] = D[Y.ShopName] ++ [Z.Category]
23 }
24 }
25 return(D)
26 End updateDict

Select all that apply.

  1. A

    Line 1: Incorrect initialization of A

  2. B

    Line 5: Incorrect conditional statement

  3. C

    Line 16: Incorrect update of L

  4. D

    Line 21: Incorrect conditional statement

  5. E

    Line 22: Incorrect updation of dictionary D

Show answer

Correct answers

  • B

    Line 5: Incorrect conditional statement

  • D

    Line 21: Incorrect conditional statement

Question 16

+4 marksOne correct option

stations is a list that contains the sequence of stations visited by a train from the "Trains" dataset. Each element in stations is a pair: [Name, Distance], the first entry is the name of the station, while the second entry is the distance of this station from the first station in the list.
maxDist is a procedure that accepts stations as a parameter and returns the names of a pair of consecutive stations which have the longest distance between them on this route. Complete the following procedure.

text
1 Procedure maxDist(stations)
2 pair = ["None", "None"]
3 max = 0, diff = 0
4 prev = first(stations)
5 foreach x in rest(stations){
6 diff = last(x) - last(prev)
7 *************************
8 * Fill the code *
9 *************************
10 prev = x
11 }
12 return(pair)
13 End maxDist

Based on the above data, answer the given subquestions.

There may be multiple pairs having the same maximum distance. If we wish to find a pair of stations closest to the first station in the list, which of the following is the correct code fragment?

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

Correct answer

  • A

Question 17

+4 marksOne correct option

stations is a list that contains the sequence of stations visited by a train from the "Trains" dataset. Each element in stations is a pair: [Name, Distance], the first entry is the name of the station, while the second entry is the distance of this station from the first station in the list.
maxDist is a procedure that accepts stations as a parameter and returns the names of a pair of consecutive stations which have the longest distance between them on this route. Complete the following procedure.

text
1 Procedure maxDist(stations)
2 pair = ["None", "None"]
3 max = 0, diff = 0
4 prev = first(stations)
5 foreach x in rest(stations){
6 diff = last(x) - last(prev)
7 *************************
8 * Fill the code *
9 *************************
10 prev = x
11 }
12 return(pair)
13 End maxDist

Based on the above data, answer the given subquestions.

There may be multiple pairs having the same maximum distance. If we wish to find a pair of stations closest to the last station in the list, which of the following is the correct code fragment?

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

Correct answer

  • B

Question 18

+3 marksOne correct option

trains is a list that contains information about trains associated with a station stn. Specifically, each element in this list is a pair: [Arrival, Departure]. If the arrival or departure time is empty, it is represented as "None".

text
1 flag1 = False, flag2 = True
2 count = 0
3 foreach x in trains{
4 if(first(x) == "None" or last(x) == "None"){
5 flag1 = True
6 }
7 else{
8 count = count + 1
9 }
10 }
11 if(count == length(trains)){
12 flag2 = False
13 }

Based on the above data, answer the given subquestions.

Which of the following statements about the variable flag1 is True at the end of execution of the given pseudocode?

  1. A

    It is True if and only if stn is a starting or ending station for at least one train in the list

  2. B

    It is False if and only if stn is a starting or ending station for at least one train in the list

  3. C

    It is True if and only if stn is a starting station for one train and ending station for some other train in the list

  4. D

    It is False if and only if stn is a starting station for one train and ending station for some other train in the list

Show answer

Correct answer

  • A

    It is True if and only if stn is a starting or ending station for at least one train in the list

Question 19

+3 marksOne correct option

trains is a list that contains information about trains associated with a station stn. Specifically, each element in this list is a pair: [Arrival, Departure]. If the arrival or departure time is empty, it is represented as "None".

text
1 flag1 = False, flag2 = True
2 count = 0
3 foreach x in trains{
4 if(first(x) == "None" or last(x) == "None"){
5 flag1 = True
6 }
7 else{
8 count = count + 1
9 }
10 }
11 if(count == length(trains)){
12 flag2 = False
13 }

Based on the above data, answer the given subquestions.

What does the variable count represent at the end of execution of the given pseudocode?

  1. A

    It is the number of trains associated with stn

  2. B

    It is the number of trains for which stn is a starting station

  3. C

    It is the number of trains for which stn is an ending station

  4. D

    It is the number of trains for which stn is neither a starting nor an ending station

Show answer

Correct answer

  • D

    It is the number of trains for which stn is neither a starting nor an ending station

Question 20

+4 marksOne correct option

trains is a list that contains information about trains associated with a station stn. Specifically, each element in this list is a pair: [Arrival, Departure]. If the arrival or departure time is empty, it is represented as "None".

text
1 flag1 = False, flag2 = True
2 count = 0
3 foreach x in trains{
4 if(first(x) == "None" or last(x) == "None"){
5 flag1 = True
6 }
7 else{
8 count = count + 1
9 }
10 }
11 if(count == length(trains)){
12 flag2 = False
13 }

Based on the above data, answer the given subquestions.

At the end of execution of the code given, what can be said about the values stored by the Boolean variables flag1 and flag2?

  1. A

    flag1 and flag2 always store the same value

  2. B

    flag1 and flag2 always store opposite values

  3. C

    flag1 always stores the value True

  4. D

    flag2 always stores the value True

Show answer

Correct answer

  • A

    flag1 and flag2 always store the same value

Question 21

+3 marksNumerical answer

Let M be the adjacency matrix of the graph G given below. Consider the procedure given below.

Based on above information, answer the given subquestions.

What will be the value of B at the end of the execution of the pseudocode given below?

Show answer

Correct answer: 0

Question 22

+3 marksNumerical answer

Let M be the adjacency matrix of the graph G given below. Consider the procedure given below.

Based on above information, answer the given subquestions.

What will be the value of B at the end of execution of pseudocode given below?

Show answer

Correct answer: 1

Question 23

+4 marksNumerical answer

Let M be the adjacency matrix of the graph G given below. Consider the procedure given below.

Based on above information, answer the given subquestions.

What will be the value of B at the end of execution of pseudocode given below?

Show answer

Correct answer: 0

Question 24

+4 marksOne correct option

Consider the procedure evaluate given below, where P and Q are the lists of same length. If L1 = [1, 2, 0, 4, 3] and L2 = [0, 2, 3, 5, 1] then answer the given subquestions.

text
1 Procedure evaluate(P, Q)
2 if(P == []){
3 return(P)
4 }
5 else{
6 c = first(P) * first(Q)
7 return([c] ++ evaluate(rest(P), rest(Q)))
8 }
9 End evaluate

What will evaluate(L1, L2) return?

  1. A

    [0, 4, 0, 20, 3]

  2. B

    [1, 4, 3, 9, 4]

  3. C

    [1, 10, 0, 8, 0]

  4. D

    [0, 4, 3, 20, 0]

Show answer

Correct answer

  • A

    [0, 4, 0, 20, 3]

Question 25

+3 marksNumerical answer

Consider the procedure evaluate given below, where P and Q are the lists of same length. If L1 = [1, 2, 0, 4, 3] and L2 = [0, 2, 3, 5, 1] then answer the given subquestions.

text
1 Procedure evaluate(P, Q)
2 if(P == []){
3 return(P)
4 }
5 else{
6 c = first(P) * first(Q)
7 return([c] ++ evaluate(rest(P), rest(Q)))
8 }
9 End evaluate

How many times will the procedure evaluate be called, excluding the main call?

Show answer

Correct answer: 5