Data Compression - AP Computer Science Principles

  1. Which of the following best describes the primary difference between lossless and lossy data compression algorithms?
    Answer: Lossless compression guarantees that the original data can be perfectly reconstructed, while lossy compression only allows for an approximation of the original data. The fundamental distinction between the two compression types is data fidelity. Lossless compression algorithms preserve all original data, allowing for perfect reconstruction. Lossy algorithms achieve higher compression ratios by permanently discarding data that is deemed less important, resulting in an approximation of the original.
  2. Fewer bits does not necessarily mean less information. Which of the following statements provides the best justification for this claim in the context of lossless compression?
    Answer: Lossless compression uses fewer bits by finding more efficient ways to represent patterns and repetitions in the original data. This statement is the essence of lossless compression. It doesn't remove information; it encodes the existing information more efficiently. By identifying redundancies (like a repeated word or color pattern) and creating a shorthand for them, the same amount of information can be represented with a smaller number of bits.
  3. Read the passage. Streaming services rely on compression to deliver content efficiently across networks with varying speeds. Compression reduces the number of bits sent, which can prevent buffering and lower data usage. Lossless compression preserves exact data and is common for text like subtitles, while lossy compression is common for images and video because it can shrink files much more by discarding information viewers are less likely to notice. JPEG is a familiar lossy format for still images, and MPEG is widely used for video, often combining multiple strategies to reduce size. The main challenge is balancing smaller files against visible artifacts or reduced clarity. Services tune compression levels to maintain acceptable quality while keeping playback smooth. Why is lossy compression preferred in many streaming video applications?
    Answer: It achieves much smaller files, with tolerable quality loss. This question tests AP Computer Science Principles skills in understanding data compression, specifically why lossy compression is preferred for streaming video applications. Data compression reduces file sizes to enable efficient streaming, with lossy compression achieving much greater reduction by removing information viewers are unlikely to notice. In the provided passage, lossy compression for video is described as being able to 'shrink files much more by discarding information viewers are less likely to notice,' with the key benefit being prevention of buffering and smooth playback. Choice A is correct because it captures the essential trade-off: achieving much smaller files (enabling smooth streaming) with tolerable quality loss, as stated in the passage's discussion of balancing file size against artifacts. Choice B is incorrect because it describes lossless compression - the passage clearly states lossy compression discards information. To help students: Discuss real-world streaming constraints like bandwidth limitations and why perfect quality isn't always necessary. Use examples of quality settings in streaming platforms to illustrate the compression trade-offs.
  4. A hospital needs to store high-resolution MRI scans. These images are very large, but it is critical that no detail, however small, is altered or lost during storage and retrieval. What is the most appropriate compression method?
    Answer: Lossless compression, because the exact original image data must be perfectly recoverable for accurate medical diagnosis. In medical imaging, the integrity of the data is paramount. Any loss of detail could lead to a misdiagnosis. Therefore, only lossless compression is acceptable, as it guarantees that the decompressed image is identical to the original scan.
  5. A software company needs to distribute a critical program update to its users. The update file must be exactly identical on the user's computer as it was on the company's server to function correctly. Which type of compression is most appropriate for this task?
    Answer: Lossless compression, because the original file must be perfectly reconstructed after decompression to ensure the program's integrity. For program files, executables, or any data where perfect integrity is required, lossless compression is the only acceptable option. Any loss or alteration of data (as would occur with lossy compression) would corrupt the program and cause it to fail.
  6. Which of the following data types requires lossless compression if it is to be compressed at all?
    Answer: A text file containing the source code for a computer program. Source code is a form of text where every single character, space, and symbol is critical. Changing or removing even one character can cause the entire program to fail. Therefore, if compressed, it must be done losslessly. The other options are all forms of media where some data loss is often acceptable.
  7. A scientist is transmitting a massive dataset from a remote arctic research station to a university. The data consists of precise temperature readings where every digit is scientifically significant. Due to the satellite link's limited bandwidth, the data must be compressed. Which approach should be taken?
    Answer: Use a lossless compression algorithm to reduce the transmission size while ensuring every measurement is perfectly preserved. Scientific data, especially precise measurements, require perfect integrity. Lossy compression would alter the values, invalidating the research. Lossless compression provides the necessary balance by reducing the file size for more efficient transmission while guaranteeing that the data received is identical to the data collected.
  8. Read the passage. A media company publishes articles, photos, and videos and uses different compression methods depending on content. Compression reduces the number of bits needed by encoding patterns more efficiently, helping files download faster and cost less to store. Lossless compression preserves exact data and is favored for text, where accuracy matters, while lossy compression discards some information to achieve smaller files and is common for images and video. Huffman coding and LZW are lossless techniques often used for text or general data, while JPEG is a popular lossy format for still images. MPEG is widely used for video compression, often balancing quality against file size. Selecting the right method depends on whether perfect fidelity or smaller size is the priority. Based on the text, how does Huffman coding differ from JPEG compression?
    Answer: Huffman is lossless for symbols; JPEG is lossy for images. This question tests AP Computer Science Principles skills in understanding data compression, specifically comparing the fundamental differences between Huffman coding and JPEG compression. Data compression uses different methods for different content types, with Huffman coding being a lossless technique for text and symbols, while JPEG is a lossy format designed specifically for images. In the provided passage, Huffman coding is described as a 'lossless technique often used for text,' while JPEG is identified as 'a popular lossy format for still images.' Choice A is correct because it accurately captures this fundamental distinction: Huffman is lossless and works with symbols/text, while JPEG is lossy and designed for images, as explicitly stated in the passage. Choice C is incorrect because it reverses their characteristics - Huffman preserves data (lossless) while JPEG discards details (lossy). To help students: Create comparison tables showing compression methods grouped by lossless vs. lossy and their typical applications. Emphasize that the choice of compression method depends on both the content type and whether perfect accuracy is required.
  9. Read the passage. A messaging app compresses text to save bandwidth and storage while keeping messages readable and unchanged. Compression reduces file size by encoding common patterns with fewer bits, and for text this must be lossless so every character is restored exactly. Huffman coding is one lossless technique that assigns shorter bit patterns to characters that appear more often, which can shrink many natural-language messages. LZW is another lossless method that replaces repeated sequences with short codes from a growing dictionary, which can be effective for repetitive logs or structured text. In contrast, JPEG and MPEG are typically lossy and are chosen for images and video where small inaccuracies are acceptable. The app therefore favors lossless algorithms for text to avoid altering meaning. Based on the text, what is the primary benefit of using Huffman coding?
    Answer: It assigns shorter codes to frequent symbols to reduce size. This question tests AP Computer Science Principles skills in understanding data compression, specifically how Huffman coding works as a lossless compression technique. Data compression reduces file sizes by encoding information more efficiently, with Huffman coding being a lossless method that assigns variable-length codes based on symbol frequency. In the provided passage, Huffman coding is described as 'one lossless technique that assigns shorter bit patterns to characters that appear more often, which can shrink many natural-language messages.' Choice A is correct because it accurately describes Huffman coding's primary benefit: assigning shorter codes to frequent symbols to reduce size, exactly as stated in the passage. Choice B is incorrect because it describes lossy compression behavior (removing pixels), while Huffman coding is explicitly identified as lossless in the passage. To help students: Use frequency analysis exercises to demonstrate how Huffman coding works. Show examples of common letters (like 'e' in English) getting shorter codes than rare letters (like 'q').
  10. In which of the following situations would the use of lossy compression be unacceptable?
    Answer: A financial institution archiving a database of customer transaction records for auditing purposes. Financial records require absolute precision. Any alteration, no matter how small, could have serious legal and financial consequences. Therefore, only lossless compression is acceptable for this type of data. The other options describe scenarios where loss of media quality is a common and acceptable trade-off.
  11. Read the passage. In a streaming service, compression shrinks data so videos load quickly and use less bandwidth. The text explains that lossless compression preserves every bit of information, while lossy compression removes some details to achieve smaller files. For digital media, JPEG commonly compresses photos by discarding subtle image data, and MPEG commonly compresses video by reducing repeated or less-noticeable visual information across frames. This creates a trade-off: smaller files and smoother streaming versus potential blur or blocky artifacts. In contrast, text and program files often use lossless methods such as Huffman coding and LZW, since even a missing character can change meaning. Based on the text, what trade-offs are involved in using MPEG?
    Answer: It reduces file size but may lower visual quality. This question tests AP Computer Science Principles skills in understanding data compression, specifically the trade-offs involved in lossy compression methods like MPEG. Data compression reduces file sizes through various methods, with lossy compression achieving smaller sizes by permanently removing some data that is deemed less important or noticeable. The passage specifically states that MPEG 'reduces repeated or less-noticeable visual information across frames' and creates 'a trade-off: smaller files and smoother streaming versus potential blur or blocky artifacts.' Choice B is correct because it accurately captures this trade-off - MPEG reduces file size (enabling smoother streaming) but may lower visual quality (through blur or artifacts). Choice A is incorrect because MPEG decreases, not increases, file size, and Choice C falsely claims no bandwidth cost when the passage emphasizes bandwidth savings. To help students: Focus on identifying key phrases about trade-offs in compression contexts. Practice recognizing that lossy compression always involves sacrificing some quality for efficiency gains.
  12. Read the passage. In a streaming-service setting, data compression reduces the number of bits needed to store or transmit information. Compression works by finding patterns and representing them more efficiently, which helps platforms deliver movies, music, and captions quickly over limited bandwidth. Two broad categories appear: lossless compression preserves every original detail so the decompressed data matches exactly, while lossy compression removes some information to achieve smaller files. For text such as subtitles and chat logs, lossless methods are common because even a small change can alter meaning; Huffman coding assigns shorter bit patterns to frequent symbols, and LZW replaces repeated sequences with short codes. For images and video, lossy methods often dominate because the human eye tolerates small changes; JPEG compresses still images by discarding subtle visual details, and MPEG compresses video by combining spatial compression with frame-to-frame prediction. The trade-off is constant: stronger compression usually means smaller files but more noticeable artifacts, so services adjust settings to balance quality and smooth playback. Based on the text, what trade-offs are involved in using JPEG compression?
    Answer: It reduces file size but may introduce visible artifacts. This question tests AP Computer Science Principles skills in understanding data compression, specifically the trade-offs involved in lossy compression methods like JPEG. Data compression reduces file sizes by removing redundant information, with lossy compression achieving greater reduction by permanently discarding some data that may not be noticeable to users. In the provided passage, JPEG compression is described as discarding 'subtle visual details' to compress still images, while noting that 'stronger compression usually means smaller files but more noticeable artifacts.' Choice A is correct because it accurately captures both aspects of the JPEG trade-off: reduced file size (benefit) and potential visible artifacts (cost) as stated in the passage. Choice B is incorrect because it contradicts the lossy nature of JPEG - the passage clearly states JPEG 'discards subtle visual details,' not preserving every pixel. To help students: Focus on identifying key terms like 'trade-off' and 'artifacts' in compression contexts. Practice distinguishing between the benefits (smaller files) and costs (quality loss) of different compression methods.
  13. Read the passage. In a streaming service, compression shrinks data so videos load quickly and use less bandwidth. The text explains that lossless compression preserves every bit of information, while lossy compression removes some details to achieve smaller files. For digital media, JPEG commonly compresses photos by discarding subtle image data, and MPEG commonly compresses video by reducing repeated or less-noticeable visual information across frames. This creates a trade-off: smaller files and smoother streaming versus potential blur or blocky artifacts. In contrast, text and program files often use lossless methods such as Huffman coding and LZW, since even a missing character can change meaning. Based on the text, which scenario best demonstrates the use of LZW compression?
    Answer: Shrinking a text document while keeping every character unchanged. This question tests AP Computer Science Principles skills in understanding data compression, specifically identifying appropriate applications for LZW lossless compression. Data compression methods must match the requirements of the data type, with LZW being a lossless algorithm particularly suited for text where data integrity is paramount. The passage groups LZW with Huffman coding as lossless methods used for 'text and program files...since even a missing character can change meaning,' emphasizing its ability to compress while preserving every character. Choice A is correct because it describes the ideal LZW scenario: shrinking a text document (achieving compression) while keeping every character unchanged (maintaining lossless integrity). Choice B describes video compression with temporal redundancy (MPEG territory), and Choice C describes lossy compression that permanently discards data. To help students: Explain how LZW builds a dictionary of repeated patterns to achieve compression without data loss. Practice identifying which scenarios require lossless compression based on the consequences of data alteration.
  14. The effectiveness of a lossless compression algorithm often depends on the content of the data. On which of the following files would a lossless algorithm likely achieve the greatest percentage of size reduction?
    Answer: A text document consisting of the same paragraph repeated thousands of times. Lossless compression algorithms work by identifying and representing redundancies (patterns and repetitions) more efficiently. A text file with thousands of repeated paragraphs is highly redundant and will therefore compress very well. Random or already compressed data has little to no redundancy for the algorithm to exploit.
  15. Read the passage. In a streaming service, compression shrinks data so videos load quickly and use less bandwidth. The text explains that lossless compression preserves every bit of information, while lossy compression removes some details to achieve smaller files. For digital media, JPEG commonly compresses photos by discarding subtle image data, and MPEG commonly compresses video by reducing repeated or less-noticeable visual information across frames. This creates a trade-off: smaller files and smoother streaming versus potential blur or blocky artifacts. In contrast, text and program files often use lossless methods such as Huffman coding and LZW, since even a missing character can change meaning. Based on the text, how does lossy compression differ from lossless compression?
    Answer: Lossy removes some details; lossless preserves all information. This question tests AP Computer Science Principles skills in understanding data compression, specifically differentiating between lossless and lossy compression methods. Data compression can be categorized into two main types: lossless compression, which preserves all original data and allows perfect reconstruction, and lossy compression, which permanently removes some data to achieve greater compression ratios. The passage explicitly states that 'lossless compression preserves every bit of information, while lossy compression removes some details to achieve smaller files.' Choice A is correct because it directly reflects this fundamental distinction between the two compression types. Choice B is incorrect because it reverses the typical outcomes - lossy compression generally achieves smaller files than lossless, and Choice C incorrectly assigns specific file types to each method when both can be used for various data types. To help students: Create comparison charts showing the characteristics of each compression type. Emphasize that the key difference is whether original data can be perfectly reconstructed after decompression.
  16. Which of the following scenarios describes a situation where lossy compression would be the most acceptable choice?
    Answer: Compressing an audio file for streaming on a music service where bandwidth is a concern. Lossy compression is most acceptable for media like music and video, where small amounts of data can be discarded without significantly impacting the user's experience. For text, medical records, and source code, any data loss would corrupt the information, making lossless compression essential.
  17. Read the passage. In a streaming service, compression shrinks data so videos load quickly and use less bandwidth. The text explains that lossless compression preserves every bit of information, while lossy compression removes some details to achieve smaller files. For digital media, JPEG commonly compresses photos by discarding subtle image data, and MPEG commonly compresses video by reducing repeated or less-noticeable visual information across frames. This creates a trade-off: smaller files and smoother streaming versus potential blur or blocky artifacts. In contrast, text and program files often use lossless methods such as Huffman coding and LZW, since even a missing character can change meaning. Based on the text, how does MPEG differ from JPEG?
    Answer: MPEG targets video; JPEG targets still images. This question tests AP Computer Science Principles skills in understanding data compression, specifically differentiating between MPEG and JPEG compression standards. Data compression standards are optimized for different types of media, with JPEG designed for still images and MPEG for video sequences that can exploit temporal redundancy. The passage clearly distinguishes these: 'JPEG commonly compresses photos by discarding subtle image data, and MPEG commonly compresses video by reducing repeated or less-noticeable visual information across frames.' Choice A is correct because it accurately identifies the fundamental difference: MPEG is designed for video compression (exploiting similarities across frames), while JPEG is designed for still image compression. Choice B incorrectly identifies both as lossless methods when the passage clearly describes them as lossy, and Choice D makes false claims about file size increases. To help students: Create visual diagrams showing how JPEG works on single images versus how MPEG exploits redundancy across video frames. Emphasize that both are lossy but optimized for different media types.
  18. An e-commerce website displays small thumbnail images of products in its catalog. To ensure the catalog page loads as quickly as possible, which is the most appropriate strategy for handling these thumbnails?
    Answer: Use lossy compression, because a small reduction in the quality of a thumbnail is an acceptable trade-off for faster page loading. For preview images like thumbnails, the primary goal is fast delivery. A slight loss of quality is generally unnoticeable at such a small size and is a worthwhile trade-off for the significant reduction in file size and consequently faster page load times, which improves user experience.
  19. Which statement accurately describes a key characteristic of lossy compression?
    Answer: It is an irreversible process because the compression algorithm permanently removes some of the original data. The core principle of lossy compression is the permanent removal of data. This makes the process irreversible; once the data is discarded to reduce file size, it cannot be recovered. This is in direct contrast to lossless compression, which is a reversible process.
  20. A user repeatedly edits and saves a digital photo using a JPEG format, which is a lossy compression scheme. What is the most likely outcome for the image after many cycles of editing and saving?
    Answer: The image quality will progressively degrade because each save operation discards more data. This phenomenon is known as generation loss. Each time an image is saved in a lossy format, the compression algorithm is applied again, and more data is discarded. This loss is cumulative, leading to a noticeable degradation of quality after several save cycles.

Start this quiz