Thinking Solutions
Thinking Solutions
Pseudocode Summary:
A = 0: A counter initialized to zero.
Initialize i = 1, B = False
Inner while loop: For each position i from 1 to the number of letters in X:
If B == True, increment A by 1.
Move X to Table 2.
As soon as such a pair is found, B becomes True, and A is incremented by 1 for that word.
This happens regardless of how many such occurrences are in the word — even one is enough.
✅ Therefore:
A counts the number of words in Table 1 that contain at least one letter followed by a vowel.
Correct Answer: ✔ Number of words with at least one letter followed by a vowel.
1
2. The pseudocode is executed using the “Olympics” dataset. What will E represent at the
end of the execution? Assume that none of the players have won more than one medal.
a. Number of players from the same country with different medals
b. Number of players from different countries with the same medals
c. Number of pairs of players from the same country with different medals
d. Number of pairs of players from different countries with the same medals
Ans. Let's analyze what the pseudocode is doing to determine the meaning of variable E:
High-Level Breakdown:
findDuo(P, Q):
Return True if:
P.Country == Q.Country
AND
P.Medal != Q.Medal
So this procedure identifies two different players from the same country but with
different medals.
2
Key Observation:
✅ Therefore:
E counts the number of distinct pairs of players from the same country who won
different medals.
Correct Answer:
✔ Number of pairs of players from the same country with different medals
3. The pseudocode is executed using the “Library” dataset. Assume that all authors have
distinct names and each book is written by a single author. What will N represent at the
end of execution?
a. Maximum number of books published by an author
b. Maximum number of books published by a pair of authors
c. Maximum number of books published by an author in a year
d. Maximum number of books published by a pair of authors in a year
Ans. Let's analyze what the pseudocode does, to determine the final meaning of N:
3
Initial Setup:
A = 1, N = 0, count = 0, value = 0
Key Logic:
This process groups and removes all books by a single author in each cycle, tracking how
many there are using A. The variable N always holds the maximum number of books found
for any single author.
✅ Therefore:
Correct Answer:
4
Ans. Let’s analyze what the variable count represents in the pseudocode.
1. The outer while loop processes all rows in Table 1, one group at a time.
2. In each outer loop iteration:
o It picks one book X and then finds all other books with the same author (i.e.,
X.Author == Y.Author) from the remaining records.
o All matching books are moved to Table 2.
o The rest are sent to Table 3.
3. After processing one group of same-author books:
o The code checks whether the current group size A is greater than N and updates
N accordingly.
o Then, it does: count = count + 1.
📌 Key Observation:
✅ Therefore:
count is the number of distinct authors — because each outer loop iteration removes all
books by one author.
Correct Answer:
✔ Number of authors
5
5. The given pseudocode is executed using the “Shopping Bills” dataset. frac stores the
ratio of the number of customers who purchased both “Soap” and “Facewash” to the
number of customers who purchased “Facewash”. Choose the correct code fragment to
complete the pseudocode. (Assume there is at least one customer who has purchased
“Facewash”).
Ans. To complete the pseudocode so that frac stores the ratio of customers who purchased
both “Soap” and “Facewash” to those who purchased “Facewash”, we must:
if(isItem(X, "Facewash")){
mCount = mCount + 1
if(isItem(X, "Soap")){
bCount = bCount + 1
}
}
6
o Check if “Facewash” is in their item list using isItem(X, "Facewash").
§ If yes, increment mCount.
§ Then check if they also have “Soap” using isItem(X, "Soap").
§ If yes, increment bCount.
if(isItem(X, "Facewash")){
mCount = mCount + 1
if(isItem(X, "Soap")){
bCount = bCount + 1
}
}
This ensures frac = bCount / mCount correctly calculates the required ratio.
6. The pseudocode is executed using the “Words” dataset. What will count represent at
the end of execution?
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
7
Ans. Let's carefully analyze the pseudocode to determine what count represents.
🔍 Understanding customCheck(P):
• Inputs: A word P.
• The function scans each letter of P.Word.
• It looks for a pair of consecutive consonants:
o B is set to True when a consonant is found.
o If the next letter is also a consonant (i.e., B is already True), then:
§ A is set to 1
§ Later, Flag becomes True, and customCheck returns True.
✅ So, **customCheck(P) returns True if and only if word P contains at least two
consecutive consonants.
count represents the number of word pairs (X, Y) such that both X and Y contain at least
two consecutive consonants.
✔ Correct Answer: