wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DSA (QUIZ 7) -Greedy Algorithms and Complexity Analysis

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the key principle of a greedy algorithm?

a)

Explore all possible combinations

b)

Always pick the global optimum

c)

Make the best local choice at each step

d)

Use recursion to reduce steps

2.

Which of the following problems can be solved optimally using a greedy algorithm?

a)

0/1 Knapsack

b)

Activity Selection

c)

Traveling Salesman

d)

Longest Common Subsequence

3.

What is the greedy choice in the Coin Change Problem using denominations of 1, 5, and 10 to make 27?

a)

Use only 1s

b)

Use only 5s

c)

Use as many 10s, then 5s, then 1s

d)

Use 3 × 9 coins

4.

Why does the Huffman coding algorithm follow the greedy approach?

a)

It picks the longest string first

b)

It chooses the lowest frequency characters first

c)

It tries all possible encodings

d)

It encodes based on the alphabet

5.

What is a common feature of problems that work well with greedy algorithms?

a)

The problem requires backtracking

b)

The solution must be recursive

c)

The problem has an optimal substructure

d)

It needs matrix multiplication

6.

What is the time complexity of a function that runs a single loop over a list of `n` elements?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

7.

Which time complexity grows the fastest as input size increases?

a)

O(n)

b)

O(log n)

c)

O(n log n)

d)

O(2n)

8.

Binary search works efficiently because it:

a)

Scans the entire list

b)

Uses nested loops

c)

Reduces the search space by half

d)

Increases the list size

9.

If you have a nested loop where both loops run `n` times, what is the time complexity?

a)

O(n)

b)

O(log n)

c)

O(n²)

d)

O(n³)

10.

Which of the following best describes Big O notation?

a)

Best-case performance

b)

Average-case performance

c)

Worst-case performance

d)

Minimum input size

11.

What does space complexity measure?

a)

Execution time

b)

Number of loops

c)

Memory used during execution

d)

Number of variables in source code

12.

What is the space complexity of this function?

a)

O(n)

b)

O(n²)

c)

O(1)

d)

O(log n)

13.

Which type of algorithm typically uses more space due to the call stack?

a)

Iterative

b)

Sorting

c)

Recursive

d)

Greedy

14.

If an algorithm creates a new array of the same size as the input array, what is the space complexity?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

15.

Which function has a quadratic space complexity?

a)

Loop that sums numbers

b)

Function that creates all pairs from a list

c)

Single loop with one variable

d)

Accessing an element from an array