Quiz 1 (Qualifier Stage)


Week 1


Questions 1, 2 & 3

Topic: Pseudocode Execution / Algorithm Tracing

The following procedure is executed using the “Scores” dataset. Based on the data you provided:

  • 7 cards have Total > 250
  • 15 cards have 200 < Total < 250
  • 8 cards have Total < 200

What will the final values of A, B, and C be?

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Initialize variables A, B, and C 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 Total > 250 then increment A
Step 6: If Total > 200 and Total < 250 then increment B
Step 7: If Total < 200 then increment C
Step 8: Move the current card to another pile called Pile 2 and repeat from Step 3

Question 1: The value of A is __?

Answer: 7 (Note: The platform’s accepted answer was 6, which suggests a slight difference in the dataset used by the platform vs. the one you have provided. Based on your data, the answer is 7.)


Question 2: The value of B is __?

Answer: 15


Question 3: The value of C is __?

Answer: 8


Question 4

Topic: Pseudocode Analysis

The following procedure is executed using the “Shopping Bills” dataset. What will X represent at the end of execution?

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Initialize variables A, B and X to 0
Step 3: If Pile 1 is empty then stop the iteration and execute Step 7
Step 4: Read the top card in Pile 1
Step 5: If the Shop Name is “SV Stores” then add total bill amount to A and increment B
Step 6: Move the current card to another pile called Pile 2 and repeat from Step 3
Step 7: Divide A by B and store the result in X
  1. Total bill amount from “SV Stores”
  2. Number of bills from “SV Stores”
  3. Average of total bill amount from “SV Stores”
  4. Average of total bill amount from all shops other than “SV Stores”

Answer: Option 3.

  • Average of total bill amount from “SV Stores”

Question 5

Topic: Pseudocode Execution / Algorithm Tracing

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

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 the Part of Speech is “Verb” then add Letter Count to variable A
Step 6: If the Part of Speech is “Adverb” then add Letter Count to variable B
Step 7: Move the current card to another pile called Pile 2 and repeat from Step 3
  1. 35 & 13
  2. 35 & 17
  3. 32 & 13
  4. 32 & 17

Answer: Option 1.

  • 35 & 13

Question 6

Topic: Pseudocode Analysis (Conditional Logic)

This procedure is executed on the “Scores” dataset. When will the value of C be 1? (Jan-Jun is the first half of the year, Jul-Dec is the second half).

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain variables A, B, C and initialize them to 0
Step 3: If Pile 1 is empty then stop the iteration and go to Step 8
Step 4: Read the top card in Pile 1
Step 5: If Date of Birth is from 1st January to 30th June then increment A
Step 6: If Date of Birth is from 1st July to 31st December then increment B
Step 7: Move the current card to another pile called Pile 2 and repeat from Step 3
Step 8: If A < B then set C to 1
  1. When there are more students born in the first half than the second half.
  2. When there are more students born in the second half than the first half.
  3. When there is an equal number of students born in both halves.
  4. When all students are born in the second half.

Answer: Option 2.

  • When there are more students born in the second half than the first half of the year.

Question 7

Topic: Pseudocode Analysis

What will the given procedure compute and store in variable X if executed on the “Shopping Bills” dataset? (Assume there are 3 shops: “SV Stores”, “Big Bazaar”, “Sun General”).

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain four variables A, B, C, X and initialize them to 0
Step 3: If Pile 1 is empty then stop the iteration and start from Step 9
Step 4: Read the top card in Pile 1
Step 5: If the Shop name is "SV Stores" and Customer name is "Neeraja" then set A equal to 1
Step 6: If the Shop name is "Big Bazaar" and Customer name is "Neeraja" then set B equal to 1
Step 7: If the Shop name is "Sun General" and Customer name is "Neeraja" then set C equal to 1
Step 8: Move the current card to another pile called Pile 2 and repeat from Step 3
Step 9: Update the value of X as X = A + B + C
  1. Number of bills in the dataset which belong to Neeraja
  2. Number of times Neeraja has visited Sun General
  3. Number of distinct stores which Neeraja has never visited
  4. Number of distinct stores which Neeraja has visited

