This is the method written in python:
def count_con(s, lo, hi):
vls = ['a', 'e', 'i', 'o', 'u']
if lo == hi:
if s[lo] not in vls:
return 1
else:
return 0
mid = (lo + hi) // 2
count_l = count_con(s, lo, mid)
count_r = count_con(s, mid + 1, hi)
return count_l + count_r
Assume we want to find its time complexity. I've come up with a recurrence relation:
T(n) = 2T(n/2) + f(n), if n > 1 or T(n) = O(1), if n <= 1
However, I cannot determine what f(n)
would be. Will combining the two halves take linear O(n)
time just like in merge-sort or constant O(1)
time? I tend to think that since it's only an addition constant O(1)
time is more suitable.
And overall, is this method O(n*logn)
or O(logn)
?