Quiz 2
Registry Synced

Computational Thinking · Week 6 — Tables & dictionaries

1034 words
5 min read
2026-08-16

Reading compass

Now · Week map

Week 6 — tables & dictionaries

Quiz 2 scope: Weeks 1–8 per IITM May 2026 foundation courses. Source baseline: IITM BS admissions important-dates calendar · May 2026 cycle. Times on assessments are operational conventions — verify hall ticket.

Week map

Table dimensions → cell access → dict as column map → frequency count

Classify → Represent → Execute → Trap-check

  • Recognize: Ask: How is a table cell addressed?
  • Procedure: Identify row and column from labels. Value at (2,3) is row 2 column 3 per course convention—verify problem statement.
  • Variations / traps: Watch for: Row/column index swapped.

Formula chain (compressed)

table rows×cols → dict key→value → frequency count pattern.
  1. Tablerow i, column j — 2D grid access
  2. Dictionarykey ↦ value — lookup by label
  3. Frequencycount[key] += 1 — tally occurrences
  4. Row scanfor j in cols: T[i][j] — fix row, sweep columns
  5. Missing keydefault 0 before += — init or get

Deep study

Computational Thinking · Week 6 — Tables and dictionaries

Deep study for Quiz 2 week 6. Tables organize records in rows; dictionaries map keys to values for fast lookup and counting.

Week map

Row/column table → record as dict → key-value lookup → frequency tally → table vs dict tradeoff.

Table notation

  • Row → one record → e.g. student name + score + section.
  • Column → one field across rows → all scores, all names.
  • Cell → intersection of row and column → single value.
  • Header → column labels → keys when converting to dict.
Mini-table:
NameScore
Ada88
Ben92
Row 1 cell (Ada, Score) = 88. Column Score = {88, 92}.

List of records (table as data)

text
table ← [
  {Name: Ada, Score: 88},
  {Name: Ben, Score: 92}
]
Access row 0 field Score → 88.

Dictionary notation

  • Key → unique identifier → string, number, tuple.
  • Value → data stored → any type.
  • Lookup → given key, retrieve value in O(1)O(1) average time (conceptually constant).
  • map[key] ← value → insert or update.
Mini-example: frequency of letters in "aba":
text
freq ← empty map
for each character c in string:
    if c in freq:
        freq[c] ← freq[c] + 1
    else:
        freq[c] ← 1
Result: {a: 2, b: 1}.

Pattern families

Easy — Read table cell

From small grid or list-of-dicts, fetch one value. Identify row vs column.

Medium — Build dict from table

Convert parallel columns to records. Count occurrences. Lookup by key; handle missing key.

Hard — Aggregate with dict

Group rows by category key. Sum or average values per group. Merge two tables on shared key.

Worked mini-examples

Example 1 — Row access.
Three rows, columns (ID, Qty): row 2 ID cell = value in column ID at index 1 (0-based).
Example 2 — Dict lookup.
phone["Ana"] = "555-0100". Lookup "Ana" → number. Lookup missing key → error unless default policy stated.
Example 3 — Frequency.
Items [red, blue, red, green]: freq red=2, blue=1, green=1.
Example 4 — Dict of lists (column store).
text
data.Name ← [Ada, Ben]
data.Score ← [88, 92]
Column Name row index 1 → Ben.
Example 5 — Update vs insert.
If key exists, overwrite value; dict size unchanged. New key increases size by 1.

Traps

  • Row index vs ID column value — row 3 ≠ ID 3 unless stated.
  • Missing key in dict — define behavior (0, null, error).
  • Counting rows vs counting distinct keys.
  • Assuming table sorted unless specified.
  • Confusing list index with dict key.

Diagnostic (try yourself)

  1. In a 4-row table with columns A and B, what does cell (row 3, B) mean?
  2. Map {x: 10, y: 20}. What is value at x? What happens at z without default?
  3. Count how many times "the" appears in word list [the, cat, the, sat].
  4. Represent the mini-table above as one dict mapping Name → Score.
  5. When is dict better than scanning entire table for each lookup?

ChatGPT prep archive

Archived import for extra depth — complements the notes above, not official IITM material.

Core concepts

  • Table: rows × columns; cell (r,c) identifies one value.
  • Dictionary: key maps to value; fast lookup by key.
  • Frequency: count repeats per key in data stream.
  • Row vs column: row is horizontal record; column is field across records.

Notation & vocabulary

StructureAccess
tablerow r, column c
dictkey k → value
frequency dictitem → count

Pattern families

Easy — Read table cell

Identify row and column from labels. Value at (2,3) is row 2 column 3 per course convention—verify problem statement.

Medium — Build frequency dict

Loop items; increment dict[item]. Missing key means zero before increment.

Hard — Table + dict combine

Use dict to store column totals keyed by header. Double loop rows then columns accumulating.
Drill these on the pattern atlas — filter to week 6.

Traps

  • Row/column index swapped.
  • 1-based vs 0-based in problem statement.
  • Dict key typo creates duplicate buckets.
  • Frequency before vs after normalization.

Retrieval prompts

  1. How is a table cell addressed?
  2. Dict vs table when to use?
  3. Steps to build frequency map?

Practice loop

  1. Read Deep study (if present) or core concepts once.
  2. Recite the formula chain without looking.
  3. Open one easy pattern on the interactive atlas for week 6.
  4. Attempt without solutions; mark studied after an honest try.
  5. Say one trap aloud before closing the tab.
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.