wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

DAA Sessional

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

If an array has n elements and you perform one right rotation of the first k elements, how many swaps are required using the EXCHANGE(p, q) function?

a)

k − 1

b)

k

c)

k + 1

d)

Depends on array contents

2.

When computing prefix sums of an array (where prefixSum[i] represents Sum of elements from index 0 to i) , what is the time complexity if the algorithm is implemented iteratively?

a)

O(log n)

b)

O(n)

c)

O(n log n)

d)

O(1)

3.

What is the time complexity of finding the second smallest element in an unsorted array of size n?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n²)

4.

The worst-case of Quick Sort occurs when the pivot always becomes:

a)

Middle element

b)

Largest or smallest element

c)

Random element

d)

Median

5.

What is the time complexity of Binary Search in a sorted array?

a)

O(n)

b)

O(n log n)

c)

O(log n)

d)

O(1)

6.

Quick Sort exhibits worst-case behavior when:

a)

The array is randomly arranged

b)

The pivot divides array into equal halves

c)

The partitioning produces subproblems of size n-1 and 0

d)

The array has duplicate elements

7.

In the best-case scenario, Quick Sort partition produces subproblems of size:

a)

n and 0

b)

At most n/2 each

c)

n-1 and 1

d)

n/3 and 2n/3

8.

What is the time complexity of building a heap from an unsorted array of n elements?

a)

O(n)

b)

O(n log n)

c)

O(log n)

d)

O(n²)

9.

What is the time complexity of inserting an element into a heap?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n log n)

10.

In the Fractional Knapsack problem, items should be sorted based on:

a)

Weight

b)

Profit

c)

Profit/Weight ratio

d)

Weight/Profit ratio

11.

Huffman coding assigns:

a)

Fixed length codes to all characters

b)

Variable length codes based on frequency

c)

Random codes to characters

d)

Alphabetically ordered codes

12.

What is the time complexity of Prim's algorithm using a Min-Priority Queue?

a)

O(V)

b)

O(E)

c)

O(E log V)

d)

O(V²)

13.

Kruskal's algorithm uses which data structure to detect cycles?

a)

Stack

b)

Queue

c)

Disjoint Set (Union-Find)

d)

Binary Tree

14.

Dijkstra's algorithm works correctly only when:

a)

Graph has cycles

b)

All edge weights are non-negative

c)

Graph is disconnected

d)

All edge weights are equal

15.

In Matrix Chain Multiplication, what does the M-table store?

a)

Matrix dimensions

b)

Minimum number of scalar multiplications

c)

Order of matrix multiplication

d)

Result of multiplication

16.

What does the S-table store in Matrix Chain Multiplication?

a)

Scalar multiplication count

b)

Matrix sizes

c)

Split position for optimal parenthesization

d)

Final result

17.

The time complexity of finding the Longest Common Subsequence (LCS) using dynamic programming is:

a)

O(m + n)

b)

O(m × n)

c)

O(m² + n²)

d)

O(2^n)

18.

Floyd-Warshall algorithm finds:

a)

Single source shortest path

b)

All pairs shortest path

c)

Minimum spanning tree

d)

Maximum flow

19.

The time complexity of Floyd-Warshall algorithm is:

a)

O(V²)

b)

O(V³)

c)

O(V log V)

d)

O(E log V)

20.

Dynamic programming is applicable when a problem has:

a)

Greedy choice property only

b)

Optimal substructure only

c)

Both optimal substructure and overlapping subproblems

d)

Neither optimal substructure nor overlapping subproblems

21.

In an undirected graph where each edge weighs 2 units, BFS can find:

a)

Maximum path

b)

Shortest path

c)

Minimum spanning tree

d)

Strongly connected components

22.

The expected time complexity of Randomized Quick Sort is:

a)

O(n)

b)

O(n log n)

c)

O(n²)

d)

O(log n)

23.

What is the main difference between Las Vegas and Monte Carlo algorithms?

a)

Las Vegas always gives correct answer, Monte Carlo may not

b)

Monte Carlo always gives correct answer, Las Vegas may not

c)

Both always give correct answers

d)

Neither gives correct answers

24.

The cost model for incrementing a binary counter counts:

a)

Total number of bits

b)

Number of bits that need to be flipped

c)

Number of zeros in the counter

d)

Position of highest bit

25.

The worst-case time complexity of Insertion Sort is:

a)

O(n)

b)

O(n log n)

c)

O(n²)

d)

O(log n)

26.

A heap is always:

a)

Complete binary tree

b)

Balanced binary tree

c)

Binary search tree

d)

AVL tree

27.

The time complexity of building a Huffman Tree with n symbols is:

a)

O(n log n)

b)

O(n²)

c)

O(log n)

d)

O(n)

28.

The Longest Common Subsequence problem differs from substring problem because:

a)

Elements must be consecutive

b)

Order must be maintained but not continuity

c)

Case sensitivity applies

d)

None of the above

29.

In a max-heap of n elements, the largest and smallest element positions are:

a)

Root and leaf

b)

Leaf and root

c)

Both at root

d)

Both at leaves

30.

The amortized cost of incrementing a binary counter of k bits over n operations is:

a)

O(1)

b)

O(k)

c)

O(log n)

d)

O(n)