CS I · Tue Oct 27 · 13.2 · Do Now

Trace Tables

  • Terminology and concepts to look out for: trace table · column · row
  • Relevance to me: Yesterday you traced short steps on the Store It bench, and most of them were easy to follow in your head. Today the steps get longer, and you build the tool that keeps track of them for you.
  • Board Question: When you follow a list of steps in your head, how many changing numbers can you keep straight at the same time? Give a number, and say what you would do if there were more than that.

Open the I Do form on the right and answer Section 1 from your first reading.

Discussion form

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

I Do questions
  1. notebook cue: trace table

    In your own words, what does a trace table keep track of, and why is it on paper instead of in your head?

    Check

    A trace table keeps track of what every box holds after each line runs. It is on paper because working memory holds only a few items, and the table lets the reader look a value up instead of remembering it. See The Trace Table, paragraph 1, and A Small Space for Remembering.

  2. notebook cue: column

    Which names in a snippet get a column in the trace table?

    Check

    Every name the code stores a value in, which is every name on the left of an arrow, plus a shown column if the code shows anything. The line number gets a column on the left. See The Trace Table, paragraph 2.

  3. notebook cue: row

    How many rows does a trace table need, and when will that number be bigger than the number of lines of code?

    Check

    One row for each line that runs. With no loops every line runs once, so the rows equal the lines. When the class meets loops, a line that runs again gets another row. See Why the Habit Matters, paragraph 2.

Announcements

Tracing Code by Hand

1 This section explains why people who read code keep track of its values on paper, and how a trace table does that work.

What the Class Has Practiced

2 Yesterday, the class learned that a program stores values in boxes. Each store step works out its right side and then replaces the old value in the box on the left. On the Store It bench, every snippet was two to five lines long and used one to three boxes. Snippets that short can be followed without writing anything down, and many students did exactly that.

A Small Space for Remembering

3 Psychologists use the term working memory for the small amount of information a person can hold in mind while using it. In 1956, the psychologist George Miller published a well-known paper arguing that people can hold about seven items, plus or minus two, in immediate memory. In 2001, Nelson Cowan reviewed many later studies and concluded that the limit is smaller, about four chunks, when people cannot repeat the items to themselves or group them. A chunk is a group of items that the mind treats as one unit, such as a familiar word instead of its separate letters.

4 Tracing code in the head uses this small space. A person following a snippet must remember which line comes next, the current value of every box, and the result of the step being worked. With two boxes and three lines, that fits, which is why short snippets feel easy. With four boxes that each change several times, the list is longer than working memory can hold, and old values begin to blur with new ones. The mistakes that follow are predictable. A value that was replaced gets used again, or a box that never changed gets a new value by accident.

The Trace Table

5 A trace table moves that work out of memory and onto paper. It is a grid with one column for each box and one row for each step of the code. Each row records one line that runs, and the values in that row are what every box holds right after the line runs. Because each row stays on the page, the person tracing can look up any value instead of remembering it, and a partner or teacher can check the work one row at a time. Teachers sometimes call this "running the code with your fingers," because one finger moves down the code one line at a time while the pencil records what the computer would store.

6 The table starts with its header row, and building the header is part of the method. Before tracing any line, the reader scans the code for every name that appears on the left of an arrow and gives each one a column. A column for the line number goes on the left, and a column for anything the code shows goes on the right. A name that is stored many times still gets only one column, because it is one box. Building the header shows how much there is to keep track of before the work begins. Figure 1 shows a finished trace table for four lines of code, with its header row at the top and one row below it for each line that ran.

Why the Habit Matters

7 Researchers who have studied the scratch paper of beginning programmers report that students who wrote out the values of variables as they traced tended to answer tracing questions correctly more often than students who wrote nothing. With the table doing the remembering, the reader can put full attention on working out each step. Tracing is also a skill on the AP Computer Science A exam, where many questions show a code segment and ask what it prints or what a variable holds, and students answer without running the code.

8 The snippets will not stay short. Soon the class will meet loops, in which the same lines run again and again. A trace table then needs one row for every line that runs, not one row for every line that is written, so a loop of three lines that runs four times fills twelve rows. A reader who builds the habit on short snippets will be ready when the snippets get long.

Summary

9 Working memory holds only a few items at once, so tracing long code in the head leads to mistakes. A trace table gives each box a column and each line that runs a row, which turns memory work into reading work.

Sources: Miller, Psychological Review (1956); Cowan, Behavioral and Brain Sciences (2001); Lister and others, ITiCSE Working Group Reports (2004); Cunningham and others, ICER (2017); College Board, AP Computer Science A Course and Exam Description (2025); Store It reading, class site (2026).

Discussion form

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

