Programming, problem solving, and algorithms

CPSC 203, 2026 W1

October 13, 2026

Announcements

  • Examlet 2 runs today through Sunday.
  • Lab 5 (matplotlib and pandas) and POTW 5 (pandas and matplotlib) due Sunday.
    • If your scheduled lab was yesterday, you can still attend:
      • T1F: Tue, 18:00 - 19:30.
      • T1E: Thu, 9:30 - 11:00.
  • Project 1 due Monday, October 26 (~two weeks).

Key-Value Lookup

Key-Value Pairs

  • Given the key, we would like to quickly retrieve the corresponding value.


Key Value
name Ian Mitchell
department Computer Science
program M.Sc.
start date 1995-09-01
terms 7
domestic student yes
⋮ ⋮

Representing Key-Value Pairs

  • How could we represent this information? Don’t say “dictionary”.

    • What type for the whole set of data?
    • What type for each row of data?
    • What type for the keys?
    • What type for the values?

Efficiency of List Representations

If there are \(n\) key-value pairs in the store, how long does it take to:

  • Look up the value associated with a key?
  • Determine whether a key is in the store?
  • Add a key-value pair?
  • A Python dict can perform any of these operations in constant time for any \(n\).

Dictionary Patterns

Not Just a One-Trick Pony

Dictionaries / key-value lookup is useful for solving other common problems.

  • Compound data.
  • Tracking membership.
  • Counting appearances / frequencies.
  • Finding complements.
  • Grouping by (discrete) category.
  • Representing a map or translation over a discrete domain.

Today: Finish slides / class activity from last lecture for the first five.

Thursday: Translation / mapping.