Back

Activity 2.22: Quarter 2 Review

divider

Activity 2.22

Quarter 2 Review

What This Quarter Was

Before the list appears: name the three big ideas this quarter was built from.

Value Trace
QUARTER 1 gave you the pieces.
input, variables, decisions, loops, arrays
QUARTER 2 gave you three ways to think about them.

What This Quarter Was

Value Trace
QUARTER 1 gave you the pieces.
input, variables, decisions, loops, arrays
QUARTER 2 gave you three ways to think about them.
ABSTRACTION package it up and stop looking inside
ALGORITHMS two correct answers can cost differently
DATA the number is not the same as the truth

Abstraction: Write It Once, Then Stop Looking Inside

A method with a parameter lets you name a job and stop thinking about how it is done. Scope is what makes that safe: a method can see the main program's variables, and nothing outside can see the method's own.

And you built two projects on it. Build 1 taught you how big a thing you can make; Build 2, how to keep one going for days.

Algorithms: Correct Is Only the Start

Linear search never fails. Binary search is far faster, and it needs sorted data. Selection sort takes about four times as long when the list doubles.

Polynomial time or lower is reasonable; exponential or factorial is not. When a problem is too slow to solve exactly, a heuristic gets close. And some problems are undecidable: no algorithm can answer them for every input.

Data: The Number Is Not the Truth

Bits mean nothing until a program says what they are. A fixed number of them has limits: overflow, round-off, and what sampling misses.

Compression trades size against exactness. And information is something you extract from data, after you have cleaned it, questioned where it came from, and decided how to show it.

But Here Is the Thread

Five activities, five different topics. What do they have in common?

Value Trace
THE PATTERN THIS QUARTER KEPT MAKING
2.10 a correct search, a wrong answer, no error
2.14 the same bits, four different meanings
2.16 every sample measured right, the shape lost
2.18 every record accurate, the conclusion biased
2.20 every bar true, the impression false

But Here Is the Thread

Value Trace
THE PATTERN THIS QUARTER KEPT MAKING
2.10 a correct search, a wrong answer, no error
2.14 the same bits, four different meanings
2.16 every sample measured right, the shape lost
2.18 every record accurate, the conclusion biased
2.20 every bar true, the impression false
Correct is not the same as right.

Every one of those produced accurate output, and every one could mislead somebody. That is the most useful idea in the quarter, and it is not on the reference sheet.

This Was Half the Exam

Algorithms and Programming is 30–35% of the multiple choice. Data is 17–22%.

Between them, roughly half the paper. That was this quarter.

Today

Six traces. Then the checklist. Then the checkpoint.

Then the gallery walk: you run your Build 2 program for everybody.

'F' → Fullscreen

divider

The Exam Notation, Assembled

Everything you have met, on one card. You get this sheet on exam day and it is collected afterward. Read it before the traces.

Exam Reference Sheet, Condensed
a ← expression assign a COPY of the result
aList ← bList assigns a COPY of the list
DISPLAY(expression) show it, FOLLOWED BY A SPACE
= ≠ > < ≥ ≤ comparison. = means EQUALS
aList[1] THE FIRST ELEMENT
LENGTH(aList) how many
INSERT(aList, i, value) shift right, place at i
APPEND(aList, value) place at the end
REMOVE(aList, i) remove and shift left
a MOD b remainder
a / b TRUE division. 17 / 5 is 3.4
there is no rounding operator
REPEAT n TIMES { } no loop counter is provided
REPEAT UNTIL(cond) { } repeats UNTIL it becomes true
FOR EACH item IN aList { }
IF(cond) { } ELSE { } the only two selection forms
PROCEDURE name(p1, p2)
{
RETURN(expression) hands back AND exits immediately
}
result ← name(a, b)

Three things on that card cost more marks than the rest put together:

  • DISPLAY prints a space after every value, so two calls in a row give space-separated output on one line. Console.WriteLine starts a new line instead.
  • Lists start at 1. Every index answer is one higher than the C# one.
  • aList ← bList makes a copy. In C#, int[] aList = bList; does not: both names point at the same array, and the same program gives different answers in the two notations.
divider

Warm-Up: Six Traces

On paper. Do not run anything. Four are C# and two are exam notation, and they are not in the order you might expect. Check which one you are in before you answer.


Trace 1 — C#

What does this print?

Trace 1
int size = 10;
Console.WriteLine(Grow(size));
Console.WriteLine(size);
int Grow(int size)
{
size = size * 2;
return size;
}

Trace 2 — C#

Three numbers. Make a table of low, high, mid and checks for the first call before you answer.

