Blocks of about the square root
transcript
Twenty thousand accounts. A bonus goes to a range. A question counts rich accounts. A tree does not fit. What now?
There are twenty thousand operations. Each scans up to twenty thousand accounts. That is four hundred million steps. Too slow, in Python especially.
Cut the accounts into blocks. A block holds about one hundred forty-one. Whole blocks get one tag.
Account two is a partial block. Accounts three to five are a whole block. It gets one pending five. Accounts six and seven are partial.
Whole blocks take one tag each. The two partial blocks are done by hand. A partial block holds at most one hundred forty-one. That is about one hundred forty-one steps.
There are one hundred forty-two blocks. Each search takes about eight steps. In all, about twenty-eight million steps.
Blocks fit when trees do not. Whole blocks are cheap. Partial blocks are small. Four hundred million becomes twenty-eight million. Full breakdown in the lecture.