SECTION 15 / 31

Choose what to remember and what work remains

1 min read
Dictionary lookup does not require sorted keys. Extract and sort keys only when the later task needs calendar order.
Dictionary lookup does not require sorted keys. Extract and sort keys only when the later task needs calendar order.
Value choiceCan answerDoes not retain
TrueHas this date appeared?Count and student identities
CountHow many records have this date?Individual IDs
ID listWhich ID occurrences appeared?Direct key membership without searching the list
ID dictionaryWhich distinct IDs appeared?Repeated copies of the same ID

Under the course’s constant-time dictionary-operation assumption, a birthday presence/count scan does one small amount of dictionary work per record. Finding all pairs inside a large equal-date group still requires work for every pair output. Storing ID lists also needs space for those IDs. Do not claim the entire task, including arbitrary list concatenation or producing all pairs, is constant time.

The course’s list model is sequential: finding a member may require a scan. That is why an ID dictionary can be useful for repeated membership questions. A list remains useful when sequence and repeated occurrences matter.

Try it yourself

Can a True flag answer “which students”?

Show explained answer

No. It loses the IDs.

Try it yourself

Does a direct dictionary lookup require sorting its keys first?

Show explained answer

No.

Try it yourself

If all n students share one birthday and we print all pairs, can there be only n outputs?

Show explained answer

No. There are n(n−1)/2 unordered pairs; outputting them requires that many pair outputs.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