2

I have to come up with the recurrence for the quaternary search algorithm.

My initial thought is $T(n)=4T(\frac{n}{4})+c$ because the algorithm examines all four subproblems, and each is one quarter the size of the entire array. But this can't be right because that yields a complexity of $O(n)$. I looked on Google and the complexity of quaternary searches are supposed to be $\log_4n$, but I don't know what the recurrence would be to get me that complexity.

Any help would be greatly appreciated. Thanks!

  • 1
    Welcome to CS.SE! See http://cs.stackexchange.com/q/23593/755, http://cs.stackexchange.com/q/192/755, and any textbook that describes how to characterize the running time of an algorithm as a recurrence relation. Then, edit the question to show your reasoning and why you think the recurrence is $T(n) = 4 T(n/4) + c$. Don't just guess -- show us your thought process. Without knowing how you got that answer, it's hard for us to point out where you went awry or correct any misconceptions you might have. – D.W. Oct 05 '16 at 20:33
  • Cross-posted: http://cs.stackexchange.com/q/64268/755, http://math.stackexchange.com/q/1954101/14578. Please do not post the same question on multiple sites. Each community should have an honest shot at answering without anybody's time being wasted. – D.W. Nov 22 '16 at 23:39

2 Answers2

2

Your recurrence is wrong, which is why you get the wrong answer. I suspect that the reason your recurrence is wrong is that you don't quite understand the algorithm. Try mimicking your reasoning on binary search until you successfully get the correct running time in that case.

Moreover, as mentioned in the comments, the running time (assuming constant-time comparisons and the RAM machine model) is $\Theta(\log n)$, but cannot get more accurate than that. To get $\log_4 n$ you need to count something more specific, such as the number of comparisons performed by the algorithm.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
0

The correct recursion formula is $T(n) = T(\frac{n}{4}) + c$, which yields $O(lgn)$. Because the base is 4 here, for quaternary searches it becomes $O(log_4n)$.