Mock Set - II: Computational Thinking
Mock Set - II: Computational Thinking
Mock Set - II
Total Marks: 50 Duration: 45 mins
1. The following pseudocode is executed using the “Scores” table. What will the value of
A represent at the end of execution? [3 Marks]
A=0
while (Table 1 has more rows) {
Read the first row X in Table 1
if (X.Gender == “M” and X.CityTown == “Chennai”) {
A = A + X.Mathematics
}
Move X to Table 2
}
Solution: In the question we need to find what A will represent at the end of the execution.
Here initially A is assigned to 0, and A is only updated when the condition, if (X.Gender ==
“M” and X.CityTown == “Chennai”), is satisfied.
We have two conditions inside the if ( ) which is separated by ‘and’, therefore both of
the conditions need to be satisfied to update A. Here the update statement is A = A +
X.Mathematics where the mathematics marks of current card X is added to A.
Computational thinking Mock Set - II Page 2 of 20
2. The following pseudocode is executed using the “Library” table. At the end of the execution,
the variable A captures the maximum number of pages of a book which is written in a language
other than English. 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.Language == “English” and X.Pages > A) {
A = X.Pages
}
b.
if (X.Language 6= “English” and X.Pages > A) {
A = X.Pages
}
c.
if (X.Language 6= “English” and X.Pages < A) {
A = X.Pages
}
d.
if (X.Language == “English” and X.Pages < A) {
A = X.Pages
}
Solution: At the end of the execution A captures the maximum number of pages of a book
which is written in a language other than English. Here initially A is assigned to 0.
Also we have one more condition to be satisfied which is language of the book shouldn’t be of
English.
Therefore the code block which complete the pseudocode is
if (X.Language 6= “English” and X.Pages > A) {
A = X.Pages
}
Computational thinking Mock Set - II Page 3 of 20
3. The following pseudocode is executed using the “Scores” table. At the end of the execution,
A captures the second highest mark in Mathematics. Assume that the variable Max holds
the value of the highest mark in Mathematics. 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.Mathematics > A) {
A = X.Mathematics
}
b.
if (X.Mathematics > Max and X.Mathematics < A) {
A = X.Mathematics
}
c.
if (X.Mathematics < Max and X.Mathematics > A) {
A = X.Mathematics
}
d.
if (X.Mathematics < Max) {
A = X.Mathematics
}
Solution: In the question we need to store the second highest mark in A, where highest mark
is already stored in the variable Max. Initially A is initialised to 0.
To store the maximum number of pages, A needs to be updated as A = X.Pages whenever
X.Pages > A. But here we need to store the second highest mark in A and hence we need to
ensure X.Mathematics is lesser than the Max.
Therefore the code block which complete the pseudocode is
if (X.Mathematics < Max and X.Mathematics > A) {
A = X.Mathematics
}
Computational thinking Mock Set - II Page 4 of 20
4. Let X be a row in the “Words” table. Let isShortVerb be a procedure to find whether the
word in the row X is a verb with letter count at most five. Choose the correct code fragment
to complete the pseudocode. [3 Marks]
a.
if (X.PartOfSpeech == “Verb”) {
return (True)
}
else {
return (False)
}
b.
if (X.PartOfSpeech == “Verb” and X.LetterCount ≤ 5) {
return (False)
}
else {
return (True)
}
c.
if (X.PartOfSpeech == “Verb” or X.LetterCount ≤ 5) {
return (True)
}
else {
return (False)
}
d.
if (X.PartOfSpeech == “Verb” and X.LetterCount ≤ 5) {
return (True)
}
else {
return (False)
}
Solution: isShortVerb is a procedure which finds whether the word in the row X is a verb
with letter count at most five.
We need the procedure to return ‘True’ when both the conditions,“word is a verb” and “letter
count atmost 5”, are satisfied.
Computational thinking Mock Set - II Page 5 of 20
5. The following pseudocode is executed using the “Words” table. What will the value of
A represent at the end of execution? [3 Marks]
A=0
while (Table 1 has more rows) {
Read the first row X in Table 1
i = 1, B = True
while (i ≤ X.LetterCount) {
if (ith letter of X.Word is a vowel) {
B = False
}
i=i+1
}
if (B) {
A=A+1
}
Move X to Table 2
}
Solution: We need to find what A will represent at the end of the execution. Here initially
A is assinged to 0 and A is only updated when B is ’True’.
Initially we have a while (Table 1 has more rows) loop which iterates along each and every
word in the paragraph. Inside the loop we initialise B to ’True’.
Following we have nested loop, while (i ≤ X.LetterCount), inside the above mentioned while
loop. Here we are iterating through every letter of the X.Word .
Inside the nested loop, while (i ≤ X.LetterCount), we are checking the condition if (ith letter
of X.Word is a vowel). When the condition satisfied at least once B is updated as ‘False’.
Since the A is updated inside the while (Table 1 has more rows) and outside the while (i ≤
X.LetterCount) loop, A is updated when X.Word contains no vowels in it.
Computational thinking Mock Set - II Page 7 of 20
6. The following pseudocode is executed using the “Library” table. At the end of the execution,
A captures the number of books which are published after 2010 or have less than the average
number of pages. Assume that the variable Avg holds the value of the average number of
pages of the books in the table. 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.Year > 2010) {
6 C = True
7 }
8 if (X.Pages > Avg) {
9 C = True
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: A captures the number of books which are published after 2010 or have less than
the average number of pages. We need to find the mistakes in the pseudocode.
Since A captures the number of books, A needs to be incremented once the conditions
satisfied. But in Line 12 A is always assigned to 1. This is one of mistake in the pseudocode.
The correct statement would be A =A +1.
Here for each book C is initialised to ‘False’ and we have two if blocks, in the code, which
is used to update, C to ‘True’, once the conditions inside the if blocks are satified. Here in
the second if block, Line 8, if (X.Pages > Avg), it checks whether the pages are greater than
average pages. This is another mistake. We need to check whether the pages are lesser than
the average pages. So correct statement would be if (X.Pages < Avg)
Computational thinking Mock Set - II Page 8 of 20
7. The following pseudocode is executed using the “Library” table. At the end of the execution,
A is set to True if and only if there is a pair of books with same genre and same year of
publication. 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.Genre == Y.Genre or X.Year == Y.Year ) {
A = True
}
b.
if (X.Genre == Y.Genre and X.Year == Y.Year ) {
A = True
}
c.
if (X.Genre == Y.Genre or X.Year == Y.Year ) {
A = False
}
d.
if (X.Genre == Y.Genre and X.Year == Y.Year ) {
A = False
}
Solution: We need to set A to ‘True’ if there is a pair of books with same genre and same
year of publication. Initially A is assigned as ‘False’,
As we need to compare each book with all other books we have nested loop in this pseudocode.
Once we find a pair which satisfies the conditions we need to assign A to ‘True’.
Here there are two conditions to be satisfied, ”Books should be same genre” and ”Books should
be same publication”.
Therefore the code block which complete the pseudocode is
if (X.Genre == Y.Genre and X.Year == Y.Year ) {
A = True
}
Computational thinking Mock Set - II Page 9 of 20
8. The following pseudocode is executed using the “Library” 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.Pages == A) {
B=B+1
}
if (X.Pages > A) {
A = X.Pages
B=1
}
Move X to Table 2
}
Solution: In the question we need to find what A and B will represent at the end of the
execution. Here initially A and B is assigned to 0.
if (X.Pages == A) {
B=B+1
}
Code-block 2
if (X.Pages > A) {
A = X.Pages
B=1
}
Code-block 2 is used to find the maximum number of pages across all the books. Her
whenever, A is updated, the value of B is assigned as 1.
Computational thinking Mock Set - II Page 10 of 20
9. The following pseudocode is executed using the “Words” 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
if (X.Word ends with a full stop) {
C = C + GetSomething(Table 2)
Clear all rows in Table 2
}
}
a. Number of pairs of words with the same part of speech and letter count
b. Number of pairs of words with the same part of speech and different letter count
c. Number of pairs of words with the same part of speech and letter count, that occur in
the same sentence
d. Number of pairs of words with same part of speech and different letter count, that occur
in the same sentence
Solution:In the pseudocode an iteration, while (....), is used to go through each and every
words in the paragraph and the words in Table 1 is moved to Table 2 till the condition, if
(X.Word ends with a full stop), is satisfied. Here Table 2 contains the words of a single
sentence. C is updated using the return value of the Procedure GetSomething inside the
if condition.
The procedure Procedure GetSomething takes the parameter as Table 2 which is essentially
words of a sentence. Using nested while conditions each and every pair of words in a sentence is
compared. For comparison condition, if (X.LetterCount 6= Y.LetterCount and X.PartOfSpeech ==
Computational thinking Mock Set - II Page 12 of 20
10. Let A be an author who had written a book in the “Library” table and B be a positive integer
value. What does the procedure DoSomething compute? [5 marks]
a. Outputs “True” if and only if the second book of the author A was published at least
B years after their first book was published
b. Outputs “True” if and only if the last book of the author A was published at least B years
after their first book was published
c. Outputs “True” if and only if the last book of the author A was published at least B years
after their second-last book was published
d. Outputs “True” if and only if the last book of the author A was published at least B years
before their first book was published
e. None of the above
Solution: Here the procedure DoSomething accepts the parameters A, author, and B, a
positive integer.
An iteration, while (....), is used to go through each and every rows in the table. Inside the
loop nested if conditions are used. The outer if, if (X.Author == A), condition checks whether
the author of the book matches with the parameter A.
There are two if conditions inside the outer if, if (X.Year < D) and if (X.Year < D). Here
the first condition save the year of last book published in variable C and the second condition
saves the year of first book published in D.
Computational thinking Mock Set - II Page 14 of 20
After the while loop, the last block of if, if (C−D ≥ B), checks whether the difference between
the year of last book and first book is atleast B.
Computational thinking Mock Set - II Page 15 of 20
11. The following pseudocode is executed using the “Scores” table. At the end of the execution,
A captures the number of female students who are above average in at least one subject.
Assume that the variables M, P and C hold the average marks of the subjects Mathematics,
Physics and Chemistry respectively. 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 Read the first row X from Table 1
4 if (CheckSomething(X, M, P, C)) {
5 A=1
6 }
7 Move X to Table 2
8 }
a. Error in Line 4
b. Error in Line 5
c. Error in Line 10
d. Error in Line 11
e. Multiple return(False) in procedure CheckSomething
f. No error
Solution: Here the A which captures the number of female students who are above average
in at least one subject. An iteration, while (....), is used to go through each and every rows in
the Scores table.
For each card the A is assigned to value 1 when the condition, if (CheckSomething(X,
M, P, C)), is satisfied. Since A holds the number of students which satisfies the conditions
specified in the question, A needs to be incremented. This is one of the mistake in the code.
Computational thinking Mock Set - II Page 16 of 20
The purpose of the Procedure CheckSomething is to return true when the conditions in
the questions are satisfied. The first condition, if (Y.Gender == “F”), checks whether the
student is Female. The nested condition, if (Y.Mathematics > C1 and Y.Physics > C2 and
Y.Chemistry > C3), checks whether the marks of all the subjects are greater than the average
marks of each subject. This is another mistake in the code. We need to check at least whether
marks of one of the subject is greater than the average mark. So the correct condition is if
(Y.Mathematics > C1 or Y.Physics > C2 or Y.Chemistry > C3).
Computational thinking Mock Set - II Page 17 of 20
12. The following pseudocode is executed using the “Words” table. At the end of the execution,
A captures the number of sentences with at least two nouns that have at most 2 vowels. The
pseudocode may have mistakes. Identify all such mistakes (if any). It is a Multiple Select
Question (MSQ). [5 Marks]
1 A = 0, C = 0
2 while (Table 1 has more cards) {
3 Read the first row X from Table 1
4 if (X.PartOfSpeech == “Noun” and CountVowels(X) ≤ 2) {
5 C=C+1
6 }
7 if (X.Word ends with a full stop) {
8 if (C ≥ 2) {
9 A=A+1
10 C=0
11 }
12 }
13 Move X to Table 2
14 }
Solution: Here the A which captures the number of sentences with at least two nouns that
have at most 2 vowels. An iteration, while (....), is used to go through each and every words
in the paragraph.
There are two if conditions inside the while loop. The first if, if (X.PartOfSpeech == “Noun”
and CountVowels(X) ≤ 2), checks whether the part of speech is Noun and return value of the
Computational thinking Mock Set - II Page 18 of 20
procedure, Procedure CountVowels, is at most 2. The next if, if (ith letter of Y.Word is a
vowel), is executed at the end of a sentence. At the end of the sentence A is incremented if
the condition, if (C ≥ 2) is satisfied. Also C is initialised to 0 inside the if (C ≥ 2) condition.
This is a mistake in the pseudocode. C should be initialised to 0 after the end of the sentence
irrespective of the condition, if (C ≥ 2). Therefore C is updated in wrong place. Instead
C needs to be updated between the line 11 and line 12.
The procedure, Procedure CountVowels, returns the number of vowels in a word. Here i is
used to iterate along the letters of words. But here i is only incremented when the condition,
if (ith letter of Y.Word is a vowel), is satisfied. This is another mistake in the pseudocode.
Here, i should be incremented irrespective of the condition, if (ith letter of Y.Word is a vowel).
The correct place to increment i is between line 22 and line 23.
Computational thinking Mock Set - II Page 19 of 20
13. The following pseudocode is executed using the “Scores” table. At the end of the execution,
C captures the number of pairs of students who have the same date of birth, or the same
City/Town but different gender. 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.DateOfBirth == Y.DateOfBirth) {
C=C+1
}
if (X.Gender 6= Y.Gender and X.CityTown == Y.CityTown) {
C=C+1
}
b.
if (X.DateOfBirth == Y.DateOfBirth) {
C=C+1
}
else {
if (X.Gender 6= Y.Gender and X.CityTown == Y.CityTown) {
C=C+1
}
}
c.
if (X.DateOfBirth == Y.DateOfBirth) {
if (X.Gender 6= Y.Gender and X.CityTown == Y.CityTown) {
C=C+1
}
}
d.
if ((X.DateOfBirth == Y.DateOfBirth)
or (X.Gender 6= Y.Gender and X.CityTown == Y.CityTown)) {
C=C+1
}
Computational thinking Mock Set - II Page 20 of 20
Solution: Here C captures the number of pairs of students who have the same date of birth,
or the same City/Town but different gender.
Here the conditions needs to be satisfied are “Same date of birth” OR “Different gender and
Same City/Town”. There are two code blocks in the options which can be used to complete
the code, They are
if (X.DateOfBirth == Y.DateOfBirth) {
C=C+1
}
else {
if (X.Gender 6= Y.Gender and X.CityTown == Y.CityTown) {
C=C+1
}
}
and
if ((X.DateOfBirth == Y.DateOfBirth)
or (X.Gender 6= Y.Gender and X.CityTown == Y.CityTown)) {
C=C+1
}