Imagine you have a large box of books and you want to fit them into a smaller box without losing any pages. What is the main goal of data compression in computing?
Think about how you can fit more books in a smaller box without losing any pages.
Data compression reduces the size of data so it uses less storage or bandwidth, similar to packing books tightly without losing any pages.
Run-length encoding (RLE) compresses data by replacing repeated characters with a count and the character. What is the output of encoding the string AAAABBBCCDAA using RLE?
Input: AAAABBBCCDAA Output: ?
Count how many times each character repeats consecutively and write the count before the character.
RLE counts consecutive characters and writes the count followed by the character: 4 A's, 3 B's, 2 C's, 1 D, 2 A's.
Which type of compression uses a dictionary of repeated patterns and replaces repeated data with references to this dictionary?
Think about a compression method that builds a list of common pieces and reuses them.
Dictionary-based compression stores repeated patterns in a dictionary and replaces repeats with references to save space.
Which statement correctly compares lossless and lossy compression?
Think about whether the original data can be perfectly restored after compression.
Lossless compression keeps all data so it can be perfectly restored; lossy compression removes some data to save more space but loses some quality.
Given the characters and their frequencies: {'a': 5, 'b': 9, 'c': 12, 'd': 13, 'e': 16, 'f': 45}, what is the length of the Huffman code for character 'f'?
Frequencies: a=5, b=9, c=12, d=13, e=16, f=45 Question: Length of Huffman code for 'f'?
In Huffman coding, the most frequent character gets the shortest code.
Since 'f' has the highest frequency, it gets the shortest code, which is 1 bit long.