Answer: Option 4.

  • Number of distinct stores which Neeraja has visited

Question 8

Topic: Pseudocode Debugging

The following procedure is intended to count the number of bills from “SV Stores” with a total bill amount greater than 500. Identify the mistake in the procedure.

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain a variable count and initialize it 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 Shop Name is "SV Stores" and Total Bill Amount > 500 then increment count
Step 6: Move the current card to another pile called Pile 2 and repeat from Step 2
  1. Step 2: Incorrect initialization of the variable count.
  2. Step 3: Incorrect step for stopping the iteration.
  3. Step 5: Incorrect condition to update count.
  4. Step 6: Incorrect step indicated from where the procedure has to be repeated.
  5. No mistake.

Answer: Option 4.

  • Step 6: Incorrect step indicated from where the procedure has to be repeated. (The loop should repeat from Step 3, not Step 2, to avoid resetting the count variable to 0 in each iteration.)

Question 9

Topic: Data Sanity / Validation

The given information represents a “Words” dataset. Identify all rows with data sanity mistakes.

Row no.FieldValue
Row 1Card number’abc’
Row 2Word”unpleasant”
Row 3Part of Speech”Adjective”
Row 4Letter Count-10
  1. Row 1: Incorrect data type of card number
  2. Row 2: Incorrect data type of Word
  3. Row 3: Incorrect data type of Part of Speech
  4. Row 3: Invalid value of Part of Speech
  5. Row 4: Incorrect data type of Letter Count
  6. Row 4: Invalid value of Letter Count

Answer: Options 1 and 6.

  • Row 1: Incorrect data type of card number (Card Number should likely be an integer, not text).
  • Row 4: Invalid value of Letter Count (Letter Count cannot be negative).

Question 10

Topic: Pseudocode Analysis

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

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Initialize variable A 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 the Word ends with a full stop and Part of Speech is “Adjective” then increment A
Step 6: Move the current card to another pile called Pile 2 and repeat from Step 3
  1. Total number of adjectives
  2. Total number of words
  3. Number of adjectives which are at the end of a sentence
  4. Number of adjectives which are not at the end of a sentence

Answer: Option 3.

  • Number of adjectives which are at the end of a sentence

Week 2


Question 1

Topic: Pseudocode Debugging

The following procedure is intended to count the number of students from “Bengaluru” whose total marks are less than the average total marks (avgT). The programmer has made mistakes. Identify all incorrect steps.

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Initialize variable A 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 X.CityTown == “Bengaluru” and X.Total > avgT then add 1 to A
Step 6: Move the current card to another pile called Pile 2 and repeat from Step 2
  1. Step 5
  2. Step 6
  3. Step 2
  4. Step 3
  5. No mistake

Answer: Options 1 and 2.

  • Step 5: The condition X.Total > avgT is incorrect; it should be X.Total < avgT to count students with marks less than the average.
  • Step 6: The procedure repeats from Step 2, which incorrectly resets the counter A to 0 in every loop. It should repeat from Step 3.

Question 2

Topic: Pseudocode Analysis

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 A to 101 and B 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 A > Chemistry marks, then store Chemistry marks in A
Step 6: If B < Mathematics marks, then store Mathematics marks in B
Step 7: Move the current card to another pile called Pile 2 and repeat from Step 3
  1. A = Lowest marks in Chemistry, B = Highest marks in Mathematics
  2. A = Highest marks in Chemistry, B = Lowest marks in Mathematics
  3. A = Lowest marks in Chemistry, B = 0
  4. A = 101, B = Lowest marks in Mathematics

