Algorithms | Analysis of Algorithms | Question 2
What is the time complexity of fun()?
The time complexity can be calculated by counting the number of times the expression “count = count + 1;” is executed. The expression is executed 0 + 1 + 2 + 3 + 4 + …. + (n-1) times.
Time complexity = Theta(0 + 1 + 2 + 3 + .. + n-1) = Theta (n*(n-1)/2) = Theta(n2)
Quiz of this Question
Please comment below if you find anything wrong in the above post
My Personal Notes arrow_drop_up
Please Login to comment...