Question-16
Python programming
Time complexity
Consider the following python function:
Time complexity of fun
in terms of $ $ notation is
Answer
Solution
The outer loop runs \(n\) times, and the inner loop runs \(\frac{n}{i}\) times for each value of \(i\) from \(1\) to \(n\). Therefore, the total number of iterations is approximately \(\sum_{i=1}^{n} \frac{n}{i}\), which is \(n \log n\). Hence, the time complexity of fun
is $ (n n) $.