문제

I have written the running time based on my calculation in red color on the picture. But I don't know what would be for that IF statement as well as it's body's running time. Will that IF condition's running time would be n x n ? Because each time in the inner loop, it would be evaluated. Isn't it? What about it's body's?

enter image description here

도움이 되었습니까?

해결책

You need to take into account two different parameters, m and n. The outermost loop executes m times, and the inner loop executes n times. The complexity, therefore, is θ(mn).

Note that the if-statement and its body are executed in constant time.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top