You are on page 1of 8

In worst case what is the number of primitive operations executed by the following algorithm?

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

The closed form of T(n) would be

n!

If T(n)=n2-n+log n then T(n) is

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

If f(n) is O(g(n)) and f(n) is W (g(n)) then f(n) is

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)

if (lim( f(n) / g(n) ) = , n

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)

Contraposive of the statement "If it is sea-water then it must be salaine" is

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

Two main measures for the efficiency of an algorithm are

Time and space

You might also like