I Do questions
  1. notebook cue: trace table

    In your own words, what does a trace table keep track of, and why is it on paper instead of in your head?

    Check

    A trace table keeps track of what every box holds after each line runs. It is on paper because working memory holds only a few items, and the table lets the reader look a value up instead of remembering it. See The Trace Table, paragraph 1, and A Small Space for Remembering.

  2. notebook cue: column

    Which names in a snippet get a column in the trace table?

    Check

    Every name the code stores a value in, which is every name on the left of an arrow, plus a shown column if the code shows anything. The line number gets a column on the left. See The Trace Table, paragraph 2.

  3. notebook cue: row

    How many rows does a trace table need, and when will that number be bigger than the number of lines of code?

    Check

    One row for each line that runs. With no loops every line runs once, so the rows equal the lines. When the class meets loops, a line that runs again gets another row. See Why the Habit Matters, paragraph 2.

Figure 1. A trace table for four lines of code. The header row has a column for the line, one for each box the code stores a value in, and one for what is shown; each line that runs gets its own row.

The big picture so far (newest on top)

Big picture 5 of 5. What you can reach. The AI tool sits inside its walls from Big picture 4. You can reach past them to a library card's databases, Look It Up stations, archives, books on the shelf and librarians, each with a real catch.
Big picture 4 of 5. Walls you can't see. Around the chain from Big picture 3 sit three walls: sources behind a login that the search can't open, a training gap shaped by crawler blocks and licensing deals, and policy rules that can look like missing information.
Big picture 3 of 5. Generation and retrieval. In Google's AI Mode, Lens reads the image, Search fetches pages from the open web (retrieval), and Gemini writes the answer from its squeezed chunk (generation), with links back to the pages.
Big picture 2 of 5. The song ladder. On each rung the gaps get bigger and less is really known, but the model sings every rung in the same confident voice. On rung 4 a word gets "picked anyway," which people call a hallucination.
Big picture 1 of 5 (from 12.2). Training squeezes one chunk of the internet into a much smaller parameters file and loses details; probability fills the gaps when the model is used.
Discussion form

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

I Do questions
  1. notebook cue: trace table

    In your own words, what does a trace table keep track of, and why is it on paper instead of in your head?

    Check

    A trace table keeps track of what every box holds after each line runs. It is on paper because working memory holds only a few items, and the table lets the reader look a value up instead of remembering it. See The Trace Table, paragraph 1, and A Small Space for Remembering.

  2. notebook cue: column

    Which names in a snippet get a column in the trace table?

    Check

    Every name the code stores a value in, which is every name on the left of an arrow, plus a shown column if the code shows anything. The line number gets a column on the left. See The Trace Table, paragraph 2.

  3. notebook cue: row

    How many rows does a trace table need, and when will that number be bigger than the number of lines of code?

    Check

    One row for each line that runs. With no loops every line runs once, so the rows equal the lines. When the class meets loops, a line that runs again gets another row. See Why the Habit Matters, paragraph 2.

Tracing Code by Hand

1 This section explains why people who read code keep track of its values on paper, and how a trace table does that work.

What the Class Has Practiced

2 Yesterday, the class learned that a program stores values in boxes. Each store step works out its right side and then replaces the old value in the box on the left. On the Store It bench, every snippet was two to five lines long and used one to three boxes. Snippets that short can be followed without writing anything down, and many students did exactly that.

A Small Space for Remembering

3 Psychologists use the term working memory for the small amount of information a person can hold in mind while using it. In 1956, the psychologist George Miller published a well-known paper arguing that people can hold about seven items, plus or minus two, in immediate memory. In 2001, Nelson Cowan reviewed many later studies and concluded that the limit is smaller, about four chunks, when people cannot repeat the items to themselves or group them. A chunk is a group of items that the mind treats as one unit, such as a familiar word instead of its separate letters.

4 Tracing code in the head uses this small space. A person following a snippet must remember which line comes next, the current value of every box, and the result of the step being worked. With two boxes and three lines, that fits, which is why short snippets feel easy. With four boxes that each change several times, the list is longer than working memory can hold, and old values begin to blur with new ones. The mistakes that follow are predictable. A value that was replaced gets used again, or a box that never changed gets a new value by accident.

The Trace Table

5 A trace table moves that work out of memory and onto paper. It is a grid with one column for each box and one row for each step of the code. Each row records one line that runs, and the values in that row are what every box holds right after the line runs. Because each row stays on the page, the person tracing can look up any value instead of remembering it, and a partner or teacher can check the work one row at a time. Teachers sometimes call this "running the code with your fingers," because one finger moves down the code one line at a time while the pencil records what the computer would store.

6 The table starts with its header row, and building the header is part of the method. Before tracing any line, the reader scans the code for every name that appears on the left of an arrow and gives each one a column. A column for the line number goes on the left, and a column for anything the code shows goes on the right. A name that is stored many times still gets only one column, because it is one box. Building the header shows how much there is to keep track of before the work begins. Figure 1 shows a finished trace table for four lines of code, with its header row at the top and one row below it for each line that ran.

