wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz-2

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.

The time complexity of finding the maximum sum subarray using Kadane’s Algorithm is (a)   .

2.

You are given a sorted array and need to find if there exists a pair with sum equal to k. The best approach is:

a)

Brute force with nested loops O(n²)

b)

Sort and Binary Search O(n log n)

c)

Two pointer approach O(n)

d)

Hash map approach O(n)

3.

The two pointer technique is most effective when the array is (a)   .

4.

Which of the following is NOT a valid use case of a hash map?

a)

Counting frequency of elements

b)

Checking duplicates in O(n)

c)

Maintaining order of elements in O(1)

d)

All the above

5.

In Python, the hash map is implemented as a (a)   data structure.

6.

Given two strings s and t, check if they are anagrams. The most efficient approach uses:

a)

Sorting both strings – O(n log n)

b)

Hash map frequency count – O(n)

c)

Brute force checking all permutations – O(n!)

d)

Binary search on characters

7.

To solve the Two Sum problem efficiently, we use a (a)   to store visited numbers.

8.

The time complexity of push and pop operations in a stack is (a)   .

9.

You are given an infix expression. Which of the following data structures is most suitable for converting it into postfix?

a)

Queue

b)

Stack

c)

Hash Map

d)

Linked List

10.

The data structure used in the implementation of recursion in programming languages is (a)   .

11.

Which of the following allows efficient insertions and deletions at both ends but not random access?

a)

Array

b)

Linked List

c)

Hash Map

d)

Stack

12.

In a singly linked list, each node contains data and a pointer to the (a)   .

13.

What is the time complexity of searching for an element in a singly linked list of size n?

a)

O(1)

b)

O(log n)

c)

O(n)

d)

O(n log n)

14.

Can you detect a cycle in a linked list in O(n) time and O(1) space using Floyd’s Cycle Detection Algorithm (Tortoise and Hare method)?

a)

True

b)

False

15.

You need to reverse a linked list in-place. What is the time and space complexity?

a)

O(n), O(n)

b)

O(n), O(1)

c)

O(log n), O(1)

d)

O(1), O(1)

16.

To check if two strings are anagrams, which approaches are valid?

a)

Sort both strings and compare

b)

Compare frequency count of characters using hash map

c)

Check if both strings are palindromes

d)

Use XOR of all characters

17.

Which problems can be solved efficiently using the two pointer technique?

a)

Pair sum in sorted array

b)

Trapping Rain Water

c)

Reversing a linked list

d)

Removing duplicates from sorted array

18.

In sliding window or two pointer problems, what can pointers represent?

a)

Left and right boundaries of a window

b)

Fast and slow traversal speeds

c)

Start and end of valid substring

d)

Indices for recursion backtracking

19.

Which of the following problems can be solved efficiently using hash maps?

a)

Two Sum

b)

Detecting cycle in linked list

c)

Grouping anagrams

d)

Finding subarray with given sum

20.

Which statements are true about hash maps?

a)

In Python, lists are implemented as hash maps

b)

Average time complexity for lookup is O(1)

c)

Worst case time complexity for lookup is O(n)

d)

Collisions can be resolved using chaining