0
What is time complexity in python
How to find it
1 ответ
+ 2
for i in range(0, n):
...
runs n times, so it has time complexity O(n).
for i in range(0, n):
for j in range(0, m):
for k in range(0, n):
...
runs n²*m times, so it has time complexity O(n²*m).
for i in range(0, n):
...
for i in range(0, n):
...
runs 2*n times, but constant factors are ignored, so it has time complexity O(n).
for i in range(0, n):
for j in range(0, n):
...
for i in range(0, n):
....
runs n²+n times, but we only care about the highest power, so it has time complexity O(n²).
That's the basics of it. Google for "big O" notation.
If you post an example of which you want to find the time complexity, I can walk you through it.