Why the Habit Matters

7 Researchers who have studied the scratch paper of beginning programmers report that students who wrote out the values of variables as they traced tended to answer tracing questions correctly more often than students who wrote nothing. With the table doing the remembering, the reader can put full attention on working out each step. Tracing is also a skill on the AP Computer Science A exam, where many questions show a code segment and ask what it prints or what a variable holds, and students answer without running the code.

8 The snippets will not stay short. Soon the class will meet loops, in which the same lines run again and again. A trace table then needs one row for every line that runs, not one row for every line that is written, so a loop of three lines that runs four times fills twelve rows. A reader who builds the habit on short snippets will be ready when the snippets get long.

Summary

9 Working memory holds only a few items at once, so tracing long code in the head leads to mistakes. A trace table gives each box a column and each line that runs a row, which turns memory work into reading work.

Sources: Miller, Psychological Review (1956); Cowan, Behavioral and Brain Sciences (2001); Lister and others, ITiCSE Working Group Reports (2004); Cunningham and others, ICER (2017); College Board, AP Computer Science A Course and Exam Description (2025); Store It reading, class site (2026).

Table Talk

Revisit your response to the Board Question.

Discuss with your table or partner if possible.

When you follow a list of steps in your head, how many changing numbers can you keep straight at the same time? Give a number, and say what you would do if there were more than that.

Chromebooks stay closed while you talk. Then answer Section 3 of the I Do form right here under My View and submit it. This is the last time you answer today's Board Question.

Sign out of Google when you finish on a shared computer, so the next student can sign in as themselves. Google then shows a "Redirect notice" page. Click the muggsofcompsci.net/cs1 link on it to come back.

This form has three sections. Section 1: your first answer to the Board Question. Section 2: nine reading questions on the passage, like the ACT. Section 3: the Board Question one last time, at the end of the I Do.

CR 1. Board Question: When you follow a list of steps in your head, how many changing numbers can you keep straight at the same time? Give a number, and say what you would do if there were more than that. Give your answer and one reason.

Write your answer in your lab notebook, labeled CR 1.

MC 1. The main purpose of the passage is to:

  • compare Miller's and Cowan's careers as psychologists.
  • argue that students should stop using computers to run their code.
  • explain why following code in the head leads to mistakes as code grows, and how a trace table moves that work onto paper.
  • teach readers how loops work in Java.

MC 2. According to paragraph 3, Cowan concluded that when people cannot repeat or group items, working memory holds about:

  • four chunks.
  • seven items, plus or minus two.
  • as many items as the person needs.
  • one item at a time.

MC 3. As it is used in paragraph 4 ("old values begin to blur with new ones"), the word blur most nearly means:

  • move faster.
  • get erased by the computer.
  • become larger numbers.
  • become hard to tell apart.

MC 4. The author most likely mentions that every Store It snippet was two to five lines long in order to:

  • explain how many rows a loop needs.
  • show why students could follow those snippets without writing anything down.
  • prove that the Store It bench was too easy to be useful.
  • compare the Store It bench with the AP exam.

MC 5. Based on paragraph 8, a loop of two lines runs five times. How many rows does its part of the trace table need?

  • 2
  • 5
  • 7
  • 10

MC 6. According to paragraph 6, what does the reader do before tracing any line?

  • run the code on a computer to see the result
  • check the last row of the table against the answer
  • fill in the shown column with what the code prints
  • scan the code for every name on the left of an arrow and give each one a column

MC 7. According to paragraph 4, why do mistakes appear when four boxes each change several times?

  • The trace table has too many columns to read.
  • The arrows in the code point the wrong way.
  • The values to remember are more than working memory can hold.
  • The computer stores the wrong value in a box.

MC 8. How does Cowan's estimate in paragraph 3 compare with Miller's?

  • Cowan's limit is smaller: about four chunks instead of about seven items.
  • The two estimates are the same.
  • Cowan found that working memory has no limit.
  • Cowan's limit is larger: about seven chunks instead of about four items.

MC 9. Which statement from the passage best supports the claim that a trace table "turns memory work into reading work"?

  • Soon the class will meet loops, in which the same lines run again and again.
  • Because each row stays on the page, the person tracing can look up any value instead of remembering it.
  • Yesterday, the class learned that a program stores values in boxes.
  • A chunk is a group of items that the mind treats as one unit.

CR 2. Revisit your response to the Board Question. Discuss with your table or partner if possible. When you follow a list of steps in your head, how many changing numbers can you keep straight at the same time? Give a number, and say what you would do if there were more than that. Give your answer now. Did it stay the same or change? Say what from the reading or your discussion made it stay or change.

Write your answer in your lab notebook, labeled CR 2.