Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CSA06 DESIGN AND ANALYSIS OF ALGORITHMS - Worksheet

Total questions: 51

Worksheet time: 26mins

Name
Class
Date
1.

Consider the recursive function: int mystery(int n) { if (n <= 1) return 1; else return mystery(n - 1) + mystery(n - 1); } What is the time complexity of mystery(n)?

a)

O(n)

b)

O(n²)

c)

O(2ⁿ)

d)

O(log n)

2.

What is the maximum number of comparisons needed to search an element in a sorted array of 1000 elements using binary search?

a)

10

b)

9

c)

100

d)

1000

3.

Which of the following problems is most suitable for a greedy approach?

a)

Longest Common Subsequence

b)

Matrix Chain Multiplication

c)

Fractional Knapsack

d)

0/1 Knapsack

4.

Which of the following functions grows faster than f(n) = n log n?

a)

f(n) = n

b)

f(n) = log n

c)

f(n) = n²

d)

f(n) = √n

5.

Given the two recursive algorithms: A1: T(n) = T(n - 1) + n A2: T(n) = 2T(n/2) + n Which algorithm has a better (lower) asymptotic time complexity?

a)

A) A1

b)

B) A2

c)

C) Both same

d)

D) Depends on implementation

6.

For the function f(n) = 3n log n + 2n + 100, what is the dominant term that defines its time complexity?

a)

3n log n

b)

2n

c)

100

d)

None

7.

What is the total number of comparisons done by selection sort in the worst case on an array of size n?

a)

O(n log n)

b)

O(n²)

c)

O(n)

d)

O(log n)

8.

Consider the recurrence T(n) = 3T(n/4) + n. What is the time complexity using the Master Theorem?

a)

O(n)

b)

O(n log n)

c)

O(n1.2)O(n^{1.2})

d)

9.

Count the number of operations (in Big-O) for the code: for (int i = 0; i < n; i++) for (int j = i; j < n; j++) cout << i << j;

a)

O(n)

b)

O(n2)O(n^2)

c)

O(n log n)

d)

O(n3)O(n^3)

10.

What is the best possible worst-case time complexity for any comparison-based sorting algorithm?

a)

O(n)

b)

O(n log n)

c)

O(n2)O(n^2)

d)

O(log n)

11.

Which of the following strategies does binary search use?

a)

Brute force

b)

Divide and conquer

c)

Greedy

d)

Dynamic programming

12.

Which of the following is an example of an optimization problem?

a)

Finding if an element exists in an array

b)

Finding the shortest path in a graph

13.

Let f(n) = 2n2+3n+42n^2 + 3n + 4 . Which of the following is the tightest upper bound for f(n)?

a)

O(n)

b)

O(n2)O(n^2)

c)

O(n3)O(n^3)

d)

Θ(n log n)

14.

Which of the following statements is TRUE?

a)

f(n) = Θ(g(n)) implies f(n) = O(g(n))

b)

f(n) = O(g(n)) implies f(n) = Θ(g(n))

c)

f(n) = Ω(g(n)) implies f(n) = Θ(g(n))

d)

None of the above

15.

Consider the recurrence relation: T(n) = 2T(n/2) + n. What is the time complexity?

a)

O(n)

b)

O(n log n)

c)

O(log n)

d)

O(n2)O(n^2)

16.

Which of the following is NOT part of the algorithm analysis framework?

a)

Input size

b)

Primitive operations

c)

Execution time

d)

Variable naming conventions

17.

Arrange the following efficiency classes in increasing order of growth:

a)

O(1)O(1) , O(logn)O(log n) , O(n)O(n) , O(n2)O(n^2)

b)

O(n2)O(n^2) , O(n)O(n) , O(logn)O(log n) , O(1)O(1)

c)

O(n)O(n) , O(1)O(1) , O(n2)O(n^2) , O(logn)O(log n)

d)

O(logn)O(log n) , O(n2)O(n^2) , O(1)O(1) , O(n)O(n)

18.

Arrange the following in increasing order of their asymptotic complexity:

a)

A) 3 < 1 < 2 < 4

b)

B) 1 < 3 < 2 < 4

c)

C) 3 < 2 < 1 < 4

d)

D) 3 < 1 < 2 < 4

19.

Consider the recurrence: T(n) = T(n - 1) + 1, with T(1) = 1. What is T(n)?

a)

O(n log n)

b)

O(n)

c)

O(1)

d)

O(n2)O(n^2)

20.

Which of the following algorithms has the best worst-case time complexity for sorting?

a)

Merge Sort

b)

Quick Sort

c)

Insertion Sort

d)

Bubble Sort

21.

Which of the following problems can be efficiently solved using the divide and conquer paradigm?

a)

Finding the majority element in an array

b)

Graph coloring

c)

Longest increasing subsequence

d)

All-pairs shortest path

22.

A coin system has denominations {1, 3, 4}. What is the minimum number of coins required to make amount 6?

a)

2

b)

3

c)

1

d)

4

23.

You are given a function that solves the Tower of Hanoi problem. For n disks, how many recursive calls (excluding the initial call) are made?

a)

2n−12^n - 1

b)

2n2^n

c)

2(n−1)2^{(n-1)}

d)

n

24.

Which of the following problems is most suitable for solving using backtracking?

a)

Finding GCD of two numbers

b)

Sudoku solving

c)

Binary Search

d)

Merge Sort

25.