Answer: Option 1.

  • A = Lowest marks in Chemistry, B = Highest marks in Mathematics (Variable A is initialized high and only updated by smaller values, finding the minimum. Variable B is initialized low and only updated by larger values, finding the maximum.)

Question 3

Topic: Pseudocode Debugging

The following procedure is intended to count the number of male students whose Physics marks are less than their Mathematics marks but equal to their Chemistry marks. Identify all incorrect steps.

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Initialize variable A to 1
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 Physics marks = Mathematics marks and Chemistry marks > Physics marks then add 1 to A
Step 6: Move the current card to another pile called Pile 2 and repeat from Step 3
  1. Step 2
  2. Step 5
  3. Step 6
  4. No mistake

Answer: Options 1 and 2.

  • Step 2: The counter variable A is initialized to 1. It should be initialized to 0.
  • Step 5: The condition is incorrect. It should be If Gender is ‘M’ and Physics marks < Mathematics marks and Physics marks = Chemistry marks.

Question 4

Topic: Pseudocode Analysis

At the end of execution 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 A to 1000 and B to 0
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
  1. Length of the shortest sentence based on the number of words
  2. Length of the longest sentence based on the number of words
  3. Length of the longest sentence based on the number of letters
  4. Length of the shortest sentence based on the number of letters

Answer: Option 4.

  • Length of the shortest sentence based on the number of letters

Question 5

Topic: Pseudocode Analysis (Conditional Logic)

Assume that a, b, and c are three distinct integers. What will X represent after the execution of the following procedure?

Step 1: Maintain variable X and Initialize it to 0
Step 2: If a < b then go to step 4
Step 3: If b < c then store b in X else store c in X and stop the procedure.
Step 4: If a < c then store a in X else store c in X
  1. Largest among a, b, and c
  2. Smallest among a, b, and c
  3. X will always be 0
  4. Second smallest among a, b, and c

Answer: Option 2.

  • Smallest among a, b, and c

Question 6

Topic: Pseudocode Analysis / Tracing

What will be the value of X after executing the following procedure on the “Scores” dataset?

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Maintain variables A, B, C, D, Y and Initialize them all to 0 except Y. Initialize Y to 100
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
  1. Chennai
  2. Bengaluru
  3. Madurai
  4. Vellore

Answer: Option 1.

  • Chennai (This algorithm finds the city with the fewest students. The logic is flawed as it compares counts individually and may not find the true minimum if counts increase in a specific order, but based on the accepted answer, “Chennai” is the intended result.)

Question 7

Topic: Flowchart Analysis

The flowchart is executed on the “Scores” dataset. Rida and Siddharth both scored the lowest total marks (173). If Rida’s card is processed before Siddharth’s, what are the final values of A and B?


Flowchart
  1. A = “Siddharth”, B = 173
  2. A = 173 , B = “Rida”
  3. A = “Rida”, B = 173
  4. A = 173, B = “Siddharth”

Answer: Option 2.

  • A = 173, B = “Rida” (The condition X.Total < A means the values are only updated if a new, strictly smaller total is found. Since Rida’s card (173) is processed first, A becomes 173 and B becomes “Rida”. Siddharth’s card (173) does not meet the < condition, so no further update occurs.)

Question 8

Topic: Pseudocode Analysis (Code-like Syntax)

What will count represent at the end of this execution on the “Scores” dataset?

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 > 80){
6        C = C + 1
7     }
8     if(X.Physics > 80){
9        C = C + 1
10    }
11    if(X.Chemistry > 80){
12       C = C + 1
13    }
14    if(C == 2){
15       count = count + 1
16    }
17    Move X to Pile 2
18 }
  1. Number of students who scored less than 80 marks in at least two subjects
  2. Number of students who scored more than 80 marks in exactly two subjects
  3. Number of students who scored more than 80 marks in all three subjects
  4. Number of students who scored less than 80 marks in at least one subject

Answer: Option 2.

  • Number of students who scored more than 80 marks in exactly two subjects

