Optimizing generalized ternary search

48 Views Asked by At

There are $N$ socks numbered $1$ to $N$, one containing a gift. Dave needs to find the sock with the gift. He can ask some questions in order to find that sock: in each question, Dave chooses $2$ numbers $P,Q$ where $P \le Q$.

Let $X$ be the index of sock containing the gift .

  • If $X \le P$ , Dave pays $A$ dollars.

  • If $ P \lt X \le Q$, Dave pays $B$ dollars.

  • If $ Q \lt X $, Dave pays $C$ dollars.

Given the values of $A,B,C$, how to find the minimum number of dollars that Dave has to pay in order to find the gift?