AP Computer Science Principles · Unit 2 lecture · Part 11 of 11 · 6 min

Unit 2 wrap-upPut it together

Mr. Thompkins
That's Big Idea 2, 17 to 22 percent of the multiple choice. It started with a single bit and ended with programs that find patterns in millions of records. Let's tie it into one story.

Everything in a computer is bits, and bits mean whatever the program says they mean (2.1). Fixed numbers of bits limit what can be stored, which causes overflow and round-off, and analog data must be sampled to be stored at all. Those bits take space, so we compress them, losslessly when every bit matters and lossily when size matters most (2.2). Collected data becomes information only if we clean it, read its metadata, and resist claiming causes or ignoring bias (2.3). Programs do the heavy lifting by filtering, transforming, combining and visualizing (2.4).

TopicBig ideaMost tested skill
2.1 Binary numbersEverything is bits; n bits give 2ⁿ valuesConvert, count bits, spot overflow and round-off
2.1 Analog dataSampling approximates smooth signalsMore samples: closer copy, bigger file
2.2 CompressionFewer bits for the same (or nearly the same) dataChoose lossless or lossy for a situation
2.3 Extracting informationData needs cleaning, context and careMetadata, correlation vs causation, bias
2.4 Programs with dataFilter, transform, combine, visualizeTrace a program that processes a list
Unit 2 on one page.
?Wait, what's the formula for how many values n bits hold?
2ⁿ patterns. As whole numbers starting at 0, that's 0 to 2ⁿ - 1. Add one bit and the count doubles.
?Wait, overflow or round-off?
Overflow: a whole number too big for its fixed number of bits. Round-off: a real number that can only be stored approximately. One is about size, the other about precision.
Pause and think
Connect two topics: why might lossy compression be a bad idea for a data set you plan to analyze for correlations?
I thought about it. Show me
Lossy compression changes the values slightly and permanently. Small changes in many values could create or hide patterns, so analysis should start from exact data, compressed losslessly if at all.

Traps that cost points

✕ Reading binary from the wrong end.
✓ The rightmost bit is the ones place.
✕ Saying 8 bits hold values up to 256.
✓ 8 bits make 256 patterns: 0 to 255.
✕ Doubling the bits to double the values.
✓ Add one bit to double the number of values.
✕ Calling round-off an overflow.
✓ Overflow is too big; round-off is an approximation of a real number.
✕ Assuming exam pseudocode overflows.
✓ Integers on the reference sheet are limited only by memory.
✕ Choosing lossy for text, code or financial data.
✓ If it must come back exactly, use lossless.
✕ Thinking compression always shrinks a file.
✓ Savings depend on redundancy. Data with no repeats may not shrink.
✕ Claiming one variable causes another from data alone.
✓ Correlation is not causation; look for a third factor.
✕ Thinking more data removes bias.
✓ Bias comes from the source; more of the same data keeps it.
✕ Thinking changing metadata changes the file's content.
✓ Metadata describe the data. Changing them leaves the data alone.

Key facts for Unit 2

n bits → 2ⁿ patterns
Values 0 to 2ⁿ - 1Minimum bits: smallest n with 2ⁿ ≥ items
10110₂ = 16 + 4 + 2 = 22
Binary to decimalAdd the place values under each 1
8 bits = 1 byte
256 values24-bit color: 16,777,216 colors
samples/s × seconds × bits × channels
Size of a sampled recordingDivide by 8 for bytes
Lossless
Exact reconstructionText, code, spreadsheets, records
Lossy
Approximate, much smallerStreaming, photos, music
Metadata
Data about dataFind, organize, manage
Filter / transform / combine
IF and APPEND / APPEND a changed copy / one resultPrograms with data

Strategy for Unit 2 questions

  1. Binary: label the place values first, every time. Compare numbers only after converting them to the same base.
  2. Bits: use the powers of 2 list. Remember the "minus 1" for the largest value.
  3. Compression: find the phrase that says whether exactness or size matters most.
  4. Data conclusions: the right answer usually says "correlated, but more investigation is needed" or "still biased".
  5. Data programs: trace with a table, then name the process (filter, transform, combine).
Mixed practice
A weather station records temperature as an 8-bit whole number from 0 to 255 every 10 minutes and uploads a file each day with the station name and date. (a) How many readings per day? (b) Is the station name data or metadata? (c) A reading of 300 arrives. What problem is this, and what happens in many systems? (d) Should the station compress its archive with lossy or lossless compression, and why?
  1. (a) 24 hours × 6 readings per hour = 144 readings per day.
  2. (b) Metadata: it describes the file, not the temperature readings themselves.
  3. (c) 300 is outside 0 to 255, an overflow error. In many systems the extra bit is dropped and 300 - 256 = 44 is stored, a wrong reading.
    Why?
    This is also a reason to validate data when cleaning it.
  4. (d) Lossless: scientists may analyze exact values for trends years later, and lossy changes can't be undone.

Answer: (a) 144. (b) Metadata. (c) Overflow; it might be stored as 44. (d) Lossless, because exact values matter for later analysis.

Stuck? Get a hint
  1. How many 10-minute periods are in an hour?
  2. Does the station name describe the data or is it the data?
  3. What is the largest value 8 bits hold?
Check yourself
A system stores each pixel's brightness using 6 bits. How many different brightness levels can it represent?
  1. A6
  2. B12
  3. C36
  4. D64
Show the answer

D. 6 bits make 2⁶ = 64 patterns, so 64 levels (0 to 63). 36 is 6², the classic mix-up between 2⁶ and 6².

Check yourself
A school finds that students with more library visits have higher reading scores. Which TWO statements are best supported? I. The data shows a correlation. II. Library visits cause higher scores. III. More research is needed to know whether one causes the other. IV. The data proves that students with high scores visit the library more.
  1. AI and III
  2. BI and II
  3. CII and IV
  4. DIII and IV
Show the answer

A. The data shows a correlation (I), and claiming a cause needs more investigation (III). II and IV each claim more than correlation can support: "cause" and "proves" are the warning words.

Mr. Thompkins
That's Unit 2. Take the Unit 2 quiz, and practice binary conversions until they're automatic: they're free points. Next up is Unit 3, the biggest unit on the exam, where you'll learn to read and write the pseudocode yourself.