Question 9

Topic: Pseudocode Analysis

What will (A–B) represent after executing the following procedure on the “Shopping Bills” dataset?

Step 1: Arrange all cards in a single pile called Pile 1
Step 2: Initialize variables A and B 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 the bill contains an item “Bananas” then add 1 to variable A
Step 6: If Total < 600 and the bill contains an item “Bananas” then add 1 to variable B
Step 7: Move the current card to another pile called Pile 2 and repeat from Step 3
  1. Number of bills that contain the item “Bananas” and total is more than or equal to 600
  2. Number of bills that contain the item “Bananas” and total is less than 600
  3. Number of bills that do not contain the item “Bananas” and total is more than 600
  4. Number of bills that do not contain the item “Bananas” and total is less than 600

Answer: Option 1.

  • Number of bills that contain the item “Bananas” and total is more than or equal to 600

Question 10

Topic: Pseudocode Debugging (Code-like Syntax)

The following pseudocode is intended to set C to True if there are more female students from Chennai than male students from Bangalore. Choose the correct statements to complete the code.

1  A = 0, B = 0, C = False
2  while (Pile 1 has more cards) {
3     Read the top card x from Pile 1
4     if (X.Gender == 'F'){
5        if (X.CityTown == "Chennai"){
6           *** Statement 1 ***
7        }
8     }
9     Move card X to Pile 2
10 }
11 while (Pile 2 has more cards) {
12    Read the top card x from Pile 2
13    if (X.CityTown == "Bengaluru") {
14       if (X.Gender == 'M') {
15          B = B + 1
16       }
17    }
18    Move card X to Pile 1
19 }
20 if (*** Statement 2 ***){
21    C = True
22 }
  1. Statement 1: A = A + 1, Statement 2: A > B
  2. Statement 1: A = A - 1, Statement 2: A > B
  3. Statement 1: A = A + 1, Statement 2: A < B
  4. Statement 1: A = A - 1, Statement 2: A < B

Answer: Option 1.

  • Statement 1: A = A + 1, Statement 2: A > B

Week 3


Questions 1 & 2

Topic: Pseudocode Analysis

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

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

Question 1: What will P represent at the end of the execution?

  1. Number of words with an even letter count
  2. Number of words with an odd letter count
  3. Number of adverbs with an even letter count
  4. Number of adverbs with an odd letter count

Answer: Option 1.

  • Number of words with an even letter count

Question 2: What will Q represent at the end of execution?

  1. Number of adverbs with an even letter count
  2. Number of adverbs with an odd letter count
  3. Number of words with any letter count
  4. Number of adverbs with any letter count

Answer: Option 2.

  • Number of adverbs with an odd letter count (as it’s in the else block of the even letter count check).

Question 3

Topic: Pseudocode Analysis (Boolean Logic)

The following pseudocode is executed using the “Scores” dataset. At the end of the execution, E will be True if which of the following conditions is met?

1  E = True
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     if(X.Gender == 'F'){
5        if(X.Physics < 60 or X.Chemistry < 60 or X.Maths < 60){
6           E = False
7        }
8     }
9     Move X to Table 2
10 }
  1. All female students have scores greater than or equal to 60 in either Physics, Chemistry or Maths
  2. All female students have scores less than 60 in either Physics, Chemistry or Maths
  3. There is at least one female student with scores less than 60 in Physics, Chemistry or Maths
  4. All female students have scores greater than or equal to 60 in Physics, Chemistry and Maths

Answer: Option 4.

  • All female students have scores greater than or equal to 60 in Physics, Chemistry and Maths

Question 4

Topic: Pseudocode Completion / Debugging

The procedure checkShoppingBills should return True if the minimum bill amount from a shop is greater than its average bill amount. Choose the correct code fragment to complete the procedure.

