ITPEC IP April 2024 Question 25
A technique that represents a figure with pixels is considered. In the case of Fig. 1, when each row of the figure of 3×3 pixels is read on a pixel-by-pixel basis from upper left to right and B and W are respectively written for black and white, the result is “BWBBBBBWB” (9 characters). Then, when a succession of n characters of “B”s or “W”s is represented as “Bn” or “Wn” respectively (where n is an integer of 2 or greater), Fig. 1 can be represented as “BWB5WB” (6 characters) and the compression ratio in this case is defined as 6/9 or 66.7%. When the figure of 5×5 pixels in Fig. 2 is represented by using the same technique, what is the compression ratio in percentage?
Explanation
52.0% — encode Fig. 2 as one continuous string, as Fig. 1 does, then divide the encoded length by the 25 pixels.
Read row by row from the upper left: BBBBB, BWWWW, BBBBW, BWWWW, BWWWW. A run continues across the end of a row, as the B5 in Fig. 1 does, so the runs are B6, W4, B4, W1, B1, W4, B1, W4.
- •Runs of 2 or more take 2 characters: B6, W4, B4, W4, W4 give 5 × 2 = 10
- •Single pixels take 1 character: W, B, B give 3
- •Encoded string B6W4B4WBW4BW4: 10 + 3 = 13 characters
- •Compression ratio: 13 ÷ 25 = 0.52, that is 52.0%
Answer (b)
Why not others:
- •(a) 48.0 — 100 − 52, the share of characters saved, not the encoded length over the original length as the ratio is defined
- •(c) 76.0 — 19 ÷ 25: reading the figure column by column gives B6WBW2BWBW2BWBW2BW4, 19 characters, but the technique reads rows from left to right
- •(d) 88.0 — 22 ÷ 25, a length no reading order of the figure produces
Key rule: In run-length encoding the scan order matters: follow the order the method defines, let runs continue across line ends, and write a single pixel without a count.
Multimedia · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.