wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Analysis of Algorithms

Total questions: 10

Worksheet time: 33mins

Name
Class
Date
1.

What does it mean when we say that an algorithm X is asymptotically more efficient than Y?

a)

X will be a better choice for all inputs

b)

X will be a better choice for all inputs except possibly small inputs

c)

X will be a better choice for all inputs except possibly large inputs

d)

Y will be a better choice for small inputs

2.

Which of the following is not O(n^2)?

a)

(15^10) * n + 12099

b)

n^1.98

c)

n^3 / (sqrt(n))

d)

(2^20) * n

3.

Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3 and f4?

f1(n) = 2^n

f2(n) = n^(3/2)

f3(n) = nLogn

f4(n) = n^(Logn)

a)

f3, f2, f4, f1

b)

f3, f2, f1, f4

c)

f2, f3, f1, f4

d)

f2, f3, f4, f1

4.

Consider the following functions:

f(n) = 2^n

g(n) = n!

h(n) = n^logn

Which of the following statements about the asymptotic behavior of f(n), g(n), and h(n) is true?

a)

f(n) = O(g(n)); g(n) = O(h(n))

b)

f(n) = omega (g(n)); g(n) = O(h(n))

c)

g(n) = O(f(n)); h(n) = O(f(n))

d)

h(n) = O(f(n)); g(n) = omega (f(n))

5.

Which of the following is not true about comparison based sorting algorithms?

a)

The minimum possible time complexity of a comparison based sorting algorithm is O(nLogn) for a random input array

b)

Radix Sort is taken linear time for sorting

c)

Counting Sort is not a comparison based sorting algortihm

d)

Heap Sort is not a comparison based sorting algorithm.

6.

What is time complexity of fun()?


int fun(int n)

{ int count = 0;

for (int i = n; i > 0; i /= 2)

{ for (int j = 0; j < i; j++)

{ count += 1; }}

return count; }

a)

O(n^2)

b)

O(nLogn)

c)

O(n)

d)

O(nLognLogn)

7.

Consider the above functions

Which of the following is true?

(a) h(n) is 0(f(n))

(b) h(n) is 0(g(n))

(c) g(n) is not 0(f(n))

(d) f(n) is 0(g(n))

a)

a

b)

b

c)

c

d)

d

8.

What is the time complexity of fun()?

int fun(int n)

{

int count = 0;

for (int i = 0; i < n; i++)

for (int j = i; j > 0; j--)

count = count + 1;

return count;

}

a)

Theta (n)

b)

Theta (n^2)

c)

Theta (n*Logn)

d)

Theta (nLognLogn)

9.

What is the time complexity of following function fun()? Assume that log(x) returns log value in base 2.

void fun()

{

int i, j;

for (i=1; i<=n; i++)

for (j=1; j<=log(i); j++)

printf("XYZ");

}

a)

Θ(n)

b)

Θ(nLogn)

c)

Θ(n^2)

d)

Θ(n^2(Logn))

10.

The time complexity of the following C function is (assume n > 0)

int recursive (int n) {

if(n == 1)

return (1);

else

return (recursive (n-1) + recursive (n-1));

}

a)

O(n)

b)

O(n log n)

c)

O(n^2)

d)

O(2^n)