Quiz 2
Registry Synced

computationalthinking-week1

701 words
4 min read

Reading compass

Now · Week map

CT week 1 builds representations: naming quantities, picking datatypes, and tracing state through flowcharts or pseudocode.

Week map

Problem → variables as named state → datatypes → iterators → flowchart symbols → state snapshots → input/output boxes.

Representation notation

  • Variable → name bound to a value that may change → count, total, name.
  • State → all current variable values at one instant → snapshot table one row per step.
  • Iterator → variable stepping through a sequence or count → i from 0 to n-1.
  • Datatype → kind of value → determines legal operations → number vs string vs list.

Flowchart symbols

ShapeRoleExample action
Ovalstart / endStart, Stop
Rectangleprocesstotal ← total + price
Diamonddecisionscore ≥ 50?
Parallelograminput / outputRead age, Print sum
Arrow direction defines order. At a diamond, follow one branch label (Y/N or T/F).

Choosing a representation

Ask three questions:
  1. Single vs collection? One score → number; list of scores → list.
  2. Fraction allowed? Integer count vs float average.
  3. Text vs number? ID as string even if digits; phone codes not for arithmetic.
Mini-example: Track 5 quiz scores → list scores length 5, not five unrelated names unless table fixed.

State snapshot tracing

Problem: start x=3, y=1. Process: y ← x + y, then x ← y - 2.
stepxy
init31
after 1st34
after 2nd24
Read as: assignment uses current values when evaluating right-hand side.

Pattern families

Easy — Read flowchart step

  • Follow arrows; update rectangles; branch at diamond once.
  • Identify start/end and missing arrow bugs in diagrams.
  • Match parallelogram to Read/Print in trace.

Medium — Choose datatype and names

  • From word problem, list variables and types.
  • Distinguish index (position) vs value at index.
  • Flowchart with two variables swapping — track both columns.

Hard — Full state table

  • Multi-step with decision: duplicate row only along taken branch.
  • Iterator introduced mid-flow: when does i increment?
  • Detect unreachable rectangle (no arrow in).

Worked mini-examples

Example 1 — Simple trace.
Start a=10, b=2. a ← a - ba=8. b ← a + bb=10.
Example 2 — Decision.
n=7. Diamond: n > 5? Yes → msg ← "big". Else branch skipped. msg is "big".
Example 3 — Iterator intro.
i=0, sum=0. Loop body: sum ← sum + i, i ← i + 1, repeat while i < 4.
isum after step
00
10
21
33
46
Loop stops when i becomes 4.
Example 4 — Wrong type choice.
Storing price = "12.50" then total = price + 5 concatenates strings in Python-like semantics — representation error if numeric total intended.

Traps

  • Skipping decision branch label — both paths mentally.
  • Same name for two concepts (total for both count and sum).
  • Using value before rectangle that assigns it.
  • Iterator confused with stored data value (i vs item[i]).
  • Flowchart arrow bypassing update rectangle.

Diagnostic (try yourself)

  1. Start p=5, q=3. Execute p ← p + q then q ← p - q. What are final p and q?
  2. A flowchart diamond asks x < 0. If x = 0, which branch (Y/N) is taken for “less than zero”?
  3. You need to store a student’s 8 weekly quiz percentages. One variable or a collection? Which datatype class?
  4. Trace c=1, d=4, then c ← d, d ← c. What are c and d? (Watch order.)
  5. In a state table, why duplicate rows only on the taken branch after a decision?
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.