Determining if a Hamiltonian path exists in a graph is an example of which problem type?

a)

NP-complete problem

b)

P problem

c)

Tractable problem

d)

Undecidable problem

26.

Which of the following is a problem with a yes/no answer?

a)

Decision problem

b)

Optimization problem

c)

Search problem

d)

Enumeration problem

27.

What will be the output of this recursive function fun(3)?

a)

A) 1 2 3

b)

B) 3 2 1

c)

C) 2 3 1

d)

D) 1 3 2

28.

Which of the following functions belong to the same class of problems in terms of efficiency class (i.e., same growth trend)?

a)

Matrix Multiplication and Tower of Hanoi

b)

Insertion Sort and Selection Sort

c)

Merge Sort and Linear Search

d)

Quick Sort and Bubble Sort

29.

Which of the following is typically solved using brute-force?

a)

Subset sum problem

b)

Primality testing for large numbers

c)

Fibonacci number computation

d)

GCD of two numbers

30.

Which of the following is NOT a valid algorithm design strategy?

a)

A) Divide and Conquer

b)

B) Greedy

31.

The 8-Queens Problem is best solved using which of the following techniques?

a)

Divide and Conquer

b)

Backtracking

c)

Dynamic Programming

d)

Greedy Method

32.

In a sorted array, which method guarantees locating an element if it exists and the array has duplicates?

a)

Jump Search

b)

Linear Search from start

c)

Modified Binary Search to find first/last occurrence

d)

Hashing

33.

Determining whether a graph has a cycle is best described as which type of problem?

a)

Enumeration Problem

b)

Optimization Problem

c)

Decision Problem

d)

Search Problem

34.

What does the following code fragment do? for (int i = 0; i < n; i++) { if (arr[i] == key) return i; }

a)

Binary search

b)

Hashing

c)

Linear search

d)

Jump search

35.

Q34. Which of the following problems can be simulated using a stack, mimicking recursion?

a)

Evaluating expressions using postfix notation

b)

Sorting an array using bubble sort

c)

Finding the shortest path in a graph using Dijkstra's algorithm

d)

Searching an element in a sorted array using binary search

36.

You need to solve a puzzle where the goal state depends on achieving smaller subgoals that resemble the original problem. Which technique are you most likely applying?

a)

Backtracking

b)

Greedy

c)

Divide and Conquer

d)

Brute Force

37.

A recursive algorithm solves a problem by breaking it into two subproblems of size n - 1 each. What is the total number of subproblem calls for input n = 4?

a)

4

b)

8

c)

15

d)

16

38.

You are solving a maze and need to find any path from the start to the goal. You try all possible directions from each junction until the goal is reached. What is this method?

a)

Depth-First Search

b)

Breadth-First Search

c)

Greedy Selection

d)

Dynamic Expansion

39.

You are solving the Tower of Hanoi problem with 3 disks. What is the minimum number of steps required?

a)

6

b)

7

c)

8

d)

9

40.

A problem is solved by recursively reducing input size by 1 and combining each result additively. This approach is best described as:

a)

Greedy

b)

Divide and Conquer

c)

Recurrence Accumulation

d)

Dynamic Choice

41.

You're tracing a recursive function where the first thing it does is call itself with n - 1, and then prints n. What will be the order of printed values for input n = 3?

a)

3 2 1

b)

1 2 3

c)

2 3 1

d)

3 1 2

42.

You are designing an algorithm to solve a Sudoku puzzle by filling empty cells with valid digits and backtracking when a dead end is reached. What is the search tree's depth for a grid with 10 empty cells?

a)

9

b)

10

c)

100

d)

Depends on puzzle structure

43.

You are given a chessboard and must find all positions where placing a queen will not attack others already placed. Which technique is most suited to solve the n-Queens problem?

a)

Brute Force Enumeration

b)

Backtracking with constraint checks

c)

Heuristic Greedy filling

d)

Divide and Conquer on board halves

44.

If a recursive algorithm branches into 3 subproblems at each level, how many subproblems are generated for depth d = 3?

a)

9

b)

12

c)

13

d)

27

45.

A recursive algorithm prints a number before and after calling itself on a smaller value. What pattern is expected in its output for input n = 2?

a)

A) 2 1 1 2

b)

B) 1 2 2 1

c)

C) 1 1 2 2

d)

D) 2 2 1 1

46.

A recursive problem is defined such that for input n, it makes one call to n - 1 and then performs a single constant operation. How many operations (excluding base case) are done for input n = 5?

a)

4

b)

5

c)

6

d)

10

47.

How many different permutations can be generated for a password consisting of 4 distinct characters?

a)

16

b)

24

c)

256

d)

120

48.

A recursive algorithm solving a decision problem doubles the number of subproblems at each level. How many subproblem instances are generated (total) for input level 4?

a)

4

b)

8

c)

15

d)

16

49.

A recursive problem reduces the input by 1 until it reaches 0. At each step, it performs two constant-time operations after the recursive call. How many operations are performed for n = 4?

a)

4

b)

8

50.

In a solution space tree, what technique is used to avoid unnecessary exploration of branches that cannot lead to a valid solution?

a)

Preprocessing

b)

Pruning

c)

Memoization

d)

Expansion

51.

You're solving two recursive problems: Problem A: One subproblem per level Problem B: Two subproblems per level Which will likely result in more recursive calls for the same input size?

a)

A

b)

B

c)

Both are equal

d)

Cannot be determined without base case