wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Algorithm UNIT Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the time complexity of a linear search algorithm?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(1)

2.

Which asymptotic notation gives the upper bound of an algorithm's time complexity?

a)

Big-O

b)

Big-Ω

c)

Big-Θ

d)

None

3.

What is the worst-case time complexity of a binary search algorithm?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(1)

4.

Which algorithm has a time complexity of O(n^2)?

a)

Bubble sort

b)

Selection sort

c)

Insertion sort

d)

All of the above

5.

What is the best-case time complexity of a heap sort algorithm?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(1)

6.

Which data structure is used in a heap sort algorithm?

a)

Array

b)

Linked list

c)

Stack

d)

Queue

7.

What is the time complexity of a naive string-matching algorithm?

a)

O(n)

b)

O(n^2)

c)

O(n log n)

d)

O(1)

8.

Which algorithm is used for finding a pattern in a text?

a)

Rabin-Karp algorithm

b)

Knuth-Morris-Pratt algorithm

c)

Naive string-matching algorithm

d)

All of the above

9.

What is the time complexity of a binary search algorithm in the average case?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(1)

10.

Which asymptotic notation gives the lower bound of an algorithm's time complexity?

a)

Big-O

b)

Big-Ω

c)

Big-Θ

d)

None

11.

What is the worst-case time complexity of an insertion sort algorithm?

a)

O(n)

b)

O(n^2)

c)

O(n log n)

d)

O(1)

12.

Which data structure is used in a hash table?

a)

A) Array

b)

B) Linked list

c)

C) Stack

d)

D) Queue

13.

What is the best-case time complexity of a quick sort algorithm?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(1)

14.

Which data structure is used in a merge sort algorithm?

a)

Array

b)

Linked list

c)

Stack

d)

Queue

15.

What is the time complexity of a Knuth-Morris-Pratt algorithm?

a)

O(n)

b)

O(n^2)

c)

O(n log n)

d)

O(1)

16.

Which algorithm is used for finding a pattern in a text?

a)

Rabin-Karp algorithm

b)

Knuth-Morris-Pratt algorithm

c)

Naive string-matching algorithm

d)

All of the above

17.

What is the time complexity of a binary search algorithm in the worst case?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(1)

18.

Which data structure is used in a binary search algorithm?

a)

A) Array

b)

B) Linked list

c)

C) Stack

d)

D) Queue

19.

What is the worst-case time complexity of a selection sort algorithm?

a)

O(n)

b)

O(n^2)

c)

O(n log n)

d)

O(1)

20.

Akhil is trying to find a specific book in a library. He knows that the library uses a hashing system to categorize its books. Which algorithm has a time complexity of O(1)?

a)

Linear search

b)

Binary search

c)

Hashing

d)

None

21.

What is the difference between best case, worst case, and average case analysis?

a)

Best case: average performance; Worst case: minimum performance; Average case: maximum performance.

b)

Best case: minimum performance; Worst case: maximum performance; Average case: expected performance.

c)

Best case: expected performance; Worst case: average performance; Average case: minimum performance.

d)

Best case: maximum performance; Worst case: expected performance; Average case: minimum performance.

22.

How does binary search improve upon linear search?

a)

Binary search can be applied to unsorted data without any preprocessing.

b)

Binary search is faster than linear search because it reduces the search space exponentially.

c)

Binary search requires more comparisons than linear search.

d)

Linear search is more efficient for large datasets than binary search.

23.

Describe the interpolation search algorithm and its use cases.

a)

Interpolation search is best used for uniformly distributed sorted arrays, particularly when the dataset is large and the values are evenly distributed.

b)

Interpolation search is primarily used for searching in linked lists.

c)

Interpolation search can be used for any type of data distribution.

d)

Interpolation search is effective for small, unsorted datasets.

24.

What is the naive string matching algorithm?

a)

A complex algorithm that uses dynamic programming to find substrings.

b)

The naive string matching algorithm is a straightforward method for finding a substring in a string by checking each position for a match.

c)

An algorithm that sorts the string before searching for the substring.

d)

A method that only checks the first character of the string for matches.

25.

How does the Rabin-Karp algorithm work?

a)

It employs a binary search method to locate patterns.

b)

The algorithm relies on sorting the text and patterns.

c)

The Rabin-Karp algorithm works by using hashing to efficiently search for patterns in a text.

d)

It uses brute force to find patterns in the text.

26.

What is the main advantage of the Knuth-Morris-Pratt algorithm over naive string matching?

a)

It has a linear time complexity compared to the naive algorithm's quadratic time complexity.

b)

It uses a brute-force approach for pattern matching.

c)

It requires more memory than the naive algorithm.

d)

It can only match patterns of fixed length.

27.

In what scenarios would you prefer interpolation search over binary search?

a)

When the data is sorted in descending order.

b)

When the data is uniformly distributed.

c)

When the data is highly skewed.

d)

When the dataset is small and unsorted.

28.

What is the role of the prefix table in the KMP algorithm?

a)

The prefix table determines the length of the pattern to be searched.

b)

The prefix table helps in skipping unnecessary comparisons in the KMP algorithm.

c)

The prefix table is used to store the final results of the KMP algorithm.

d)

The prefix table is a data structure that holds the frequency of characters in the pattern.

29.

What is the purpose of asymptotic notation in algorithm analysis?

a)

To measure the speed of computer hardware.

b)

To determine the exact runtime of an algorithm.

c)

To provide a graphical representation of algorithms.

d)

To describe the efficiency and growth rates of algorithms.

30.

Define time complexity and space complexity.

a)

Time complexity is the measure of time an algorithm takes to run, while space complexity is the measure of memory an algorithm uses.

b)

Space complexity is the speed at which an algorithm executes.

c)

Time complexity refers to the amount of data an algorithm can process.

d)

Time complexity is the total number of lines in an algorithm.