0

What's the complexity of the above? It's part of a larger problem where the (1/2) comes from the probability of that happenening, so the worst case is:

T(n) = T(n/2) + c

but the average case is:

T(n) = (1/2)T(n/2) + (1/2)c

Our professor told us that the answer to the worst case is O(n), and that the average case is O(n) as well. This doesn't sit right with me because if you have 10,000 coin flips, you're saying you're expecting 10,000 heads (recurse on heads, break on tails). I said it was O(1) on our midterm, anyone else have any insight?

David Richerby
  • 81,689
  • 26
  • 141
  • 235
  • Is $c$ supposed to be $\Theta(1)$? If so, by the Master Theorem the worst case is $\Theta(\log n)$. – Aristu Oct 12 '16 at 18:56
  • 3
    It doesn't have complexity. Algorithms have complexity but $T$ is just a mathematical function. You're not trying to find its complexity: you're just trying to find out what it is. – David Richerby Oct 12 '16 at 19:03
  • Assuming $c$ is constant, the solution to the first recurrence is $T(n)=\Theta(\log n)$ and the second has $T(n)=\Theta(1)$. Since neither answer is what your professor said, it would be helpful if you stated the "larger problem" explicitly. – Rick Decker Oct 12 '16 at 19:14

0 Answers0