← Home · Student guide · Schedule · Weeks · Pseudocode · Glossary
Mini-Quiz (6–8 min) — Week 3: Loops and Lists
- What is an analog signal and provide examples
- What is a digital signal and provide examples
Answer
- analog signals has values that change smoothly over time rather than in discrete intervals. Examples: Key Fob, radio waves, television waves, or sound waves
- digital signals are analog signals broken in to steps - examples CD, MP3, digital photo, digital electronics e.g. PIR sensor/voltage
- What is a Bit
Answer
Bit - A contraction of “Binary Digit”; the single unit of information in a computer, typically represented as a 0 or 1
- What is a byte
Answer
Byte - 8 bits
- What is binary, what is decimal
Answer
Binary - A way of representing information using only two options
Based on: traversal patterns (FOR EACH, REPEAT n TIMES), accumulation, list indexing (AP=1-based vs Python=0-based)
Instructions
- No notes. Show your reasoning. Time: 6–8 minutes.
- Trace a REPEAT loop What does the program display?
SET total ← 0
REPEAT 4 TIMES
SET total ← total + 3
END REPEAT
DISPLAY(total)
Answer
total: 0 → 3 → 6 → 9 → 12; output 12.
- FOR EACH traversal (count items meeting a condition) Complete the pseudocode to count how many numbers in L are even. Use FOR EACH.
# L ← [3, 6, 2, 5]
SET count ← 0
# your code here
DISPLAY(count)
Answer
FOR EACH x IN L
IF (x MOD 2 = 0)
SET count ← count + 1
END IF
END FOR EACH
DISPLAY(count) # 2
Reasoning: 6 and 2 are even → count=2.
- Indexing (AP pseudocode is 1-based) Given L ← [“A”,”B”,”C”,”D”], what does DISPLAY(L[2]) show?
Answer
“B” — AP pseudocode uses 1-based indexing (L[1]=”A”, L[2]=”B”).
- Accumulator pattern (sum of list) Write pseudocode to compute the sum of all values in L and DISPLAY the result.
Answer
SET sum ← 0
FOR EACH v IN L
SET sum ← sum + v
END FOR EACH
DISPLAY(sum)
Notes: Works for numeric L; for empty L, sum stays 0.
- REPEAT UNTIL vs WHILE (concept) In 1–2 sentences, explain the difference between REPEAT UNTIL condition and a WHILE condition loop in general terms.
Answer
REPEAT UNTIL runs the body at least once and stops when the condition becomes true. A typical WHILE loop checks the condition first and may run zero times. AP pseudocode uses REPEAT UNTIL to express post-condition loops.
Q1–Q4 aligned to: Unit 1 — Abstraction/Functions; AP Classroom AAP‑3.* (procedures/abstraction) and AAP‑2.* (lists); Barron’s Procedures/Parameters; Abstraction.
Q0. What is an abstraction in computer science?
Answer
An abstraction is a simplified representation of something complex that hides unnecessary details, allowing us to focus on high-level operations or ideas.
Q0b. Give an example of abstraction in programming.
Answer
Examples: Using a function to perform a task without knowing its internal code; variables representing data; using a map or list data structure without knowing how it is implemented.
Q0c. Why are abstractions important in computer science?
Answer
Abstractions help manage complexity, make code easier to read and maintain, and allow programmers to build on top of existing solutions without needing to understand every detail.
Q1. Convert the following binary number to decimal:
101101₂
Answer
101101₂ = 45₁₀
Q2. Convert the following decimal number to binary:
27₁₀
Answer
27₁₀ = 11011₂
Q3. What is the decimal value of the binary number 1110₂?
Answer
1110₂ = 14₁₀
Q4. Write the binary representation of the decimal number 19.
Answer
19₁₀ = 10011₂
Q5. (Short answer) Why is binary used in computers? (1–2 sentences)
Sample Answer
Computers use binary because digital circuits have two stable states (on/off, 1/0), making it reliable and easy to represent data and instructions
Q6. What is overflow in binary addition? Give an example.
Answer
Overflow occurs when the result of a binary addition is too large to fit in the available number of bits. For example, adding 1111₂ (15 in decimal) + 1₂ (1 in decimal) in 4 bits gives 10000₂, but only the last 4 bits (0000) are kept, so the result is 0 and the overflow is lost.
Q7. What happens when a number is too large to be stored in 8 bits?
Answer
The value wraps around and only the least significant 8 bits are kept. For example, 255 + 1 = 256, but in 8 bits, 256 is 100000000₂, so only 00000000₂ (0) is stored and the overflow is lost.
Q8. What is rounding error? Give an example with binary fractions.
Answer
Rounding error happens when a number cannot be exactly represented in binary, so it is rounded to the nearest value. For example, 0.1 in decimal cannot be exactly written in binary, so computers store an approximation, which can lead to small errors in calculations.
Q9. Why do computers sometimes give imprecise answers when adding decimals like 0.1 + 0.2?
Answer
Because numbers like 0.1 and 0.2 cannot be exactly represented in binary, their stored values are approximations. When added, the result may not be exactly 0.3 due to these small rounding errors.
Q10. What is lossless compression? Give an example.
Answer
Lossless compression reduces file size without losing any information. The original data can be perfectly reconstructed. Example: ZIP files, PNG images.
Q11. What is lossy compression? Give an example.
Answer
Lossy compression reduces file size by removing some data, resulting in a loss of quality. The original data cannot be perfectly restored. Example: JPEG images, MP3 audio.
Q12. What is the main trade-off between lossy and lossless compression?
Answer
Lossy compression achieves smaller file sizes but loses some information, while lossless keeps all information but may not compress as much.