I'm having some trouble determining the time complexity of this recursive function in terms of Big-O notation.
double expRecursive(double x, int n) {
if (n <= 4) {
return expIterativ(x, n);
}
return expRecursive(x, n/2) *
expRecursive(x, (n + 1)/2);
}
(The time complexity of the method expIterative is O(n))
Is the recurrence relation of expRecursive() T(n) = 2T(n/2) + n?
If this is the case I suppose T(n) = O(nlogn) after applying the master theorem?
My biggest problem is coming up with the correct recurrence relation...
expIterativ's behavior on negative numbers is unclear. If it only does work from0 < n <= 4then it's constant time and you're left with 2*log(n) == O(log(n)). I assume this function is always called with positive numbers. - ggorlen