Bird
0
0

A student wrote this pseudocode for a simple compression:

medium📝 Analysis Q6 of 15
Intro to Computing - How Data is Represented
A student wrote this pseudocode for a simple compression:
for each character in string:
if character is same as previous:
increase count
else:
output count and previous character
reset count to 1

What is the main error in this approach?
AIt outputs characters instead of counts
BIt increases count even when characters differ
CIt resets count before reading the first character
DIt does not output the last character and its count
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop logic

    The loop outputs count and character only when a new character appears.
  2. Step 2: Identify missing output

    The last character group is not output after the loop ends.
  3. Final Answer:

    It does not output the last character and its count -> Option D
  4. Quick Check:

    Missing last output = Main error [OK]
Quick Trick: Always output last group after loop ends [OK]
Common Mistakes:
  • Forgetting last output
  • Resetting count incorrectly
  • Outputting before first character

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Intro to Computing Quizzes