Twenty billion steps for two words.
transcript
A tag of a hundred thousand letters. Same letters as the typed word? Count each letter in both. It is correct. It is slow. The first attempt is correct. Its cost hides in the scans.
Stone and tones. Fifty steps. That is instant. Twice the letters. Four times the steps. It grows like n squared. Ten letters hide the cost. Test the real size.
A hundred thousand letters. Two n squared steps. Twenty billion steps in all. The search should answer at once. Every letter scans both words. The same letter is counted again.
One counting pass is two hundred thousand steps. That is a hundred thousand times fewer. It uses twenty six counts. Sorting would take n log n. One count for each letter. Each word is walked once. Memory stays constant. The answer comes at once. A map would also work.
Count once. Full breakdown in the lecture.