Professional Documents
Culture Documents
Algorithm addPositive(A,n) Input: An array A of n>=1 elements Output: The sum of all positive elements sum for j A[0] 1 to n-1 if A[j] > 0 then sum return sum 8n-3 sum+A[j]
If T(n) denotes the running time of an algorithm and can be expressed in recursive form as 1 T(n)= n.T(n-1) otherwise if n=1
n!
O(n )
f(n)=O(g(n)), if there exists an integer n0 and a constant c>0 such that for all integers , n>=n0 , f(n)<=cg(n). If f(n)=5n+2 and f(n) is O(n) then value of C and n0 is C=6, n0=3
5 (g(n))
Arrange the following function in increasing order O(logn), O(n2), O(2n), O(nlogn), O(1) O(1), O(logn), O(nlogn), O(n2), O(2n)
then f(n) is
(g(n))
Algorithm findMax(A,10) n 10 max A[0] for j 1 to n-1 if A[j] > max then max A[j] return max Time complexity of the algorithm is O(n)
If it is not salaine then it is not sea water To disprove 2k +3 is a prime for all positive integer value of k, we found that for k=5 the value is 35 = 7 X 5. This is called as proof by Counter example