Category: Algo Time Complexity

What is the time complexity of, f(n)= 5n2+3n+4

What is the time complexity of given function, f(n)= 5n2+3n+4 ? Solution:  Given,  f(n)=5n2 +3n+4  5n2 +3n+4>=5n2 +3n+4 for all n>=1 5n2 +3n+4>= 5n2 +3n for all n>=1 5n2 +2n+4>=5n2 for all n>=1 f(n)>=5n2 for all n>=1 Compare with the standard Big omega notation equation that is,  f(n)>=c*g(n) for all n0>=n So here c =5, g(n)=n2 and n0 =1 f(n)=Ω(g(n))  f(n)=Ω(n2) 

Find the time complexity of sum of two matrices

What is the time complexity of the program for the sum of two matrices? Step count method void sum() { int n, a[n][n],b[n][n],c[n][n],i,j; //—-0  for(i=0;i<n;i++) //—-n+1   {      for(j=0;j<n;j++) //—-n+1       {         c[i][j]=a[i][j]+b[i][j]; //—-n        }   } } f(n) = 0 + (n+1) * (n+1+n) f(n) = (n+1)*(2n+1) f(n) =  2n2 + 3n + 1 f(n) = O(n2)