abreazeale4071 abreazeale4071
  • 22-10-2017
  • Mathematics
contestada

How many comparisons are needed for a binary search in a set of 64 elements?

Respuesta :

meerkat18
meerkat18 meerkat18
  • 02-11-2017

Let f(n) be the number of comparisons required to search for an element in a search sequence of size n. Then from the binary search algorithm we can have f(n) = f(n/2) + 2, where n is even.

 

The number of comparisons needed for a binary search in a set of 64 elements is f(64).

f(64) = f (32) + 2

= f(16) + 2 + 2

= f(8) + 2 + 2 + 2

= f(4) + 2 + 2 + 2 + 2

= f(2) + 2 + 2 + 2 + 2 + 2

= f(1) + 2 + 2 + 2 + 2 + 2 + 2

= 0 + 2 + 2 + 2 + 2 + 2 + 2+ 2

f(64) = 14

Answer Link

Otras preguntas

A triangle has two sides of lengths 7 and 9. What value could the length of the third side be?
A triangle has two sides of lengths 7 and 9. What value could the length of the third side be?
Do you agree with the statement: it's better to prevent then treat. Give some reasons for your opinion.
In the pictures down belowCan anyone help? Fractions and percents
do you think acid rain also affect crops.
use the intercepts to graph the equation 4x-2y=8 please help me solve and graph
i have a few problems on combining like terms please help:1)   12r-8-122)      n-10+9n-3      3)    -4x-10x4) -r-10r
an angle measure x degrees. what is the measure of its compliment? what is the measure of its supplement?
Explain the significance of the equation y = 50x + 20 which represents the hourly cost of a car repair.
Do you agree with the statement: it's better to prevent then treat. Give some reasons for your opinion.