Idea of Efficiency Class 12
Idea of Efficiency Class 12
What is Algorithm:
An algorithm is well-defined and systematic or step
by step method to complete specific task.
2.Nested Loop:
for i in range(n):
for j in range(n):
m=m+2
(Steps in red will take cn times)(outer loop executed n times)
Total time= cn*n = cn2
O(n2 )
3.Consecutive statement:
x=x+1 # time=a
for i in range(n): # time= cn
m=m+2
for i in range(n): # time= bn2
for j in range(m):
m=m+2
Total time = a+cn+bn2 = O(n2)[Considering only the dominant term]