University of Auckland · FACULTY OF COMPUTER SCIENCE

COMPSCI101 Chap.8 Dictionaries and Keyed Data

- one subject, every graph, every model, every mark
5 Chapters2-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 8 of 9 · COMPSCI101

Dictionaries and Keyed Data

Define dictionary

The course material gives this chapter a concrete anchor: The dictionary labs move from mapping creation and lookup to updates and applied keyed processing. That dictionary anchor controls how key lookup is explained and how frequency table is tested in changed practice.

Dictionaries and Keyed Data turns dictionary, key lookup and frequency table into executable reasoning.

The chapter's practical target is to construct and update a frequency dictionary while handling a previously unseen key, so every explanation should connect syntax to program state, control flow and observable output.

Treat dictionary as a precise program object, not a loose label. Identify the value or responsibility of dictionary before execution, then trace what can read it, change it or depend on it.

This makes state changes visible before they become debugging guesses.

Use key lookup to explain the program's next move. Work through one representative key lookup input by hand and name the branch, iteration or call that follows. If the key lookup trace cannot be stated, the code may run by accident rather than by understood design.

Bring in frequency table as the test of structure.

Compare normal, boundary and invalid inputs for frequency table; state the expected behaviour first; then use the mismatch between expectation and result to localise the defect.

For the application — construct and update a frequency dictionary while handling a previously unseen key — write the smallest complete example that exposes the rule.

Explain why the frequency table result works, what would break it and how the program should signal or recover from that failure.

Trace key lookup

Before running an dictionary example, make a trace table with the important state before and after each operation. Include the value associated with dictionary, the control decision governed by key lookup and the output or object affected by frequency table.

The dictionary table turns an unexplained result into a sequence that can be tested one transition at a time.

Test three inputs: an ordinary case, a boundary case and an invalid case. State the expected frequency table result for each before execution, then compare it with what the program actually does.

A useful test of key lookup isolates one rule; changing several conditions at once cannot reveal which condition caused the failure.

Practise explaining the solution without reading the code.

For COMPSCI101, name the data representation, the control flow, the responsibility of each function or class and the reason the chosen design supports construct and update a frequency dictionary while handling a previously unseen key.

This frequency table rehearsal matters when a written test or interview asks why the program works rather than whether it produces one correct output.

A complete response should make the task visible before the detail: identify what must be decided, define the relevant terms, connect the evidence to key lookup, and use frequency table to test the result.

The final sentence about frequency table should answer the question actually asked rather than merely repeat the topic.

The controlling limit is specific: Dictionary iteration order must not be confused with numeric or alphabetical key order unless the program explicitly sorts it.

Keep that frequency table limit beside the worked example, because it separates a careful COMPSCI101 answer from one that sounds confident but claims more than the task or evidence supports.

For revision, retrieve dictionary, key lookup and frequency table without notes, explain their relationship aloud, then complete a changed version of the application: construct and update a frequency dictionary while handling a previously unseen key.

Record the first failed key lookup reasoning move and repair it before attempting another case.

In this chapter

What this chapter covers

  • 01

    dictionary

  • 02

    key lookup

  • 03

    frequency table

  • 04

    Applying dictionary

  • 05

    Limits of key lookup and frequency table

Worked example · free

AskSia practice: apply Dictionaries and Keyed Data

Q [4 marks]. AskSia-authored four-point reasoning drill: how should a student construct and update a frequency dictionary while handling a previously unseen key? This is not a University question or marking scheme.
  • 1Define dictionary in the scenario.
  • 1Explain the mechanism using key lookup.
  • 1Test the conclusion with frequency table.
  • 1State a qualified decision and review signal.
A strong response identifies the relevant evidence, uses key lookup as the explanatory link and tests the recommendation through frequency table. It ends by stating that dictionary iteration order must not be confused with numeric or alphabetical key order unless the program explicitly sorts it.
Sia tip — The four points are AskSia-authored practice weighting only.
Glossary

Key terms

dictionary
A mutable mapping that associates unique hashable keys with values. Use this definition when the task is to construct and update a frequency dictionary while handling a previously unseen key.
key lookup
Retrieval of a mapped value by a key, with explicit behaviour required for an absent key. Use this definition when the task is to construct and update a frequency dictionary while handling a previously unseen key.
frequency table
A mapping from observed categories to the number of times each category occurs. Use this definition when the task is to construct and update a frequency dictionary while handling a previously unseen key.
FAQ

Dictionaries and Keyed Data FAQ

What is the main task in Dictionaries and Keyed Data?

Construct and update a frequency dictionary while handling a previously unseen key.

How do dictionary and key lookup work together?

Use dictionary to establish the object or condition, then use key lookup to explain how it changes the outcome being analysed.

What must a COMPSCI101 answer qualify here?

Dictionary iteration order must not be confused with numeric or alphabetical key order unless the program explicitly sorts it.

How should I revise Dictionaries and Keyed Data?

Retrieve dictionary, key lookup and frequency table, apply them to a changed case, and correct the first point where the evidence no longer supports the conclusion.

Study strategy

Exam move

Reconstruct the relationship among dictionary, key lookup and frequency table; complete the chapter application without notes; then test the result against this limit: Dictionary iteration order must not be confused with numeric or alphabetical key order unless the program explicitly sorts it.

Working through Dictionaries and Keyed Data in COMPSCI101? Sia is AskSia’s AI Computer Science tutor — ask any COMPSCI101 Dictionaries and Keyed Data question and get a clear, step-by-step explanation grounded in how COMPSCI101 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 15 of your University of Auckland subjects - and 1,000+ Bibles across every Australian university.
Sia - your COMPSCI101 tutor, unlimited, worked the way the exam marks it
The full 2-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
Unlock the full COMPSCI101 Bible + 15 University of Auckland subjects
$0.99 Trial