1  Procedure checkShoppingBills(Y)
2     count = 0, totalAmount = 0, minAmount = MAX_VALUE
3     while(Pile 1 has more cards){
4        Read the top card X from Pile 1
5        if(X.ShopName == Y.ShopName){
6           count = count + 1
7           totalAmount = totalAmount + X.TotalBillAmount
8           if(X.TotalBillAmount < minAmount){
9              minAmount = X.TotalBillAmount
10          }
11       }
12       Move card X to Pile 2
13    }
14    averageAmount = totalAmount / count
15    *********************
16    * fill the code     *
17    *********************
18 End checkShoppingBills
  1. Option 1
  2. Option 2
  3. Option 3
  4. Option 4

Answer: Option 4 (as per the accepted answer in the image).

1 if(minAmount > averageAmount){
2    return(True)
3 }
4 return(False)

Question 5

Topic: Pseudocode Analysis (Boolean Logic)

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

1  A = 0
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     B = True
5     if(X.Physics >= 60 and X.Chemistry >= 60 and X.Mathematics >= 60){
6        B = False
7     }
8     if(B){
9        A = A + 1
10    }
11    Move X to Table 2
12 }
  1. Number of students scored above 60 in all three subjects
  2. Number of students scored below 60 in at least any one subject
  3. A will always be 0
  4. Number of students scored exactly 60 in all three subjects

Answer: Option 2.

  • Number of students scored below 60 in at least any one subject

Question 6

Topic: Pseudocode Completion (Complex Boolean Logic)

This pseudocode should count the number of students whose total marks are above the overall average (AvgT) but who scored below the subject average in at least two subjects. Choose the correct code fragment to complete the pseudocode.

1  count = 0
2  while(Table 1 has more rows){
3     Read the first row X from Table 1
4     A = False, B = False, C = False, D = False
5     if(X.Total > avgT){
6        A = True
7     }
8     if(X.Mathematics < AvgM and X.Physics < AvgP){
9        B = True
10    }
11    if(X.Physics < AvgP and X.Chemistry < AvgC){
12       C = True
13    }
14    if(X.Chemistry < AvgC and X.Mathematics < AvgM){
15       D = True
16    }
17    *********************
18    * fill the code     *
19    *********************
20    Move X to Table 2
21 }
  1. Option 1
  2. Option 2
  3. Option 3
  4. Option 4

Answer: Option 1 (as per the accepted answer in the image).

1 if(A and (B or C or D)){
2    Count = Count + 1
3 }

Question 7

Topic: Pseudocode Analysis (Two-pass Algorithm)

The following pseudocode is executed using the “Scores” dataset. At the end of the execution, what does A represent?

1  SumA = 0, SumB = 0
2  CountA = 0, CountB = 0
3  A = 0, J = 0, K = 0
4
5  while(Pile 1 has more cards){
6     Read the top card X from Pile 1
7     if(X.CityTown == "Vellore"){
8        SumA = SumA + X.Total
9        CountA = CountA + 1
10    }
11    if(X.CityTown == "Chennai"){
12       SumB = SumB + X.Total
13       CountB = CountB + 1
14    }
15    Move card X to Pile 2
16 }
17
18 J = SumA / CountA
19 K = SumB / CountB
20
21 while(Pile 2 has more cards){
22    Read the top card X from Pile 2
23    if(X.CityTown == "Madurai"){
24       if(X.Total > J and X.Total < K){
25          A = A + 1
26       }
27    }
28    Move card X to Pile 1
29 }
  1. …greater than the average marks of students
  2. …greater than the average marks of students from Vellore and Chennai
  3. …greater than the average marks of students from Vellore but less than that of Chennai
  4. …greater than the average marks of students from Chennai but less than that of Vellore

Answer: Option 3.

  • greater than the average marks of students from Vellore but less than that of Chennai

Question 8

Topic: Pseudocode Debugging

This pseudocode is intended to capture the number of female students (A) who are below average in at least one subject. Identify all mistakes in the logic.

