0% found this document useful (0 votes)
1 views8 pages

Thinking Solutions

The document analyzes pseudocode executed on various datasets to determine what specific variables represent at the end of execution. It covers datasets such as 'Words', 'Olympics', 'Library', and 'Shopping Bills', providing detailed explanations for variables A, E, N, count, and others. Each section concludes with the correct interpretation of the variable based on the pseudocode logic.

Uploaded by

profmgtnair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views8 pages

Thinking Solutions

The document analyzes pseudocode executed on various datasets to determine what specific variables represent at the end of execution. It covers datasets such as 'Words', 'Olympics', 'Library', and 'Shopping Bills', providing detailed explanations for variables A, E, N, count, and others. Each section concludes with the correct interpretation of the variable based on the pseudocode logic.

Uploaded by

profmgtnair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1. The pseudocode is executed using the “Words” dataset.

What will A represent at the


end of the execution?
a. Number of words with at most one letter followed by a vowel
b. Number of words with exactly one letter followed by a vowel
c. Number of words without any letters followed by a vowel
d. Number of words with at least one letter followed by a vowel
Ans. Let's analyze the pseudocode step-by-step to understand what A will represent at the end:

Pseudocode Summary:
A = 0: A counter initialized to zero.

While there are more rows in Table 1 (dataset Words):

Read a word X from Table 1.

Initialize i = 1, B = False

Inner while loop: For each position i from 1 to the number of letters in X:

Check if the i-th letter is followed by a vowel.

If yes, set B = True.

After checking all letters:

If B == True, increment A by 1.

Move X to Table 2.

What does the code do?


The inner loop checks for at least one letter that is followed by a vowel.

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:

• E = 0: Counter for something being tracked.


• The main loop processes every record P in Table 1.
o It compares P with every other record Q still left in Table 1.
o The comparison is done using a procedure called findDuo(P, Q).
o If findDuo returns True, E is incremented by 1.

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:

• The outer loop picks player P.


• The inner loop compares it with every other remaining player Q (excluding itself).
• For each valid (P, Q) pair matching the findDuo condition, E is incremented.
• This means each unordered pair (P, Q) from the same country with different medals
is counted once.

✅ 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

• A: Counter for books by the same author in one group.


• N: Keeps track of the maximum A seen so far.
• count and value are unused in determining N.

Main Loop Overview:

• The outer while loop runs as long as Table 1 has rows.


• In each iteration:
1. A record X is picked and moved to Table 2.
2. Then, all other records Y in Table 1 are compared:
§ If Y.Author == X.Author, A is incremented and Y is also moved to
Table 2.
§ Otherwise, Y is moved to Table 3.
3. After scanning, if A > N, update N = A.
4. Reset A = 1.
5. Clear Table 2 (processed books), and move Table 3 rows back to Table 1.

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:

N represents the maximum number of books published by any one author.

Correct Answer:

✔ Maximum number of books published by an author

4. What will count represent at the end of execution?


a. Total number of books
b. Number of authors
c. Number of books of same genre
d. Number of authors who wrote books of same genre

4
Ans. Let’s analyze what the variable count represents in the pseudocode.

🧠 What the Code Does:

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:

• Each time a new author group is processed, count increases by 1.


• That means:
o First group: All books by Author1 → count = 1
o Second group: All books by Author2 → count = 2
o And so on...

✅ 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:

1. Identify customers who bought “Facewash” → increment mCount.


2. Among them, identify those who also bought “Soap” → increment bCount.

✅ Let's fill the missing code between lines 4–5:

if(isItem(X, "Facewash")){
mCount = mCount + 1
if(isItem(X, "Soap")){
bCount = bCount + 1
}
}

🔁 Full Logic Flow:

• For each card X (customer),

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.

✅ Correct Code Fragment to Insert:

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.

🔁 Main Loop Logic:

• The outer loop picks one word X.


• The inner loop compares it with every other word Y still in Table 1.
• If both customCheck(X) and customCheck(Y) return True, then count is
incremented.

✅ Final Meaning of count:

count represents the number of word pairs (X, Y) such that both X and Y contain at least
two consecutive consonants.

✔ Correct Answer:

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

You might also like