3 ms·
In general, in order to a store a thing with N values you need log_2(N) bits of information. This is actually really simple to see if N is a power of two. If yo
by anon291 2y ago
In general, in order to a store a thing with N values you need log_2(N) bits of information. This is actually really simple to see if N is a power of two. If you have four things, how many yes/no questions do you need to exactly determine one of the four things? The answer is two (divide the four into two groups of two, ask which group the object is in. Then, when you have that group, split into two groups of one, and ask the next question)[1].
So, for powers of two, it's obviously log_2(N).
Now we just extrapolate. For three things, on average, you need to ask log_2(3) questions. Sometimes you ask just one, sometimes you must ask two (depending on where you split the group). Either way, the formula is the same.
log(3)/log(2) is just a way of writing log_2(3) (since the value of log3/log2 is the same regardless of which base the log is in).
Note that two isn't special. It's only because we've limited ourselves to 'how many yes/no/questions'. If you wanted to know how many multiple choice questions of 3 responses would you need to exactly determine which object of a set of 4, the answer is log_3(4).
[1] You can think of any byte, word, double word, quad word as simply a path in a binary tree of all numbers in the range 0..2^N-1 (where N is bit width). The path uniquely identifies the number.