N
N
Nikita Stechkin2021-02-18 00:07:55
Algorithms
Nikita Stechkin, 2021-02-18 00:07:55

What is the maximum number of operations in a binary search?

The number of operations can be calculated, for example, using the log n formula, but when I check this on the sheet, it turns out to be 1 more. If we take 8, then the maximum number of operations according to the formula will be 3, let's say I guessed 8, it turns out:

-4?
-More.
-6?
-More.
-7?
-More.
-eight?
Yes.
And the number 8 was guessed only after 4 attempts. Why doesn't the formula work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-02-18
@VAMPIRE37

They made a mistake with the edges: 3 bits (3 questions) are numbers from 0 to 7.
Each question specifies a bit, from the highest to the lowest:

0  000
1  001
2  010
3  011
4  100 - четыре?  - больше (старший бит 1xx )
5  101
6  110 - шесть? - больше ( 11x )
7  111 - семь – ага

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question