Trace 2
int[] ids = { 3, 8, 15, 22, 30, 41, 56 };
Console.WriteLine(Find(22));
Console.WriteLine(Find(3));
Console.WriteLine(Find(7));
int Find(int target)
{
int low = 0;
int high = ids.Length - 1;
int checks = 0;
while (low <= high)
{
int mid = (low + high) / 2;
checks = checks + 1;
if (ids[mid] == target)
{
return checks;
}
if (ids[mid] < target)
{
low = mid + 1;
}
else
{
high = mid - 1;
}
}
return -1;
}

Then answer: one of these is found in a single check. Say why that value, without the word “luck.”


Trace 3 — Exam Notation

What does this display? Every character, including spaces.

Trace 3
PROCEDURE label(n)
{
IF(n MOD 2 = 0)
{
RETURN("even")
}
RETURN("odd")
}
aList ← [4, 7, 10]
FOR EACH item IN aList
{
DISPLAY(label(item))
}

Then answer: there is no ELSE, and the procedure still always returns exactly one value. Explain why.


Trace 4 — C#

What does this print?

Trace 4
int steps = 0;
int n = 6;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
steps = steps + 1;
}
}
Console.WriteLine(steps);

Then answer: you met this number this quarter, attached to an algorithm on a list of the same length. Which one, and why is that not a coincidence?


Trace 5 — Exam Notation

What does this display?

Trace 5
bList ← [2, 4, 6]
aList ← bList
aList[2] ← 99
FOR EACH item IN aList
{
DISPLAY(item)
}
FOR EACH item IN bList
{
DISPLAY(item)
}

Then answer: write the same thing in C# with int[] aList = bList; and aList[1] = 99;, and work out what it prints. The answers differ. Say which one the exam expects.


Trace 6 — C#

Two bytes stored back to back in one array, one bit per position. What does this print?

Trace 6
int[] bits = { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 };
Console.WriteLine(ToDecimal(0));
Console.WriteLine(ToDecimal(8));
int ToDecimal(int start)
{
int total = 0;
int place = 1;
for (int i = start + 7; i >= start; i--)
{
if (bits[i] == 1)
{
total = total + place;
}
place = place * 2;
}
return total;
}

Then answer: the second number is a power of 2. Say how you can tell from the bits alone, without adding anything up.

divider

Before the Checkpoint

Go down this list and mark anything you cannot do without looking it up. Whatever you mark is your revision, and nothing else is worth spending time on.

Abstraction

  • Write a method with two parameters and a return value
  • Predict what a parameter with the same name as an outer variable does to that variable
  • Say why a method can see the main program's variables, but the main program cannot see the method's
  • Name a method in your own code that would count as student-developed, and something that would not

Algorithms

  • Trace a linear search and give its worst case for a list of n
  • Trace a binary search and count the comparisons
  • Say what binary search requires, and what happens without it
  • Count how many times a statement inside nested loops runs
  • Say what makes a running time reasonable rather than unreasonable
  • Define an undecidable problem, and a heuristic
  • Tell a decision problem from an optimization problem

Data

  • Convert decimal to binary and back
  • Compare and order binary numbers
  • Say why the same byte can be a number, a letter, or a color
  • Explain overflow and round-off, and say how they differ
  • Describe sampling, and say what too low a rate loses
  • Calculate a compression ratio; choose lossless or lossy for a situation
  • Say what metadata is for, and what changing it does not change
  • Explain why a correlation does not establish a cause
  • Explain why collecting more data does not remove bias

Notation

  • Translate a while loop into REPEAT UNTIL
  • Give the output of two DISPLAY calls in a row, spaces included
  • Convert a C# index into the exam's, which starts at 1
  • State what aList ← bList does, and what C#'s int[] aList = bList; does instead
divider

The Checkpoint

Same session, straight after this. 30 minutes, on paper, closed notes.

  • Exam format and exam pace. C# and exam notation mixed, with no warning about which is which.
  • Includes a select-all-that-apply question, with no partial credit for a partial answer.
  • Covers the whole quarter, weighted the way the exam is: algorithms heaviest, then data.
  • 40 points.

Then the gallery walk. Everybody runs their Build 2 program. Bring it working, or bring it broken and be able to say what broke.

divider

Reflection

Answer the following questions before submitting your work.

  1. You built two projects this quarter. What did Build 2 teach you that Build 1 could not have?
  2. Pick one of the five items in the correct is not the same as right list. Describe a situation outside this class where the same trap would matter.
  3. Quarter 3 opens with the Create task. Name the requirement you are least confident about, and what you will do about it before session 50.
divider

Submit

Your six trace answers with the follow-up questions, your marked checklist, and your three reflection answers.

Quarter Complete