Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Week-2, Graded (Sept 2022)

Week-2, Graded (Sept 2022)


Question 1 [2 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question 2 [2 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question-3 [3 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question-4 [2 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question 5 [2 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question-6 [3 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question-7 [2 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question-8 [3 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question-9 [2 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution
Question-10 [3 Marks]
Statement
Options
(a)
(b)
(c)
(d)
Answer
Solution

Question 1 [2 Marks]
Statement
The following procedure finds the highest Physics marks among females and the lowest Physics
marks among males from the “Scores” dataset. The programmer may have made mistakes in one
or more steps. Identify all such steps (if any). It is a Multiple Select Question (MSQ).
Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Initialize variable Fmax to 0 and variable Mmin to 101

Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. If Gender is 'M' and Mmin > Physics marks then store Physics marks in Mmin

Step 6. If Gender is 'F' and Fmax < Physics marks then store Physics marks in Fmax

Step 7. Move the current card to another pile called Pile 2 and repeat from step 3

Options
(a)

Step 2: Incorrect initialization of variable Fmax

(b)

Step 5: Incorrect condition for comparing the value of variable Mmin

(c)

Step 6: Storing Physics marks in Fmax is incorrect

(d)

No mistake

Answer
(d)

Solution
In this problem we have to find the mistakes in the procedure which finds the highest Physics
marks among females and the lowest Physics marks among males from the “Scores” dataset. We
will go through the procedure step by step.

Step 2: In this step variables Fmax and Mmin are initialized to 0 and 101 respectively which seem
to be correct. As we know that the variable Fmax, which is defined for finding the highest Physics
marks among ”females”, should be initialized to 0 and variable Mmin, which is defined for finding
the lowest Physics marks among ”males”, should be initialized to 101.

• Step 3 and 4: These steps do not have any mistakes.

• Step 5: In this step Gender and Physics marks are checked together. If the Gender is ”M” and
value stored in Mmin is higher than Physics marks then Physics Marks will be stored in Mmin.
The statement seems to be correct because whenever a new card having lower Physics marks
than the value in the variable Mmin is seen the value of Mmin is being replaced by Physics
marks.

• Step 6: In this step also Gender and Physics marks are checked together. If the Gender is ”F” and
Physics marks are higher than Fmax then Physics Marks will be stored in Fmax. The statement
seems to be correct because whenever a new card having higher Physics marks than the value in
the variable Fmax is seen the value of Fmax is being replaced by Physics marks.

• Step 7: In this step we are moving the read card to another pile 2 and repeating from step 3
which absolutely fine.
• So there is no mistake in the given procedure.
Question 2 [2 Marks]
Statement
At the end of the execution of the given procedure on the “Scores” dataset, what will A and B
represent?

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Maintain two variables A, B and initialize them to 101

Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. If A < Chemistry marks, then store Chemistry marks in A

Step 6. If Mathematics marks < B, then store Mathematics marks in B

Step 7. Move the current card to another pile called Pile 2 and repeat from step 3

Options
(a)

A = Lowest marks of Chemistry, B = Lowest marks of Mathematics

(b)

A = Highest marks of Chemistry, B = Lowest marks of Mathematics

(c)

A = lowest marks of Chemistry, B = 101

(d)

A = 101, B = Lowest marks of Mathematics

Answer
(d)

Solution
Step 5: Whenever the Chemistry marks of the picked card is greater than A, then A is being
updated with the Chemistry Marks. Initially A is initialized with 101 in step 2. It means A will never
be upadted with any Chemistry marks beacuse Chemistry marks can not be more than 101.
Hence value of A will be 101.

For example, If we pick the first card with SeqNo 0, Bhuvanesh has scored 78 in Chemistry . As 78
is not greater than 101 (the current value of A), A will not be updated and value of A will still be
101. For the next card Chemistry mark is 91. Again 91 is not greater than 101 (the current value of
A), A will not be updated and value of A will still be 101. Remember that there will not be any card
which has Chemistry Marks more than 101.

Step 6: Whenever the Mathematics marks of the picked card is lower than B, then B is being
updated with the Mathematics Marks. Initially B is initialized with 101 in step 2. Therefore, B
stores the lowest marks in Mathematics.
For example, If we pick the first card with SeqNo 0, Bhuvanesh has scored 68 in Mathematics. As
68 is lower than 101 (the current value of B), B will be updated to 68. For the next card,
Mathematics mark is 62. As 62 is again lower than 68 therefore, B gets updated to 62. The
Mathematics mark of third card is 57 which is again lower than 62 therefore, B will get updated
and value of B will be 57 (Lowest mark in Mathematics till now).
Question-3 [3 Marks]
Statement
At the end of the execution of the given procedure on the “Words” dataset, what will A and B
represent?

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Maintain two variables A, B and initialize them to 0

Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. If Letter count > A, then store A in B and Letter count in A

Step 6. If Letter Count > B and Letter count < A, then store Letter count in B

Step 7. Move the current card to another pile called Pile 2 and repeat from step 3

Options
(a)

A = Largest word length and B = Smallest word length

(b)

A = Smallest word length and B = Largest word length

(c)

A = Smallest word length and B = Second smallest word length

(d)

A = Largest word length and B = Second largest word length

Answer
(d)

Solution
Let us take the first 10 words from dataset. From step 5 and 6 it is clear that we only need the
letter count of these words (cards).

The letter counts of first ten words are 2, 3, 6, 7, 11, 3, 9, 2, 4, 3, and 4.

First card:

Step 5: If we pick the first card with SeqNo 0, the word "It" has letter count 2. As 2 is more than 0
(the current value of A), B will store the value of A therefore, the value of B will be 0 and A will be
updated with the letter count which is 2. Therefore, the current value of A and B are 2 and 0
respectively.

Step 6: Letter count of the word is not greater than A, step 6 will not be executed.
Second Card:

Step 5: The letter count is 3 which is greater than 2 therefore, B will store the value of A and A
will be updated with the letter count which is 3. Therefore, the current value of A and B are 3 and
2 respectively.

Step 6: Letter count of the word is not greater than A, step 6 will not be executed.

Therefore, the current value of A and B are 3 and 2 respectively.

Third card:

Step 5: The letter count is 6 which is greater than 3 therefore, B will store the value of A and A
will be updated with the letter count which is 6. Therefore, the current value of A and B are 6 and
3 respectively.

Step 6: Letter count of the word is not greater than A, step 6 will not be executed.

Fourth card:

Step 5: The letter count is 7 which is greater than 6 therefore, B will store the value of A and A
will be updated with the letter count which is 7. Therefore, the current value of A and B are 7 and
6 respectively.

Step 6: Letter count of the word is not greater than A, step 6 will not be executed.

Fifth card:

Step 5: The letter count is 11 which is greater than 7 therefore, B will store the value of A and A
will be updated with the letter count which is 11. Therefore, the current value of A and B are 11
and 7 respectively.

Step 6: Letter count of the word is not greater than A, step 6 will not be executed.

Sixth card:

Step 5: The letter count is 3 which is not greater than 11. Therefore, there will not any updates of
A and B. Hence, the current value of A and B are still 11 and 7 respectively.

Step 6: Letter count of the word is not greater than B, step 6 will not be executed.

Seventh card:

Step 5: The letter count is 9 which is not greater than 11. Therefore, there will not any updates of
A and B. Hence, the current value of A and B are still 11 and 7 respectively.

Step 6: Letter count of the word is greater than B, and Letter count is less than A, therefore B will
be updated with letter cout, 9 (till now second largest letter count). Hence, the current value of A
and B are 11 and 9 respectively.

Therefore,

Step 5: Whenever the letter count of the picked card is greater than A, then A is being updated
with the letter count. Therefore, A stores the largest letter count of a word. At the same step B
gets update with the second largest value stored by A.

Step 6: When the letter count is between A and B then only B is updated. Which clears that B
stores the second largest word length.
 

Question-4 [2 Marks]
Statement
At the end of the execution of the given procedure on the “Words” dataset, what will A represent?

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Maintain two variables A, B and initialize them to 10000 and 0 respectively

Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. Add Letter count to variable B

Step 6. If Word does not end with a full stop then execute step 9

Step 7. If Word ends with a full stop and B < A then store B in A

Step 8. Re-initialize the variable B to 0

Step 9. Move the current card to another pile called Pile 2 and repeat from step 3

Options
(a)

Length of the shortest sentence based on the number of words

(b)

Length of the longest sentence based on the number of words

(c)

Length of the longest sentence based on the number of letters

(d)

Length of the shortest sentence based on the number of letters

Answer
(d)

Solution
Step 5: B stores the sum of the letter counts of the words but how many words?

Step 6: It says if the word does not end with full stop then go to step 9 which is nothing but
repeating the iteration. It means when a word ends with a full stop, then step 7 and 8 will be
executed. From step 8 it is clear that whenever the word ends with a full stop then B is being
reinitialized to 0. This means B stores the letter counts in a sentence.

Step 7: For every sentence, A is compare with B. The value of A gets updated with the value of B
whenever B is lower than A.
As A is initialized with 10000, and B stores the number of letters in a sentence, A stores the lowest
letter in a sentence i.e., length of shortest sentence in terms of number of letters.
Question 5 [2 Marks]
Statement
What will the value of (A–B) represent after the execution of the following procedure using the
“Shopping Bills” dataset?

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Initialize variables A to 0 and B to 1000

Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. If the bill contains an item “Eggs” and the Price of “Eggs” > A then store Price of “Eggs” in A

Step 6. If the bill contains an item “Eggs” and the Price of “Eggs” < B then store Price of “Eggs” in B

Step 7. Move the current card to another pile called Pile 2 and repeat from step 3

Options
(a)

Difference between maxium and minimum price of an item across all shops

(b)

Difference between maxium and minimum price of an item "Eggs" in a shop

(c)

Difference between maxium and minimum price of an item "Eggs" across all shops

(d)

It will be 0.

Answer
(c)

Solution
Here in step 2, variables A and B are initialized to 0 and 1000 respectively.

As per the steps 5 and 6, we are comparing the Price of ”Eggs” of current card with variables A and
B only if the item ”Eggs” is there in it. Also, we are finding the highest and lowest unit price of the
item ”Eggs” and storing these values in variables A and B respectively.

This is the list of all such shopping bills which contain ”Eggs” item.
Card No Price

4 45

11 45

20 45

30 9

Here, values of A and B will 45 and 9 after execution of given procedure. And the value of (A-B)
will be 36. Hence (A-B) will represent the difference between maxium and minimum price of an
item "Eggs" across all shops.
Question-6 [3 Marks]
Statement
What will be the value of X after execution of the following procedure using the “Scores” dataset?

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Initialize variables A, B, C, D and Y to 0

Step 3. Maintain a variable X and initialize it to “None”

Step 4. If Pile 1 is empty then stop the iteration

Step 5. Read the top card in Pile 1

Step 6. If the Town/City is “Chennai” then add one to A. If A > Y then store A in Y and “Chennai” in
X

Step 7. If the Town/City is “Bengaluru” then add one to B. If B > Y then store B in Y and
“Bengaluru” in X

Step 8. If the Town/City is “Madurai” then add one to C. If C > Y then store C in Y and “Madurai” in
X

Step 9. If the Town/City is “Vellore” then add one to D. If D > Y then store D in Y and “Vellore” in X

Step 10. Move the current card to another pile called Pile 2 and repeat from step 4

Options
(a)

Chennai

(b)

Bengaluru

(c)

Madurai

(d)

Vellore

Answer
(a)

Solution
Here in step 2, variables A, B, C, D and Y are initialized to 0 whereas in step 3, variable X is
initialized to ”None” which indicates that this variable is used to store value of string datatype. If
we observe steps 6 to 9 then we can notice that the computation in these steps is identical except
it is for different city/town.

Variables A, B, C and D store the number of cards from Chennai, Bengaluru, Madurai and Vellore
respectively. Variable Y stores maximum among A, B, C and D. These steps also store the name of
the city/town which corresponds to the maximum in the variable X.

Here is the full list of cards which belong to the respective cities.
City/Town Card No. Total no. of cards

Chennai 2, 3, 5, 10, 12, 17, 25, 26 8

Bengaluru 8, 9, 11, 21, 23 5

Madurai 4, 13, 24, 27, 28 5

Vellore 7, 20, 29 3

From the table it is clear that there are more number of cards which belong to Chennai than other
cities. Hence, the correct answer of this question is Chennai.
Question-7 [2 Marks]
Statement
Let us define the most popular shop to be the one that generates the maximum number of bills.
The given procedure finds the number of bills of the most popular shop in the “Shopping Bills”
dataset. Fill in the blanks from the given choices and complete the procedure.

Step 1. Arrange all cards in a single pile called Pile 1

Step 2. Initialize variables SVcount, BBcount, SGcount and max to 0

Step 3. If Pile 1 is empty then stop the iteration

Step 4. Read the top card in Pile 1

Step 5. ————————————

Step 6. ————————————

Step 7. ————————————

Step 8. Move the current card to another pile called Pile 2 and repeat from step 3

Options
(a)

Step 5. If the Shop name is “SV Stores” then add one to SVcount. And if SVcount > max then
store max in SVcount.

Step 6 : If the Shop name is “Big Bazaar” then add one to BBcount. And if BBcount > max then
store max in BBcount.

Step 7 : If the Shop name is “Sun General” then add one to SGcount. And if SGcount > max then
store max in SGcount

(b)

Step 5. If the Shop name is “SV Stores” then add one to SVcount. And if SVcount < max then
store max in SVcount.

Step 6 : If the Shop name is “Big Bazaar” then add one to BBcount. And if BBcount < max then
store max in BBcount.

Step 7 : If the Shop name is “Sun General” then add one to SGcount. And if SGcount < max then
store max in SGcount

(c)

Step 5. If the Shop name is “SV Stores” then add one to SVcount. And if SVcount > max then
store SVcount in max.

Step 6 : If the Shop name is “Big Bazaar” then add one to BBcount. And if BBcount > max then
store BBcount in max.

Step 7 : If the Shop name is “Sun General” then add one to SGcount. And if SGcount > max then
store SGcount in max.

(d)

Step 5. If the Shop name is “SV Stores” then add one to SVcount. And if SVcount < max then
store SVcount in max.

Step 6 : If the Shop name is “Big Bazaar” then add one to BBcount. And if BBcount < max then
store BBcount in max.

Step 7 : If the Shop name is “Sun General” then add one to SGcount. And if SGcount < max then
store SGcount in max.

Answer
(c)

Solution
In this question we are finding the maximum among total bills generated by each shop from
shopping bills dataset. Missing steps 5, 6 and 7 are supposed to find maximum number of bills
generated among all shops. By observing the given options, we can identify that the step 5 is
counting the total number of bills generated at SV Stores. Also, it is comparing the total number of
bills generated at SV Stores so far with variable max and if it is greater than max then the same is
stored in variable max. Similar counting and comparison is happening for Big Bazaar and Sun
General in steps 6 and 7 respectively.

Hence the correct answer of this question is,

Step 5. If the Shop name is “SV Stores” then add one to SVcount. And if SVcount > max then
store SVcount in max.

Step 6 : If the Shop name is “Big Bazaar” then add one to BBcount. And if BBcount > max then
store BBcount in max.

Step 7 : If the Shop name is “Sun General” then add one to SGcount. And if SGcount > max then
store SGcount in max.
Question-8 [3 Marks]
Statement
The following pseudocode is executed using the “Scores” dataset. What will count represent at
the end of the execution of pseudocode?

1 count = 0
2 while(Pile 1 has more cards){
3 Read the top card X from Pile 1
4    C = 0
5    if(X.Mathematics < 76){
6   C = C + 1
7   }
8    if(X.Physics < 76){
9   C = C + 1
10   }
11    if(X.Chemistry < 76){
12   C = C + 1
13   }
14    if(C == 0){
15   count = count + 1
16   }
17    Move X to Pile 2
18 }

Options
(a)

Number of students who scored less than 75 marks in all three subjects

(b)

Number of students who scored more than 75 marks in all three subjects

(c)

Number of students who scored more than 76 marks in all three subjects

(d)

Number of students who scored less than 76 marks in all three subjects

Answer
(b)

Solution
The question is about finding what count represents? From the condition given in the line 14 it is
clear that count totally depends on the value of C. Whenever C is 0, count is being incremented.
So it is clear that count represents the number of times C remains 0 in an iteration.
Now let us focus on when C remains 0? C is re-initialized to 0 in line 4. In the line 5 and 6, C will be
increased by 1 whenever the Mathematics mark is less than 76. It means C will still be 0 if
Mathematics marks are greater than 75. From line 8 and 9, it is clear that C will not be increased
whenever Physics marks are less than 76. That means C will still be 0 if Physics marks are greater
than 75. Similarly from line 11 and 12, it is also clear that C will be 0 whenever students scores are
more than 75 in Chemistry. So if none of the if-conditions become true, the value of C will be 0. It
tells that student has scored more than 75 in all thres subjects. And if the any one of the if-
conditions become true C will not be 0. It tells that student has scored less than 76 in atleast one
subject.

Therefore, count is the number of students who have scored more than 75 in all the subjects.
Question-9 [2 Marks]
Statement
The following pseudocode is executed using the “Words” dataset. At the end of the execution, A
captures the maximum letter count of a verb. Choose the correct code fragment(s) to complete
the pseudocode. It is Multiple Select Question (MSQ).

1 A = 0
2 while(Pile 1 has more cards){
3    Read the Top card X in Pile 1
4    *********************
5    * Fill the code *
6    *********************
7    Move X to Pile 2
8 }

Options
(a)

1 if(X.PartOfSpeech == “Verb” and X.LetterCount > A){


2 A = X.LetterCount
3 }

(b)

1 if(X.PartOfSpeech == “Verb” and X.LetterCount < A){


2 A = X.LetterCount
3 }

(c)

1 if(X.PartOfSpeech == “Verb”){
2    if(X.LetterCount > A){
3        A = X.LetterCount
4   }
5 }

(d)

1 if(X.PartOfSpeech == “Verb”){
2    if(X.LetterCount < A){
3        A = X.LetterCount
4   }
5 }
Answer
(a), (c)

Solution
From the question, it is clear that A stores the maximum number of letters in a verb. At the start
of pseudocode, A is initialized to 0. To find the maximum letter count of a verb, we know that A
should be compared to the number of letters in the word. Whenever the part of speech of a word
is verb and the number of letters in the word is greater than A, A should be updated with the
letter count. Therefore, there are two conditions to be followed. First, the peaked word should be
a verb and second, the letter count of this verb should be greater than A (i.e., is the current value
of A). These two conditions are found in options in (a) and (c).
Question-10 [3 Marks]
Statement
The given pseudocode is executed using the “Words” dataset. At the end of execution, count
finds the number of sentences with maximum number of words. Choose the correct option to
complete the pseudocode.

1 count = 0, A = 0, B = 0
2 while(Pile 1 has more cards){
3 Read the top card X from Pile 1
4 A = A + 1
5    if(X.Word ends with full stop){
6        if(A == B){
7   count = count + 1
8   }
9   if(A > B){
10            B = A
11   *** Statement 1 ***
12   }
13   *** Statement 2 ***
14   }
15    Move X to Pile 2
16 }

Options
(a)

Statement 1: count = 1, Statement 2: A = A + 1

(b)

Statement 1: count = 1, Statement 2: A = 0

(c)

Statement 1: count = 0, Statement 2: A = 1

(d)

Statement 1: count = 1, Statement 2: A = 1

Answer
(b)

Solution
In the question, count is supposed to find the number of sentences with maximum number of
words in it. Therefore, count should be initialized to 0. Along with count, we need two more other
variables, one to keep track of the number of words in the current sentence. This is being done by
the variable A. Second variable to keep track of the number of maximum words in a sentence
seen till now. From the pseudocode it is clear that this job is being done by the variable B.
Remember, there could be more sentences having the maximum number of words. Therefore,
whenever we find the next maximum, B should be updated with the maximum number of words
in a sentence. Next, if we find the same number of words in the different sentence (i.e., equal to
the current maximum) count should be incremented. In Line 11, B is being updated whenever
the next maximum is being found. Simultaneously, count should also be initialized to one.
Therefore,

Statement 1: count = 1

For counting number of words in next new sentence, A should be re-initialized to 0. Therefore,

Statement 2: A = 0

You might also like