Time Complexity of recursion inside a for loop with variable iteration?
I was solving a LeetCode problem which I solved with two codes with different time complexities but both gave the same runtime.
Is the time complexity of this method constant?
I’ve been tasked to find the time complexity of this method, but I am not sure why it’s constant.
What I had thought was that the overall time complexity was n2^{n} because the outer loop runs n times and inner loop runs 2^{k} times because k is being multiplied by a factor of two for each time the outer loop runs. However, when I tested the method out using System.nanoTime(), the time seem to stay constant for increasing sizes of the data. I’m not sure if I’m correct or wrong, but if I’m wrong, and the method has a constant time complexity, can you please explain why? Thank you!