Entropy in a closed box
The correct notation would be math.ceil(log(T)). Also what you are asking is/can formally be solved by Binary Search Trees. You can easily traverse it by if-else conditions and arrive at the correct result in math.ceil(log(T)) steps.

It looks something like:



Just place the colour of the balls in the leaf nodes (last nodes). Your first question would be does the ball fall in the first 4 leaf nodes or the second group of 4 nodes.Then you can progress to level 2 and so on.

BST reduces the entropy by maximum amount. You can easily construct other unbalanced trees but then you will require more steps to arrive at a determinate result (in some cases) and less steps in some other cases. BST gives an absolute number of steps you must travel in order to reach the result.

More theory here.