SECTION 04 / 17

Put birthdays into month bins

1 min read
On this page 1 headings

A bin is simply a labelled group. First put each card into its month bin: January, February and so on. Two students born in different months cannot have the same birthday. Therefore, we only need day comparisons inside each month bin.

Month bins safely remove cross-month birthday comparisons. We still compare different students within each bin.
Month bins safely remove cross-month birthday comparisons. We still compare different students within each bin.
REAL COURSE DATA · THINK BEFORE EACH STEP

Bin birthdays by month

Trace the records, compare the methods and watch what changes. Back and Reset let you try again.

Ready

CURRENT RECORD X

Ready to begin

Choose Next step to follow the actual course records.

What we remember

Processed
0

Start with Next step. Predict what changes before reading the explanation.

The actual month bins in your dataset

MonthCardsWithin-bin pairs
Jan33
Feb21
Mar46
Apr10
May46
Jun10
Jul / July33
Aug10
Sep33
Oct21
Nov21
Dec46
Total3030

The full all-pairs method has 435 pair checks. Month binning has 30 card placements followed by 30 within-month pair checks when every pair is counted. The saving in pair checks is 405. This does not mean the entire algorithm does only 30 operations: grouping and storing cards also take work.

The source cards use both “Jul” and “July”. We normalize both spellings to the same month. Otherwise we would incorrectly split July into two bins and could miss a match in other data. Matching on a raw spelling is not always matching the real-world value.

Binning by day number is another safe option: create up to 31 day bins, then compare months inside each bin. A bin for the full day-and-month key can instead count previous occurrences while scanning. The right key depends on the question; sorting all dates is a different possible method.

Try it yourself

Can January 7 be compared only with November 7 after month binning?

Show explained answer

No. It belongs with the other January cards. Month binning checks day equality inside January; cross-month cards cannot match.

Try it yourself

What if all 30 students were born in March?

Show explained answer

The March bin would still need 435 unordered pair checks. The grouping pass adds work but does not save pair checks in that case.

Try it yourself

Why does a one-card bin need zero pair checks?

Show explained answer

A pair needs two different records. A singleton cannot contain a matching student pair.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