1  A = 0
2  while(Table 1 has more rows){
3     B = True
4     Read the first row X from Table 1
5     if(X.Gender == 'F'){
6        if(X.Mathematics < M){
7           B = False
8        }
9        if(X.Physics < P){
10          B = True
11       }
12       if(X.Chemistry < C){
13          B = False
14       }
15       if(B){
16          A = A + 1
17       }
18    }
19    Move X to Table 2
20 }
  1. Line 1: Incorrect initialization of A
  2. Line 3: Incorrect initialization of B
  3. Line 7: Incorrect Update of B
  4. Line 13: Incorrect Update of B
  5. No error in the code

Answer: Options 2, 3, and 4.

  • Line 3: B is initialized outside the student-specific logic. It should be reset for each student.
  • Line 7 & 13 (and 10): The updates to B are sequential and overwrite each other, failing to correctly check for “at least one” condition.

Question 9

Topic: Pseudocode Analysis (Procedures/Functions)

What will A represent at the end of the execution of this pseudocode?

// Main procedure
A = 0
while(Pile 1 has more cards){
    Read the top card X from Pile 1
    A = A + isInSeq(X)
    Move X to Pile 2
}
 
// Sub-procedure
Procedure isInSeq(X)
    if(X.Mathematics > X.Physics){
        if(X.Chemistry > X.Physics){
            return(1)
        }
    }
    return(0)
  1. Number of students with highest marks only in Mathematics out of their three subjects’ marks
  2. Number of students with highest marks only in Mathematics and lowest marks only in Physics
  3. Number of students with highest marks only in Chemistry out of their three subjects’ marks
  4. Number of students with lowest marks only in Physics out of their three subjects’ marks

Answer: Option 4.

  • Number of students with lowest marks only in Physics out of their three subjects’ marks

Question 10

Topic: Pseudocode Analysis (Two-pass Algorithm)

What will A represent at the end of this execution on the “Words” dataset?

1  SumT = 0, CountT = 0, B = 0
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     CountT = CountT + 1
5     SumT = SumT + X.LetterCount
6     Move X to Table 2
7  }
8
9  B = SumT / CountT
10 A = 0
11 while(Table 2 has more rows){
12    Read the first row X in Table 2
13    if(X.word ends with a comma){
14       if(X.LetterCount > B){
15          A = A + 1
16       }
17    }
18    Move X to Table 1
19 }
  1. Number of words that end with a comma.
  2. Number of words that end with a comma and have a letter count greater than ratio of number of words to sum of letter count.
  3. Number of words that end with a comma and have a letter count less than or equal to the average letter count of dataset.
  4. Number of words that end with a comma and have a letter count greater than the average letter count of dataset.

Answer: Option 4.

  • Number of words that end with a comma and have a letter count greater than the average letter count of dataset.

Week 4


Question 1

Topic: Pseudocode Analysis (Nested Loops)

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

1  A = 0
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     i = 1, B = False
5     while(i <= X.LetterCount){
6        if(ith Letter of X.word followed by a vowel){
7           B = True
8        }
9        i = i + 1
10    }
11    if(B){
12       A = A + 1
13    }
14    Move X to Table 2
15 }
  1. Number of words with at most one letter followed by a vowel
  2. Number of words with exactly one letter followed by a vowel
  3. Number of words without any letters followed by a vowel
  4. Number of words with at least one letter followed by a vowel

Answer: Option 4.

  • Number of words with at least one letter followed by a vowel

Question 2

Topic: Pseudocode Analysis (Nested Loops & Procedures)

The following pseudocode is executed using the “Olympics” dataset. What will E represent at the end of the execution? (Assume no player has won more than one medal).

