Lecture 13 — Dictionaries and Sets

Position in the course

This is lecture 13 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.

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 and 11 — Aggregation and lists

Assumed fluencies:

Preparation task: Tally the words of one paragraph on paper, twice, faster.

Detailed topic outline

Core (mandatory):

  1. dictionaries as label → value maps
  2. counting and grouping patterns
  3. sets and membership
  4. set operations on rosters

Extension (optional enrichment):

  1. caches and last-seen maps
  2. voting and consensus logic

Case sequence

CaseTitleDifficulty
cs-049The Word TallyBeginner
cs-050Course RostersFoundational
cs-051The Cache SimulatorIntermediate
cs-132The Silent RosterIntermediate
cs-052The Consensus CheckerExpert

Display each case full-screen from the student page (cases cs-049–cs-052); instructor pages cs-049–cs-052 under case-studies/instructor/ hold the full solutions, reveal guides, and discussion prompts. Applied additions cs-132 extend the session as optional extra attempts or homework; they share the lecture's theme but teach an applied, real-world angle.

Timing plan (120 minutes)

MinutesSegment
0–10Framing: where this fits; recall of the previous lecture
10–30Case 1 (cs-049): 5-minute attempt, then discussion and reveal
30–50Case 2 (cs-050): same rhythm
50–70Case 3 (cs-051): same rhythm, harder case
70–75Break
75–100Case 4 (cs-052): same rhythm, hardest case
100–115Synthesis: name the techniques; misconceptions check
115–120Exit questions, homework, next-lecture preview

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: Build the word tally (cs-049) as a living table: one student reads words, one updates the map, one audits.

Classroom activities

#ActivityMinutesFormat and prompt
1Human dictionary6Words are read aloud; three students act as key, value, and updater of a living tally.
2Venn stations7Roster operations (union, intersection, difference) are performed with name cards at three stations.
3Consensus debate6cs-052's agreement rule is debated: majority, unanimity, or quorum — what does each hide?

Board plan

Instructor explanation notes

Reading the room. Dictionaries are introduced as 'lists with meaningful indices' — counting is the bridge. Sets arrive through roster questions where duplication is the enemy.

Running the reveal. The consensus case (cs-052) is a logic lecture in disguise; the table before the code is the whole lesson.

Lecture focus. One sentence to repeat verbatim: Choose the structure that answers the question directly.

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. Tally the words of a provided paragraph with a dictionary; print the top three by count.
  2. Compute roster intersections and differences for cs-050's three course lists.
  3. Build the agreement table for cs-052's four reviewers and decide the verdict.

Enrichment (optional):

Formative assessment

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

  1. When do you choose a dictionary over a list? Expected: when lookup is by meaningful key, not position
  1. What single operation do sets make O(1)-ish and lists O(n)? Expected: membership testing (in)
  1. Restate the consensus rule of cs-052 precisely. Expected: a decision passes only when agreement count meets the quorum threshold

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