try to maybe “reuse” our counter, count to 256, then start over from zero? We keep a flag that tells us if we’re using, or reusing our code. Another idea is this: maybe we could count every alternate event, thus doubling our capacity? Flag to keep track of whether the event we see next should to be counted or skipped? What’s the problem with these two ideas? PAUSE (Slide 8) The problem is that a flag is one bit of state. It is a 9th bit in addition to the 8 we’re already using for the counter. We don’t have any bits to spare. We can’t get an accurate counter to count more than 256. Maybe we can get a not-so-accurate counter? Accuracy is overrated. It is useful to have Re.1 coins if you want to buy a Rs5 cup of coffee, not especially required if you want to buy a Ferrari. For many use cases it is okay to have a number that’s approximately right. (Slide 9) What we shall do – or rather, what Robert Morris did – was to toss a coin. A fair coin, that has equal chances of heads or tails. 50 - 50. If we get heads, we increase our counter. If tails, we stay at the same value This is a strange idea, we’re no longer deterministic. We’ve introduced a probabilistic element to our program, and now our answer might not be exactly right. We’re trading accuracy to be able to break the information theoretic bound to the number that we can count using just 8-bits. This is important, this is the main insight of this talk. That we can “trade accuracy for space”. PAUSE (Slide 10) Here’s a picture to illustrate how this new “counter” of ours works. A simple regular counter goes from 1 to 2, from 2 to 3, and so on. Here, if we are at 1, and we increment the counter, then we can go to 2 with 50% chance if we get heads, or we can stay at 1, with 50% chance if we get tails. PAUSE This might sound like a neat idea, but it might not be obvious if this is solving the problem at hand. The coin tossing counter can go anywhere. (Slide 11) It helps to think of the coins like this: on average we expect to see one head, for every two tosses. If we’ve tossed the coin 10 times, we expect to see 5 heads. We can see more, or maybe less. But the most likely outcome is 5. So in the case of our counter, we expect the value to increment once for every two tosses. PAUSE Let’s look at a probability chart. If we toss a fair coin 10 times, then the x-axis here is the number of heads we see, and the y-axis is the probability of that outcome. When we say that we expect to see 5 heads when we toss the fair coin 10 times, we mean that it is the most likely outcome. It is possible that we see no heads in 10 tosses, but that is very unlikely. (Slide 12) One thing is obvious directly, that the “counter” isn’t a counter anymore. It isn’t storing the count of the number of elements. Instead it is an “estimator”, we can use this to get an “estimate” of the number of elements. In this case, if the estimator is k, then our estimate is 2k. If we’ve seen n elements, then the estimator should be approximately n/2 So our estimator, which is 8 bits, can still go to 256. You can’t do more than that! But we can use that to estimate numbers up to 512. PAUSE of 2 7