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

Write an account from the old mans point of view of the river gypsies catching the cobras
ok so i need help with my english homework soon can anyone help​
ASAP HELP 100 POINTS I HAVE TO TURNE THIS IN TODAY Find the value of each variable. SHOW ALL THE WORK
Ayo why is this generation so suicidal?
how many moles of aluminum ions are present In 0.50 moles of al2so4)3​
The swim coach is planning to attend the district swim meet next week. She must decide who will swim the different events. Find the combined time of her star sw
Help me please (NO WRONG ANSWERS!) Pictures below
What is the term for a hydrocarbon with a sulfhydryl group
Part A: What does 0 represent in this situation? (3 points) Part B: Describe the height of the slide in relation to 0 in the situation. (3 points) Part C: Kayla
Use the discriminant formula to find the number of x-intercepts in the graph of the equation.2x2 + 4x + 2 =y b2 - 4ac​