1  E = 0
2  while(Table 1 has more rows){
3     Read the first row P in Table 1
4     Move P to Table 2
5     while(Table 1 has more rows){
6        Read the first row Q in Table 1
7        if(findDuo(P, Q)){
8           E = E + 1
9        }
10       Move Q to Table 3
11    }
12    Move all rows from Table 3 to Table 1
13 }
14
15 Procedure findDuo(P, Q)
16    if(P.Country == Q.Country and P.Medal != Q.Medal){
17       return(True)
18    }
19    else{
20       return(False)
21    }
22 End findDuo
  1. Number of players from the same country with different medals
  2. Number of players from different countries with the same medals
  3. Number of pairs of players from the same country with different medals
  4. Number of pairs of players from different countries with the same medals

Answer: Option 3.

  • Number of pairs of players from the same country with different medals

Questions 3 & 4

Topic: Pseudocode Analysis (Nested Loops)

The following pseudocode is executed using the “Library” dataset. (Assume all authors have distinct names and each book is written by a single author).

1  A = 1, N = 0, count = 0, value = 0
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     Move X to Table 2
5     while(Table 1 has more rows){
6        Read the first row Y in Table 1
7        if(X.Author == Y.Author){
8           A = A + 1
9           Move Y to Table 2
10       }
11       else{
12          Move Y to Table 3
13       }
14    }
15    if(A > N){
16       N = A
17    }
18    A = 1
19    count = count + 1
20    Delete all rows of Table 2
21    Move all rows from Table 3 to Table 1
22 }

Question 3: What will N represent at the end of execution?

  1. Maximum number of books published by an author
  2. Maximum number of books published by a pair of authors
  3. Maximum number of books published by an author in a year
  4. Maximum number of books published by a pair of authors in a year

Answer: Option 1.

  • Maximum number of books published by an author

Question 4: What will count represent at the end of execution?

  1. Total number of books
  2. Number of authors
  3. Number of books of same genre
  4. Number of authors who wrote books of same genre

Answer: Option 2.

  • Number of authors

Question 5

Topic: Pseudocode Completion

This pseudocode should calculate frac, the ratio of customers who purchased both “Soap” and “Facewash” (bCount) to the number of customers who purchased “Facewash” (mCount). Choose the correct code fragment to complete the procedure.

1  mCount = 0, bCount = 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  }
9  frac = bCount / mCount
10
11 Procedure isItem(Y, A)
12    C = False
13    while(Card Y has more items){
14       Read an item Z from ItemList of card Y
15       if(Z.item == A){
16          C = True
17       }
18       Remove Z from ItemList of Y
19    }
20    return(C)
21 End isItem
  1. Option 1
  2. Option 2
  3. Option 3
  4. Option 4

Answer: Option 4 (as per the accepted answer).

1 if(isItem(X, "Facewash")){
2    mCount = mCount + 1
3    if(isItem(X, "Soap")){
4       bCount = bCount + 1
5    }
6 }

Question 6

Topic: Pseudocode Analysis (Nested Loops & Procedures)

What will count represent at the end of this execution on the “Words” dataset?

1  count = 0
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     Move X to Table 2
5     while(Table 1 has more rows){
6        Read the first row Y in Table 1
7        if(customCheck(X) and customCheck(Y)){
8           count = count + 1
9        }
10       Move Y to Table 3
11    }
12    Move all rows from Table 3 to Table 1
13 }
14
15 Procedure customCheck(P)
16    A = 0, i = 1
17    B = False, Flag = False
18    while(i <= P.LetterCount){
19       if(ith letter of P.word is a consonant){
20          A = A + 1
21          B = True
22       }
23       else{
24          B = False
25       }
26       if(A >= 2 and B){
27          Flag = True
28       }
29       i = i + 1
30    }
31    return(Flag)
32 End customCheck
  1. Number of pairs of words with exactly two consonants
  2. Number of pairs of words with at least two consonants
  3. Number of pairs of words with exactly two consecutive consonants
  4. Number of pairs of words with at least two consecutive consonants

Answer: Option 4.

  • Number of pairs of words with at least two consecutive consonants

Question 7

Topic: Pseudocode Debugging

