wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz – Unit 1: Algorithm Analysis

Total questions: 21

Worksheet time: 11mins

Name
Class
Date
1.

What does the complexity of an algorithm measure?

a)

The programming language used

b)

The time and space required based on input

c)

The number of variables used

d)

The aesthetics of the code

2.

What does O big (O(f(n))) mean?

a)

Lower bound of the algorithm

b)

Asymptotic upper bound

c)

Exact execution time

d)

Average execution time

3.

If an algorithm has T(n) = 5n + 3, what is its order of complexity?

a)

Θ(1)

b)

Θ(log n)

c)

Θ(n)

d)

Θ(n²)

4.

Which of the following functions grows faster for large n?

a)

n log n

b)

c)

log n

d)

n

5.

In asymptotic notation, what does Θ(f(n)) represent?

a)

Only upper bound

b)

Only lower bound

c)

Tight bound: both upper and lower

d)

Average time

6.

Order the functions from least to greatest growth:

a)

log n < n < n² < 2ⁿ

b)

n² < log n < n < 2ⁿ

c)

2ⁿ < n² < n < log n

d)

n < log n < 2ⁿ < n²

7.

An algorithm with two nested loops from 0 to n has complexity:

a)

Θ(n)

b)

Θ(n²)

c)

Θ(n log n)

d)

Θ(log n)

8.

An algorithm that divides the problem in half at each step (like binary search) has complexity:

a)

Θ(n²)

b)

Θ(n log n)

c)

Θ(n)

d)

Θ(log n)

9.

The cost of traversing an array of size n is:

a)

Θ(1)

b)

Θ(log n)

c)

Θ(n)

d)

Θ(n²)

10.

The cost of mergesort is given by the recurrence T(n)=2T(n/2)+Θ(n). Its complexity is:

a)

Θ(n²)

b)

Θ(n log n)

c)

Θ(log n)

d)

Θ(n³)

11.

What is the rule for simplifying time equations?

a)

Keep all terms

b)

Eliminate the dominant term

c)

Keep the dominant term

12.

What is the rule for simplifying time equations?

a)

Conserve all terms

b)

Eliminate the dominant term

c)

Conserve the dominant term and eliminate constants

d)

Use only the worst case

13.

The sum of the first n integers is (1 + 2 + ... + n):

a)

Θ(n)

b)

Θ(log n)

c)

Θ(n²)

d)

Θ(2ⁿ)

14.

The average complexity of linear search in a list of n elements is:

a)

Θ(1)

b)

Θ(log n)

c)

Θ(n/2) or Θ(n)

d)

Θ(n²)

15.

The difference between the best and worst case of linear search is:

a)

None

b)

Best case Θ(1), worst case Θ(n)

c)

Best case Θ(log n), worst case Θ(n²)

d)

Best case Θ(n), worst case Θ(1)

16.

Quickselect finds the k-th smallest in:

a)

Θ(n²) always

b)

Θ(n log n) average

c)

Θ(n) average

d)

Θ(log n) worst case

17.

A tree with n nodes has how many edges?

a)

b)

n+1

c)

n-1

d)

2n

18.

The in-order traversal of a binary tree visits nodes in the order:

a)

Root - Left - Right

b)

Left - Root - Right

c)

Right - Root - Left

d)

Root - Right - Left

19.

The complexity of traversing a binary tree of n nodes is:

a)

Θ(log n)

b)

Θ(n)

c)

Θ(n²)

d)

Θ(1)

20.

The complexity of BFS in a graph represented with adjacency lists is:

a)

Θ(V²)

b)

Θ(E)

c)

Θ(V + E)

d)

Θ(log V)

21.

In an adjacency matrix of a graph with V vertices, the required space is:

a)

Θ(V + E)

b)

Θ(V²)

c)

Θ(E)

d)

Θ(1)