Count with two searches.
transcript
A sorted list of bids. Five repeats three times. How many are exactly five? Two searches answer it. Let me show you how.
The lower bound is the first position at least x. The upper bound is the first position above x. Subtract them to count. Repeats are counted once each. Test a list with repeats. Test a query below everything.
The band is five to five. The lower bound is position one. The upper bound is position four. Four minus one is three. No loop over the fives was needed.
Using the lower bound twice drops the repeats. Check a repeated value first. Use lower for low, and upper for high. Test a list with repeats.
A hundred thousand bids. Each search takes seventeen steps. Two searches, thirty-four steps. Two bounds beat a scan of every bid.
Lower for the low end. Upper for the high end. Test repeated values. Full breakdown in the lecture.