You are on page 1of 9

1. The following pseudocode is executed using the “Scores” dataset.

It computes the number of


students in each grade, where grades are assigned based on total marks. Choose the correct
code block to complete the pseudocode.
Min = 100, Max = 0
while (Table 1 has more rows) {
Read the first row X in Table 1
if (X.Total > Max) {
Max = X.Total
}
if (X.Total < Min) {
Min = X.Total
}
Move X to Table 2
}
Interval = (Max - Min) / 3
Mid2 = Max - Interval
Mid1 = Mid2 - Interval
countA = 0, countB = 0, countC= 0
while (Table 2 has more rows) {
Read the first row X in Table 2
if (X.Total ≤ Mid1) {
countC = countC + 1
}
*********************
* Fill the code *
*********************
if (X.Total > Mid2) {
countA= countA + 1
}
}

a.
if (X.Total > Mid1) {
countB = countB + 1
}
b.
if (X.Total ≤ Mid2 and X.Total ≥ Mid1) {
countB = countB + 1
}
c.
if (X.Total > Mid1 and X.Total ≤ Mid2) {
countB = countB + 1
}
d.
if (X.Total ≥ Mid1 and X.Total < Mid2) {
countB = countB + 1
}
2. The following pseudocode is executed using the “Words” dataset. Let A and B be the variables
that hold the values of letter counts of shortest and longest word, respectively. What will count
represent at the end of execution?

count = 0
while (Table 1 has more cards) {
Read the first row X from Table 1
Move X to Table T2
if (X.Word ends with a full stop) {
count = count + DoSomething (Table T2, A, B)
}
}

Procedure DoSomething (Table 2, X, Y)


C = 0, D = 0
while (Table 2 has more rows) {
Read the first row Z from Table 2
if (Z.LetterCount ≤ X) {
C=1
}
if (Z.LetterCount ≥ Y) {
D=1
}
Move Z to Table 3
}
if (C + D == 1) {
return (1)
}
else {
return (0)
}
End DoSomething

a. Number of sentences having exactly one shortest word or exactly one longest word
b. Number of sentences having exactly one shortest word and exactly one longest word
c. Number of sentences having at least one shortest word or at least one longest word
d. Number of sentences having at least one shortest word or at least one longest word but
not both
e. None of the above
3. The following pseudocode is executed using the “Shopping bills” dataset. Assume that the
variable Avg holds the value of the average total bill amount. The procedure countSomething
counts the number of bills that are not from BigBazaar and with total bill amount greater than
Avg. Choose the correct code fragment to complete the procedure. It is a Multiple Select
Question (MSQ).

Procedure countSomething ( )
count = 0
while (Pile 1 has more cards) {
Read the top card X from Pile 1
*********************
* Fill the code *
*********************
Move card X to Pile 2
}
return (count)
End countSomething

a.
if (X.ShopName == “BigBazaar”) {
if (X.TotalBillAmount > Avg) {
count = count + 1
}
}
b.
if (X.ShopName 6= “BigBazaar”) {
if (X.TotalBillAmount < Avg) {
count = count + 1
}
}
c.
if (X.ShopName 6= “BigBazaar”) {
if (X.TotalBillAmount > Avg) {
count = count + 1
}
}
d.
if (X.ShopName 6= “BigBazaar” and X.TotalBillAmount > Avg) {
count = count + 1
}
}
e. None of the above
4. The following pseudocode is executed using the “Words” dataset. What will A and B represent
at the end of execution?

sum = 0, count = 0
while (Pile 1 has more cards) {
Read the top card X from Pile 1
sum = sum + X.LetterCount
count = count + 1
}
Move card X to Pile 2
}
MLC = sum/count
A = 0, B = 0
while (Pile 2 has more cards) {
Read the top card X from Pile 2
if (X.PartsOfSpeech == “Noun” and X.LetterCount ≤ MLC) {
A=A+1
}
if (X.PartsOfSpeech == “Verb” and X.LetterCount ≥ MLC) {
B=B+1
}
Move card X to Pile 1
}

a. A = Number of nouns with letter count less than the average letter count
B = Number of verbs with letter count greater than the average letter count
b. A = Number of words with letter count less than the average letter count
B = Number of words with letter count greater than the average letter count
c. A = Number of nouns having letter count less than or equal to average letter count
B = Number of verbs having letter count greater than or equal to average letter count
d. A = Number of nouns having letter count greater than or equal to average letter count
B = Number of verbs having letter count greater than or equal to average letter count
5. The following pseudocode is executed using the “Scores” dataset. What will count represent
at the end of the execution? It is a Multiple Select Question (MSQ).

