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!
The problem
Test-left column:function name; middle column:number of items; right column: time taken
Woojin Rho is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.