I train at Codeacademy and I need to do the following function:
Define a function called anti_vowel that takes one line, text as input, and returns text with all the vowels removed.
This is my decision.
def anti_vowel(text):
md = ""
for ch in text:
if ch not in "aeiouAEIOU":
md = md + ch
return md
This works well, but I wonder what the complexity of the function is.
I think O(nk)where is n: = "text length" and k: = "length" aeoiuAEIOU "".
I take one element of the text and compare it with all the vowels, which takes O (k) time. But I repeat it n times, so I do it all in O(nk). Is my analysis correct? How could I improve my function? Can it be linear?
source
share