Lecture 11 — Lists and Slicing

Position in the course

This is lecture 11 of 32. It belongs to the course arc described in the course outline and uses the standard interactive case method: display, attempt (5 minutes), discuss, reveal, name the technique.

This lecture runs as a workshop session (build-heavy; see the timing plan), not the standard four-case rhythm.

Learning objectives

By the end of this lecture students can do all three under time pressure, which is what the four cases exercise.

Prerequisite knowledge

Before this lecture: Lectures 09–10 — Iteration patterns and strings

Assumed fluencies:

Preparation task: Predict-then-run: three slice expressions of your own making.

Detailed topic outline

Core (mandatory):

  1. list operations and slicing views
  2. aliasing versus copying
  3. in-place mutation
  4. rotation and reorder patterns

Extension (optional enrichment):

  1. lists of records
  2. shared references as a debugging skill

Case sequence

CaseTitleDifficulty
cs-041The Queue ReorderBeginner
cs-042Deduplication PatternsFoundational
cs-043Rotate and RollIntermediate
cs-044The Aliasing TrapAdvanced

Display each case full-screen from the student page (cases cs-041–cs-044); instructor pages cs-041–cs-044 under case-studies/instructor/ hold the full solutions, reveal guides, and discussion prompts.

Timing plan (120 minutes)

Format: workshop session — deliberately not the standard case rhythm.

MinutesSegment
0–10Framing: the two patterns this workshop trains
10–45Cases 1–2 (cs-041, cs-042): two 5-minute attempts back to back, one joint discussion, two reveals
45–50Break
50–90Cases 3–4 (cs-043, cs-044): same double rhythm, harder material
90–110Deliberate-practice block: build or trace one of today's patterns end to end, instructor circulating
110–120Synthesis, exit questions, homework

Timing flexes with the room: if a case ignites the class, let the discussion run and compress the synthesis; if the attempts stall, harvest partial attempts rather than extending the clock.

Worked examples

Instructor demonstration to open the lecture: Draw the queue-reorder slices (cs-041) as boxes and arrows; then alias two names to one list and mutate, watching the class notice.

Classroom activities

#ActivityMinutesFormat and prompt
1Aliasing diagrams8Pairs draw memory diagrams for four list statements, two of which alias; find the corruption.
2Slice prediction quiz5Ten slice expressions, ten seconds each, answers revealed immediately.
3Human array rotation6Twelve students are an array; two rotation algorithms are executed with physical moves.

Board plan

Instructor explanation notes

Reading the room. Aliasing is the lecture's deep idea and the term's best debugging gift. Memory diagrams are mandatory for cs-044; students who skip them will rediscover the trap in the project.

Running the reveal. Workshop format: keep builds short and predictions public.

Lecture focus. One sentence to repeat verbatim: Assignment binds a name; it rarely copies a list.

Common misconceptions

Each case's instructor page lists the specific wrong turn to expect; the reveal should address it by name.

Student practice exercises

Core:

  1. Draw memory diagrams for assignment, copy, and alias of a 3-element list.
  2. Rotate cs-043's queue by k with slicing, then without any slicing.
  3. Predict-then-run five provided aliasing statements; keep score honestly.

Enrichment (optional):

Formative assessment

Exit questions (choose one; answer on a card in 60 seconds):

  1. What is the difference between a = b and a = b[:] for lists? Expected: the first aliases (one object, two names), the second copies
  1. Give the slice for the last three items and for every second item. Expected: lst[-3:] and lst[::2]
  1. Why did the roster corrupt in cs-044? Expected: two names referenced one list; an 'append' to one mutated the other

Cards are skimmed before the next lecture; three answers become the framing. Persistent wrong answers route students to the review stations of lecture 16 or to office hours.

Homework and preparation

Learning-outcome mapping

Differentiation