Divide and conquer recurrence relation

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 9K views
Eng67
Messages
21
Reaction score
0
I am at a loss on how to get the correct answer to this question.

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

I know the formula f(n) = f(n/2) + 2

I know the correct answer which is 14.

No matter what I do I cannot come up with this answer.

Please help me by showing a couple of steps and I can break down this wall!
 
Physics news on Phys.org
f(n) = f(n/2) + 2
Yes, that is a recurrance relation. However, every recurrance relation, in order to be unique, must also involve an "initial condition". How many comparisons are needed to search a set containing 2 members?

You know that f(64)= f(32)+ 2. Okay, what is f(32)? Well, f(32)= f(16)+ 2. What is f(16)? Continue until you "hit bottom"- that is until you reach f(2).