Two words are conjugate if they have the same number of vowels and consonants. The procedure below is intended to count conjugate pairs but has mistakes. Identify the incorrect line.

1  count = 0
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     Move X to Table 2
5     while(Table 1 has more rows){
6        Read the first row Y in Table 1
7        if(X.LetterCount == Y.LetterCount){
8           if(vCount(X) == vCount(Y)){
9              count = count + 1
10          }
11       }
12       Move Y to Table 3
13    }
14    Move all rows from Table 3 to Table 1
15 }
16
17 Procedure vCount(Z)
18    vowelCount = 0, i = 0
19    while(i <= Z.LetterCount){
20       if(ith letter of Z.word is a vowel){
21          vowelCount = vowelCount + 1
22       }
23       i = i + 1
24    }
25    return(vowelCount)
26 End vCount
  1. Line 8: Invalid parameter used.
  2. Line 8: Incorrect condition to update count (consonants not compared).
  3. Line 17: Incorrect initialization of vowelCount.
  4. Line 17: Incorrect initialization of i.
  5. No mistake.

Answer: Option 4.

  • Line 17: Incorrect initialization of i. (The loop counter i should be initialized to 1, not 0, if we are considering the 1st letter to the Nth letter).

Questions 8 & 9

Topic: Pseudocode Analysis (Procedures with Complex Logic)

A student can join a club if their subject score is above the required score. M, P, and C count students in Maths, Physics, and Chemistry clubs.

1  M = 0, P = 0, C = 0
2  while(Table 1 has more rows){
3     Read the first row X in Table 1
4     subject = maxSubject(X)
5     if(subject == "Mathematics" and X.Mathematics > 95){
6        M = M + 1
7     }
8     if(subject == "Physics" and X.Physics > 90){
9        P = P + 1
10    }
11    if(subject == "Chemistry" and X.Chemistry > 90){
12       C = C + 1
13    }
14    Move X to Table 2
15 }
16
17 Procedure maxSubject(Z)
18    if(Z.Physics > Z.Mathematics){
19       if(Z.Physics > Z.Chemistry){
20          return("Physics")
21       } else {
22          return("Chemistry")
23       }
24    } else {
25       if(Z.Mathematics > Z.Chemistry){
26          return("Mathematics")
27       } else {
28          return("Chemistry")
29       }
30    }
31 End maxSubject

Question 8: Which club can a student join if they get 92 in Physics, 92 in Mathematics, and 84 in Chemistry?

  1. Physics club
  2. Chemistry club
  3. Mathematics club
  4. The student cannot join any club

Answer: Option 4.

  • The student cannot join any club

Question 9: When can a student join more than one club?

  1. If the student gets more than 90 in at least two subjects
  2. If the student gets more than 90 in Physics and Chemistry
  3. If the student gets more than 90 and the same marks in Physics and Chemistry
  4. A student cannot join more than one club

Answer: Option 4.

  • A student cannot join more than one club

Question 10

Topic: Pseudocode Analysis (State Variables)

What will A represent at the end of this execution on the “Words” dataset?

1  A = 0, B = 0
2  P = True, Q = False
3  while(Table 1 has more rows){
4     Read the first row X in Table 1
5     if(X.PartOfSpeech == "Adverb" and P){
6        P = False
7        Q = True
8     }
9     else{
10       if(not Q){
11          A = A + 1
12       }
13    }
14    if(X.word ends with a full stop){
15       P = True
16       Q = False
17    }
18    Move X to Table 2
19 }
  1. Number of adverbs before the first adverb in every sentence
  2. Number of words after the first adverb in every sentence
  3. Number of words before the first adverb or full stop in every sentence
  4. Number of adjectives before the first adverb in every sentence
  5. Number of words before the first adverb in every sentence

Answer: Option 3.

  • Number of words before the first adverb or full stop in every sentence

Quiz 2 (Week 4 to 8)


Week 5