Qualifier CT Set - II Solution
Qualifier CT Set - II Solution
Qualifier Set - II
Total Marks: 50 Duration: 45 mins
1. The following pseudocode is executed using the “Words” table. What will the value of
A represent at the end of the execution? [3 Marks]
A=0
while (Table 1 has more rows) {
Read the first row X in Table 1
if (X.PartOfSpeech == “Noun” and X.LetterCount ≥ 7) {
A=A+1
}
Move X to Table 2
}
a. Number of nouns
b. Number of words with the letter count at least 7
c. Number of nouns with the letter count at least 7
d. Number of nouns with the letter count at most 7
Solution:
• Inside the loop, we see an if-block. The variable A is incremented whenever the
if-condition evaluates to true. So, we need to see when this will happen.
• Let us take a closer look at the conditions that we are checking for:
X.PartOfSpeech == “Noun” and X.LetterCount ≥ 7
• First, we notice that there are two conditions. The first one checks if the part of
speech is a noun. The second condition checks if the letter count is at least 7.
• Both conditions are joined together by the “and” operator. So, the statement
evaluates to true if and only if both the conditions evaluate to true. This is the
same as saying that, “the word we are looking at is a noun with letter count at least
7”.
• In conclusion, the variable A represents the number of nouns with letter count at
least 7. This corresponds to option (c).
Computational thinking Qualifier Set - II Page 2 of 26
2. The following pseudocode is executed using the “Words” table. At the end of the execution,
A captures the maximum letter count of a word which is not a noun. Choose the correct code
fragment to complete the pseudocode. [3 Marks]
A=0
while (Table 1 has more rows) {
Read the first row X in Table 1
*********************
* Fill the code *
*********************
Move X to Table 2
}
a.
if (X.PartOfSpeech == “Noun” and X.LetterCount > A) {
A = X.LetterCount
}
b.
if (X.PartOfSpeech 6= “Noun” and X.LetterCount < A) {
A = X.LetterCount
}
c.
if (X.PartOfSpeech == “Noun” and X.LetterCount < A) {
A = X.LetterCount
}
d.
if (X.PartOfSpeech 6= “Noun” and X.LetterCount > A) {
A = X.LetterCount
}
Solution:
• We wish to find the maximum letter count of a word which is not a noun. As a first
step, we need to filter words which are not nouns using an if-condition.
if (X.PartOfSpeech 6= “Noun”) {
···
}
Computational thinking Qualifier Set - II Page 3 of 26
• The variable A contains the maximum letter count. We need to update A whenever
we come across a word with letter count greater than A. This can be done as follows:
if (X.LetterCount > A) {
A = X.LetterCount
}
• We need to combine the two conditions in such a way that A captures the maximum
letter count of words which are not nouns. One way to do that is to nest the two
if-conditions as follows:
if (X.PartOfSpeech 6= “Noun”) {
if (X.LetterCount > A) {
A = X.LetterCount
}
}
• A quick look at the options shows us that this particular form of the solution is not
present. Specifically, there is no nesting of if-conditions.
• Going back to the solution that we came up with, we can see that the two nested
if-conditions can be combined into a single if-condition using the “and” operator:
• In conclusion, option (d) is the correct code-fragment that we are looking for.
Computational thinking Qualifier Set - II Page 4 of 26
3. The following pseudocode is executed using the “Library” table. At the end of the execution,
A captures the second highest number of pages. Assume that the variable Max holds the value
of the highest number of pages of any book. Choose the correct code fragment to complete
the pseudocode. [3 Marks]
A=0
while (Table 1 has more rows) {
Read the first row X in Table 1
*********************
* Fill the code *
*********************
Move the row X to Table 2
}
a.
if (X.Pages > A) {
A = X.Pages
}
b.
if (X.Pages < Max and X.Pages > A) {
A = X.Pages
}
c.
if (X.Pages > Max and X.Pages < A) {
A = X.Pages
}
d.
if (X.Pages < Max) {
A = X.Pages
}
Solution:
• We wish to find the second highest number of pages among all the books in the
library. So, whatever book we pick up, the number of pages in it must be less than
the maximum number of pages:
• As in the previous question, we can either nest the two if-conditions, or have a single
if-condition that achieves the same result by using the “and” operator.
4. Let X be a row in the “Library” table. Let isShortFiction be a procedure which finds whether
the book X is a fictional book with at most 200 pages. Choose the correct code fragment to
complete the pseudocode. [3 Marks]
a.
if (X.Genre == “Fiction”) {
return (True)
}
else {
return (False)
}
b.
if (X.Genre == “Fiction” and X.Pages <= 200) {
return (False)
}
else {
return (True)
}
c.
if (X.Genre == “Fiction” and X.Pages <= 200) {
return (True)
}
else {
return (False)
}
d.
if (X.Genre == “Fiction” or X.Pages <= 200) {
return (True)
}
else {
return (False)
}
Computational thinking Qualifier Set - II Page 7 of 26
Solution:
• We are given a procedure that accepts a row from the table as a parameter and
determines if it is a work of fiction with at most 200 pages.
– Is the book’s genre fiction? The condition that we need to check is:
X.Genre == “Fiction”
– Does the book have at most 200 pages? The condition that we need to check is:
X.Pages ≤ 200
• The procedure is supposed to return True if and only if both the above conditions
are satisfied.
• Note that options (b) and (c) look very similar to each other. Both these options
have the same if-condition, but different return values. Option (b) is wrong because
its return values are swapped.
• In conclusion, option (c) is the correct code-fragment to complete the procedure given
in the question.s
Computational thinking Qualifier Set - II Page 8 of 26
5. The following pseudocode is executed using the “Scores” table. What will the value of
A represent at the end of the execution? [3 Marks]
A=0
while (Table 1 has more rows) {
Read the first row X in Table 1
B = True
if (X.Physics ≥ 70) {
B = False
}
if (X.Chemistry ≥ 70) {
B = False
}
if (X.Mathematics ≥ 70) {
B = False
}
if (B) {
A=A+1
}
Move X to Table 2
}
Solution:
• Let us go through the structure of the pseudocode. Notice that there are four non-
nested if-blocks, one after the other. The first three of these four blocks are similar.
The only difference is the subject name.
if (X.Physics ≥ 70) {
B = False
}
The variable B is being set to False whenever the physics marks is at least 70.
Computational thinking Qualifier Set - II Page 9 of 26
• Extending this observation to the first three if-blocks, we can see that the variable
B becomes False whenever the subject marks is at least 70.
if (B) {
A=A+1
}
The variable A is incremented whenever the value of B is True. Note that this is
equivalent to the following if-block:
if (B == True) {
A=A+1
}
• When will the value of B be True? Let us now go back to the beginning of the loop.
B is set to True. This is followed by three if-blocks. B is set to False whenever even
one of the subject marks is at least 70. So, B will remain True if and only if all the
subject marks are less than 70.
• From this, it follows that A represents the number of students with all subject marks
less than 70.
6. The following pseudocode is executed using the “Scores” table. At the end of the execution,
A captures the number of students students who are from Bengaluru or have Chemistry marks
less than the average Chemistry marks. Assume that the variable Avg holds the value of the
average Chemistry marks. The pseudocode may have mistakes. Identify all such mistakes (if
any). It is a Multiple Select Question (MSQ). [3 Marks]
1 A=0
2 while (Table 1 has more rows) {
3 Read the first row X in Table 1
4 C = False
5 if (X.CityTown == “Bengaluru”) {
6 C = True
7 }
8 if (X.Chemistry < Avg) {
9 C = False
10 }
11 if (C) {
12 A=1
13 }
14 Move X to Table 2
15 }
a. Error in Line 5
b. Error in Line 8
c. Error in Line 9
d. Error in Line 12
e. No error
Solution:
• There are no issues until line-4. This is clear from the options that are given to us.
• Since A captures the number of students satisfying the conditions given in the
question, A has to be incremented inside an if-block somewhere in the code. A
appears in only two places: in line-1 where it is initialized and in line-12 where it is
set to 1. Line-12 appears to be an error as A is not being incremented. At present,
this is only a guess. We will return to it soon.
• Let us now turn to the options given to us. Notice that line-11 cannot be an error
as it doesn’t find a place in the list of options. What this means is that, line-12 will
Computational thinking Qualifier Set - II Page 11 of 26
be executed only if the value of C is True at line-11. So, let us get back to the first
two if-blocks where the value of C is being altered.
• The if-block in lines 5-7 do not seem to have any problem. This is because, the
variable C is set to True whenever the student is from Bengaluru. This is in-line
with the statement given in the question.
• Now, we can see the role played by the variable C. It is set to True whenever one of
the conditions given in the statement becomes True.
• Now for the if-block in lines 8-10. If the chemistry marks is less than the average,
then the variable C is set to False. This is an error. We want the variable C to be
True whenever the chemistry marks are less than the average. So, there is an issue
with line-9. The correct statement should be
C = True
• Returning to the last if-block, we see that the variable A should be incremented
whenever C is True. So, the error in line-12 is confirmed. The correct statement
should be:
A=A+1
7. The following pseudocode is executed using the “Words” table. At the end of the execution,
A is set to True if and only if there is a pair of words with the same part of speech and the
same letter count. Choose the correct code fragment to complete the pseudocode. [3 marks]
A = False
while (Table 1 has more rows) {
Read the first row X in Table 1
Move X to Table 2
while (Table 1 has more rows) {
Read the first row Y in Table 1
Move Y to Table 3
*********************
* Fill the code *
*********************
}
Move all rows from Table 3 to Table 1
}
a.
if (X.PartOfSpeech == Y.PartOfSpeech and X.LetterCount == Y.LetterCount) {
A = True
}
b.
if (X.PartOfSpeech == Y.PartOfSpeech or X.LetterCount == Y.LetterCount) {
A = True
}
c.
if (X.PartOfSpeech == Y.PartOfSpeech or X.LetterCount == Y.LetterCount) {
A = False
}
d.
if (X.PartOfSpeech == Y.PartOfSpeech and X.LetterCount == Y.LetterCount) {
A = False
}
Computational thinking Qualifier Set - II Page 13 of 26
Solution:
• We want to look for words which have the same part of speech and same letter count.
The moment we find a word satisfying this condition, the variable A is set to True.
• So, we are looking at two conditions which have to be joined by means of the “and”
operator:
• Options (a) and (b) look similar. But note that the operator used in option (b) is
“or”. This is not what we want.
8. The following pseudocode is executed using the “Scores” table. What will the values of the
variables A and B represent at the end of the execution? [4 Marks]
A = 0, B = 0
while (Table 1 has more rows) {
Read the first row X in Table 1
if (X.Physics == A) {
B=B+1
}
if (X.Physics > A) {
A = X.Physics
B=1
}
Move X to Table 2
}
Solution:
• The variables A and B are initialized to zero to begin with. A cursory look at the
contents of the while loop help us make the following observations:
– B is being incremented inside the first if-block. B is being set to 1 inside the
second if-block. B might be keeping track of the count of something.
– The variable A seems to be keeping track of the maximum Physics marks.
• Now, let us go through the code line by line. In the first if-block, the value of B is
incremented whenever the value of physics marks of the student is equal to A. It is
still not clear why we might want to do this. So let us move to the second if-block.
• The second if-block must be quite familiar by now. It is used to find the maximum
physics marks in the table. But note that there is an extra statement: B = 1. What
this means is that, whenever we find a student with physics marks greater than the
current maximum, we update A and set B to be 1. Why is B being updated? This
is a question that we will return to in a while.
Computational thinking Qualifier Set - II Page 15 of 26
• With this information, let us revisit the first if-block. At some intermediate stage in
the iteration, let us say that the values of A and B are 88 and 1 respectively. Now,
if the row that we pick up from the table also has physics marks 88, then B will be
incremented. So, we see that B is counting the number of people whose physics score
is equal to the current maximum.
• We shall now go back to the second if-block to see why B has to be updated.
Whenever we find a student whose Physics score is greater than the current maximum,
we have to reset the variable B to 1. For, only then can we start counting the
number of students with this new maximum value. Why don’t we set B to 0? This
is because, we have already seen one student whose Physics score is equal to the
current maximum.
• In conclusion, A captures the highest Physics marks in the dataset, while B captures
the number of students with maximum Physics marks. Option (d) is the correct
answer.
Computational thinking Qualifier Set - II Page 16 of 26
9. The following pseudocode is executed using the “Scores” table. What will the value of
C represent at the end of the execution? [4 Marks]
C=0
while (Table 1 has more rows) {
Read the first row X from Table 1
Move X to Table 2
while (Table 1 has more rows) {
Read the first row Y in Table 1
if (DoTheyMatch(X, Y)) {
C=C+1
}
Move Y to Table 3
}
Move all rows from Table 3 to Table 1
}
a. Number of pairs of students with the same Physics marks and Chemistry marks
b. Number of pairs of students with their sum of Physics and Chemistry marks being the
same
c. Number of pairs students with sum of their subject marks being the same
d. Number of pairs of students with sum of their Physics marks same as the sum of their
Chemistry marks
Solution:
• Let us take a cursory look at the code and see how it is structured. We notice that it
is a nested iteration, i.e., there is one while loop inside the other. So, we are looking
at pairs of rows in the table and doing some operations on these pairs. Next, we
notice that the variable C is being incremented inside an if-block. So, C is counting
the number of pairs of students satisfying some condition.
• The next question to answer is the following: when is the variable C incremented?
It is incremented whenever the procedure DoTheyMatch returns the value True.
So, the followup question is, when does the procedure return the value True?
Computational thinking Qualifier Set - II Page 17 of 26
• In conclusion, the variable C represents the number of pairs of students with the sum
of their Physics marks same as the sum of their Chemistry marks. So, the correct
option is option (d).
Computational thinking Qualifier Set - II Page 18 of 26
10. The following pseudocode is executed using the “Words” table. At the end of the execution,
C captures the number of nouns with letter count at least four and at most eight. The
pseudocode may have mistakes. Identify all such mistakes (if any). It is a Multiple Select
Question (MSQ). [5 Marks]
1 C=1
2 while (Table 1 has more cards) {
3 Read the first row X from Table 1
4 if (CheckSomething(X, 4, 8)) {
5 C=C+1
6 }
7 Move X to Table 2
8 }
a. Error in Line 1
b. Error in Line 4
c. Error in Line 5
d. Error in Line 10
e. Error in Line 11
f. Multiple return(False) in procedure CheckSomething
g. No error
Computational thinking Qualifier Set - II Page 19 of 26
Solution:
• Let us first take a cursory look at the code. There are two sections into which the
code is cleanly divided. Lines 1-8 and lines 9-21.
• In lines 1-8, we are iterating through the rows in the table and incrementing the
variable C whenever some condition is satisfied. We notice that the variable C is
initialized to 1 at the beginning. This seems to be an error. We will get back to this
soon.
• From the statement of the question, we need to count the number of nouns that have
letter count at least four and at most eight. The procedure CheckSomething is
called at line-4, and the variable C is incremented whenever the procedure returns
the value True. It is safe to assume that the procedure checks if a given word satisfies
the required conditions.
• Let us now go through the procedure line by line. We are looking for nouns and the
if-condition in line-10 is checking for that. So, line-10 is error-free. Since lines 12, 15
and 19 do not appear in the list of options, there is no error in the return value of
the procedure. This leaves us with line-11.
• Line-11 is supposed to check if the letter count of the word is greater than C1 and
less than C2. But, it is checking if the letter count is greater than C1 and greater
than C2. So, there is an error in line-11. The correct version of line-11 is as follows:
• There are no other errors in lines 9-21. We return to lines 1-8 in the code. Clearly,
line-1 is an error. The variable C has to be initialized to zero. There are no other
errors in this segment.
• In conclusion, there are two errors in the code, line-1 and line-11. So the correct
options are (a) and (e).
Computational thinking Qualifier Set - II Page 20 of 26
11. The following pseudocode is executed using the “Scores” table. Let B be a positive integer
value. What does the procedure DoSomething compute? [5 marks]
a. Outputs “True” if and only if the difference between the maximum Chemistry marks and
the minimum Chemistry marks is at least B
b. Outputs “True” if and only if the difference between the maximum Chemistry marks and
the second maximum Chemistry marks is at most B
c. Outputs “True” if and only if the difference between the maximum Chemistry marks and
the second minimum Chemistry marks is at least B
d. Outputs “True” if and only if the difference between the maximum Chemistry marks and
the minimum Chemistry marks is more than B
Computational thinking Qualifier Set - II Page 21 of 26
Solution:
• From the last if-block in the procedure DoSomething, we see that it is returning
a boolean value. So, in order to determine what the procedure is computing, it is a
good idea to understand when it returns True and when it returns False.
• First, let us take the variable C. It is initialized to 0 before entering the loop. Inside
the loop, C is updated whenever the Chemistry marks in a given row exceeds the value
stored in C. It becomes clear that C is meant to capture the maximum Chemistry
marks in the dataset at the end of the iteration.
• Next, we take up the variable D. It is initialized to 100 before entering the loop.
During the course of the iteration, it is updated whenever the Chemistry marks in
a row is less than D. It becomes clear that D is meant to capture the minimum
Chemistry marks in the dataset at the end of the iteration.
• Putting these two observations together, we see that the expression C - D captures
the difference between the maximum Chemistry marks and the minimum Chemistry
marks.
• With the last piece of the puzzle in place, the procedure returns True if and only if
this difference is at least B.
12. The following pseudocode is executed using the “Library” table. At the end of the execution,
A captures the number of pairs of books which are released under same genre and in same
year but in different languages. The pseudocode may have mistakes. Identify all such mistakes
(if any). It is a Multiple Select Question (MSQ). [5 Marks]
1 A=0
2 while (Table 1 has more cards) {
3 Move X to Table 2
4 Read the first row X from Table 1
5 while (Table 1 has more rows) {
6 Read the first row Y from Table 1
7 B = True, C = False, D = True
8 if (X.Genre 6= Y.Genre) {
9 B = True
10 }
11 if (X.Year == Y.Year) {
12 C = False
13 }
14 if (X.Language == Y.Language) {
15 D = False
16 }
17 if (B and C and D) {
18 A=A+1
19 }
20 Move Y to Table 3
21 }
22 Move all rows from Table 3 to Table 1
23 }
Solution:
• As we did with the other questions, let us take a cursory glance at the pseudocode.
A is supposed to count the number of pairs of books satisfying some condition. So,
there are two questions that we have to ask:
– Is A initialized correctly? We can see that A is initialized in line-1. It seems to
be error-free.
– Is A incremented inside an if-block? We can see that A is incremented at line-
18. Line-18 seems error-free. However, we are not sure if line-17 is checking the
condition correctly.
• Next, we turn our attention to line-7, where three boolean variables are initialized.
As line-7 is not present in the list of options, there is nothing wrong with this
initialization.
• Another interesting point is that none of the if-conditions have any error. That is,
lines 8, 11, 14 and 17 do not appear in the list of options. So, all that remains for us
to do is to check if the variables inside these if-blocks are being updated correctly.
• As line-17 is error-free, we can also rule out line-18. A has to be incremented inside
some if-block. This leads to the next question: when is A incremented?
• A is incremented whenever all three boolean variables - B, C and D - are True. A
closely related question is: when should A be incremented?
• A should be incremented whenever a pair of books have the same genre and same
year but different languages. From this, it becomes clear that each boolean variable
checks for one of these conditions.
• One look at the code tells us that:
– B checks for genre
– C checks for year
– D checks for language
• Now, we want the same genre. But notice that the if-condition in line-8 checks if the
two genres are not equal. Since B starts with the value True, it should be updated
as False inside line 9. So, there is an error at line-9.
• Next, we want same year. Line-12 again has an error. This is because C starts off
as being false and must be set to true whenever the years are the same.
• Next, we come to the if-condition in line 14. D starts off as being True. Whenever
the languages are the same, it has to be updated to False. This is exactly what is
happening in line-15. So there is no error in line 15.
• Finally, when all three conditions are satisfied A is incremented.
• To summarize, the are two errors in this code. Options (b) and (c) are correct.
Computational thinking Qualifier Set - II Page 24 of 26
13. The following pseudocode is executed using the “Words” table. At the end of the execution,
C captures the number of pairs of words which have the same part of speech, or end with a
full stop and have the same letter count. Choose the correct code fragment(s) to complete the
pseudocode. It is a Multiple Select Question (MSQ). [6 marks]
C=0
while (Table 1 has more rows) {
Read the first row X in Table 1
Move X to Table 2
while (Table 1 has more rows) {
Read the first row Y in Table 1
Move Y to Table 3
*********************
* Fill the code *
*********************
}
Move all rows from Table 3 to Table 1
}
a.
if ((X.PartOfSpeech == Y.PartOfSpeech)
or (X.Word ends with a full stop and Y.Word ends with a full stop
and X.LetterCount == Y.LetterCount)) {
C=C+1
}
b.
if (X.PartOfSpeech == Y.PartOfSpeech) {
C=C+1
}
else {
if (X.Word ends with a full stop and Y.Word ends with a full stop
and X.LetterCount == Y.LetterCount) {
C=C+1
}
}
c.
if (X.PartOfSpeech == Y.PartOfSpeech) {
C=C+1
}
if (X.Word ends with a full stop and Y.Word ends with a full stop
and X.LetterCount == Y.LetterCount) {
C=C+1
}
d.
Computational thinking Qualifier Set - II Page 25 of 26
if (X.PartOfSpeech == Y.PartOfSpeech) {
if (X.Word ends with a full stop and Y.Word ends with a full stop
and X.LetterCount == Y.LetterCount) {
C=C+1
}
}
Solution:
• Let us first list down the three conditions that appear in the question:
• We are interested in counting the pairs that satisfy the following combination of
conditions:
(C 1) or (C 2 and C 3)
• Why have we used the brackets in this way? Why not have this:
(C 1 or C 2) and (C 3). This is because of the statement in the question which
says:
“number of pairs of words which have the same part of speech, or end with a full
stop and have the same letter count”
Because of the position of the comma, we read this as follows:
“number of pairs of words which (have the same part of speech), or (end with a full
stop and have the same letter count)”
• Now, we go through the options one by one. The first option has a single if-condition
that combines all three conditions. Notice the placement of the brackets. It can be
translated as follows:
if (C 1) {
C=C+1
else {
if (C 2 and C 3) {
C=C+1
}
This is also correct. Let us see why.
if (C 1) {
C=C+1
}
if (C 2 and C 3) {
C=C+1
}
This option is wrong. This is because, whenever both C 1 and (C 2 and C 3) are
True, we end up double counting.
if (C 1) {
if (C 2 and C 3) {
C=C+1
}
}
This option is again wrong. This is because, when we nest the two if-conditions, we
end up checking the following condition: (C 1 and C 2 and C 3). This is not what
we are looking for.