Given a handful of candidate words, the checker must pick the best one. Today you rank a candidate set by frequency, breaking ties alphabetically so the choice is always deterministic.
Choose the highest-frequency word from a set of candidates, with alphabetical order breaking ties.
Candidate generation hands you a set of plausible words; ranking turns that set
into a single answer. The rule is Norvig’s: prefer the most frequent candidate,
because a common word is a likelier intended target than a rare one. Among tea,
ten, and the, the count of the towers over the others, so it wins.
The tie-break matters more than it looks. When two candidates share the top count,
picking “whichever came first” makes the answer depend on the order the generator
happened to produce - flaky and unrepeatable. Breaking ties alphabetically
makes BestByFreq a pure function of the candidates and their counts, so the same
input always yields the same correction. Determinism like this is what lets every
later lesson pin an exact expected suggestion.
func (d *Dictionary) BestByFreq(cands []string) string {// return the candidate with the greatest Count; on a tie,// prefer the alphabetically smaller word so the result is// deterministic (never depends on candidate order)}