count = 0
while (Pile 1 has more cards) {
Read the top card X from Pile 1
count = count + doSomething(X)
Move card X to Pile 2
}
Procedure doSomething (X)
if (X.Mathematics < X.Physics or X.CityTown == “Chennai”) {
return (1)
}
return (0)
End doSomething

a. Number of Chennai students whose Mathematics marks are less than Physics marks
b. Number of Chennai students + Number of students whose Mathematics marks are less
than Physics marks.
c. Number of Chennai students whose Mathematics marks are greater than or equal to
Physics marks + Number of students whose Mathematics marks are less than Physics
marks
d. Number of Chennai students + Number of students not from Chennai whose Mathematics
marks are less than Physics marks
e. None of the above
6. The following pseudocode is executed using the “Words” dataset. At the end of execution of
the pseudocode, countB captures the number of verbs whose letter count is strictly greater
than the average letter count of verbs. But the pseudocode may have mistakes in one or more
lines. Identify all such lines (if any). It is a Multiple Select Question (MSQ).

1 sum = 0, count = 0
2 while (Pile 1 has more cards) {
3 Read the top card X in Pile 1
4 sum, count = addIfVerb(X)
5 Move card X to Pile 2
6 }
7 Avg = sum / count
8 countB = 0
9 while (Pile 2 has more cards) {
10 Read the top card X in Pile 2
11 if (X.LetterCount ≥ Avg and X.PartOfSpeech == “Verb”) {
12 countB = countB + 1
13 }
14 Move card X to Pile 1
15 }
16 Procedure addIfVerb (Y, sumV, countV)
17 if (Y.PartOfSpeech == “Verb”) {
18 sumV= sumV + Y.LetterCount
19 countV = 1
20 }
21 return ([sumV, countV])
22 End addIfVerb

a. Error in Line 4
b. Error in Line 7
c. Error in Line 11
d. Error at Line 12
e. Error in Line 17
f. Error at Line 18
g. Error at Line 19
h. Error in Line 21
i. No error in the code
7. The following pseudocode is executed using the “Scores” dataset. What will the value of count
represent at the end of execution?

A = 0, B = 0, C = 0, count = 0
while (Pile 1 has more cards) {
Read the top card X from Pile 1
A, B, C = doSomething(X, A, B, C)
Move X to Pile 2
}
while (Pile 2 has more cards) {
Read the top card Y from Pile 2
if (Y.Mathematics == A and Y.Physics == B and Y.Chemistry == C) {
count = count + 1
}
Move Y to Pile 1
}
Procedure doSomething(Y, A1, B1, C1) {
if (A1 < Y.Mathematics) {
A1 = Y.Mathematics
}
if (B1 < Y.Physics) {
B1 = Y.Physics
}
if (C1 < Y.Chemistry) {
C1 = Y.Chemistry
}
return ([A1, B1, C1])
End doSomething

a. Number of students who scored the lowest marks in any one of three subjects.
b. Number of students who scored the lowest marks in all three subjects.
c. Number of students who scored the highest marks in all three subjects.
d. Number of students who scored the highest marks in any one of three subjects.
8. The following pseudocode is executed using the “Words” dataset. What will A and B represent
at the end of execution?

Procedure countSomething ( )
A = 0, B = 0
while (Pile 1 has more cards) {
Read the top card X from Pile 1
if (X.PartOfSpeech 6= “Noun”) {
if (X.LetterCount 6= 6) {
A=A+1
}
}
else {
if (X.LetterCount == 6) {
B=B+1
}
}
Move card X to Pile 2
}
return ([A, B])
End countSomething

a. A = Number of nouns with letter count not equal to 6


B = Number of words with letter count equal to 6
b. A = Number of words other than nouns with letter count equal to 6
B = Number of words with letter count equal to 6
c. A = Number of words other than nouns with letter count not equal to 6
B = Number of nouns with letter count equal to 6
d. A = Number of words other than nouns with letter count not equal to 6
B = Number of words with letter count equal to 6
9. The following pseudocode is executed using the “Scores” dataset. When will Flag be set to
True?

A = 0, B = 0, Flag = False
while (Pile 1 has more cards) {
Read the top card X from Pile 1
if (X.Gender == ‘M’) {
if (X.CityTown == “Madurai”) {
A=A+1
}
}
else {
if (X.CityTown == “Bangalore”) {
B=B+1
}
}
Move card X to Pile 2
}
if (A > B) {
Flag = True
}

a. If number of male students from Madurai is greater than the number of students from
Bangalore.
b. If number of male students from Madurai is greater than the number of female students
from Bangalore.
c. If number of male students from Madurai is less than the number of students from
Bangalore.
d. If the number of male students is greater than that of number of female students

You might also like