wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Algorithm Complexity Quiz

Total questions: 15

Worksheet time: 5mins

Name
Class
Date
1.

If the capacity of the knapsack is 50, and we have items with weights [10, 20, 30] and values [60, 100, 120], the maximum profit using fractional knapsack is:

a)

220

b)

240

c)

280

d)

300

2.

Time complexity of fractional knapsack using sorting is:

a)

O(n log n)

b)

O(n)

c)

O(n²)

d)

O(log n)

3.

Huffman coding is optimal because it:

a)

Uses dynamic programming

b)

Uses greedy choice of minimum frequency nodes

c)

Uses divide and conquer

d)

Uses brute force

4.

Time complexity of Huffman coding with priority queue is:

a)

O(n)

b)

O(n log n)

c)

O(n²)

d)

O(log n)

5.

In maximum subarray problem, the crossing subarray is computed in:

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n²)

6.

In MCM, if dimensions are [10, 20, 30], the minimum multiplication cost is:

a)

6000

b)

12000

c)

18000

d)

2000

7.

Time complexity of DP solution for MCM is:

a)

O(n²)

b)

O(n³)

c)

O(n log n)

d)

O(2ⁿ)

8.

If we have weights [1,3,4,5], values [1,4,5,7] and capacity = 7, maximum profit in 0-1 knapsack is:

a)

7

b)

9

c)

11

d)

12

9.

In MCM, the cost of multiplying a chain Ai...Aj at position k is given by:

a)

cost(i,k) + cost(k+1,j) + pi−1 × pk × pj

b)

cost(i,j) + pi−1 × pj × pk

c)

cost(i,k) − cost(k+1,j)

d)

cost(i,j) × (pi−1 × pk × pj)

10.

Find the pivot element from the given input using median-of-three partitioning method. 8, 1, 4, 9, 6, 3, 5, 2, 7.

a)

8

b)

7

c)

9

d)

6

11.

Analyze the time complexity derivation of the divide and conquer maximum subarray algorithm. Which recurrence relation represents the time complexity correctly?

a)

T(n)=T(n−1)+O(1)

b)

T(n)=2T(n/2)+O(n)

c)

T(n)=T(n/2)+O(log n)

d)

T(n)=nT(n−1)+O(n2))

12.

Solve the following recurrence using Master's theorem. T(n) = 16T (n/4) + n

a)

T(n) = O(n)

b)

T(n) = O(log n)

c)

T(n) = O(n2log n)

d)

T(n) = O(n^2)

13.

Solve the following recurrence using Master's theorem. T(n) = 4T (n/4) + n log n

a)

T(n) = O(n (log n)^2)

b)

T(n) = O(n log n)

c)

T(n) = O(n^2 log n)

d)

T(n) = cannot be solved using master's theorem

14.

Given matrices A1 of dimension 10×30, A2​ of dimension 30×5 and A3​ of dimension 5×60,what is the cost of multiplying A1(A2A3)

a)

4500

b)

27000

c)

10500

d)

9000

15.

Time complexity of divide & conquer maximum subarray algorithm is:

a)

O(n)

b)

O(n log n)

c)

O(n²)

d)

O(log n)