Skip to content
Advertisement

what is the Time Complexity of a nested loop in a recursive function?

I have a recursive function with a nested loop.I’m looking for what is the time complexity? Here is the function

JavaScript

Advertisement

Answer

Suppose n is the length of input_str. The algorithm can iterate n times recursively in the worst case, i.e., in each recursive call letter will be increased by 1 and it can be continued up to n. In each iteration, the wors case is O(n) (running the loop completely). Hence, the time complexity is O(n^2).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement