wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

DSA Quiz - 50 Questions

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What is the time complexity of accessing an element in an array using its index?

a)

O(n)

b)

O(log n)

c)

O(1)

d)

O(n log n)

2.

Which of the following algorithms is best for finding the second largest element in an unsorted array?

a)

Single traversal

b)

Bubble Sort

c)

Binary Search

d)

Merge Sort

3.

In string problems, which algorithm is used for pattern matching?

a)

Kruskal's Algorithm

b)

Rabin-Karp

c)

Dijkstra's Algorithm

d)

Prim's Algorithm

4.

If an array is rotated k times, what is the best way to find the minimum element?

a)

Linear search

b)

Binary search

c)

Hashing

d)

Merge sort

5.

What happens when you try to access an index that is out of bounds in an array?

a)

Prints 5

b)

IndexError

c)

Prints None

d)

Runtime Error

6.

Which is not true about linked lists compared to arrays?

a)

Easier insertion/deletion

b)

Faster random access

c)

Memory can be dynamic

d)

Can grow/shrink easily

7.

Which pointer makes a doubly linked list possible?

a)

Next pointer only

b)

Previous pointer only

c)

Both next & previous

d)

None

8.

Application of circular linked list?

a)

Undo operation

b)

Memory management

c)

Binary tree representation

d)

Array storage

9.

What will happen when you try to access data from a None head in a linked list?

a)

Prints None

b)

NullPointer Exception

c)

Prints 0

d)

No Error

10.

Which is the most suitable data structure to implement a music playlist?

a)

Stack

b)

Queue

c)

Circular Linked List

d)

Array

11.

Which is not an application of stack?

a)

Function calls

b)

Undo/Redo

c)

Expression evaluation

d)

Job Scheduling

12.

If a stack has push() and pop(), then queue can be implemented using:

a)

1 stack

b)

2 stacks

c)

3 stacks

d)

None

13.

Which data structure is used in Breadth First Search?

a)

Stack

b)

Queue

c)

Tree

d)

Heap

14.

What happens when you try to pop from an empty stack?

a)

Removes element

b)

IndexError

c)

Prints None

d)

Runtime Warning

15.

Which application uses priority queues?

a)

CPU scheduling

b)

Undo operation

c)

BFS traversal

d)

DFS traversal

16.

What is the time complexity of searching in a balanced BST?

a)

O(n)

b)

O(1)

c)

O(log n)

d)

O(n log n)

17.

Which traversal of a BST gives elements in sorted order?

a)

Preorder

b)

Postorder

c)

Inorder

d)

Level order

18.

What is the maximum number of nodes in a binary tree of height h?

a)

2^h - 1

b)

h^2

c)

log h

d)

h!

19.

Application of tries?

a)

Sorting

b)

Word Dictionary

c)

Heap construction

d)

Graph traversal

20.

This condition checks for a leaf node in a binary tree.

a)

Internal Node

b)

Leaf Node

c)

Root Node

d)

Height

21.

Which is not true about heaps?

a)

Complete Binary Tree

b)

Max element is at root (for max-heap)

c)

Useful for heap sort

d)

Provides O(1) search

22.

Application of heaps?

a)

Priority queue

b)

Hashing

c)

DFS traversal

d)

Linked list

23.

Hash collisions can be solved by:

a)

Chaining

b)

Deletion

c)

DFS

d)

BFS

24.

In a max-heap of n elements, what is the complexity to insert an element?

a)

O(n)

b)

O(1)

c)

O(log n)

d)

O(n log n)

25.

What is printed when you pop the smallest element from a heap?

a)

5

b)

2

c)

1

d)

3

26.

Which algorithm is used to find the shortest path in a weighted graph?

a)

Prim's

b)

Kruskal's

c)

Dijkstra's

d)

DFS

27.

Which algorithm is used for minimum spanning tree?

a)

Dijkstra's

b)

Kruskal's

c)

BFS

d)

DFS

28.

Which data structure is used in DFS?

a)

Stack

b)

Queue

c)

Linked List

d)

Heap

29.

This graph is directed cyclic.

a)

Directed cyclic

b)

Undirected

c)

Acyclic

d)

Tree

30.

Which is an application of graph?

a)

Maps & Navigation

b)

CPU Scheduling

c)

String reversal

d)

Sorting numbers

31.

Which is the fastest sorting algorithm on average?

a)

Bubble sort

b)

Quick sort

c)

Selection sort

d)

Insertion sort

32.

Which sorting guarantees O(n log n) worst case?

a)

Merge Sort

b)

Quick Sort

c)

Heap Sort

d)

Bubble Sort

33.

Binary search works only on:

a)

Unsorted arrays

b)

Linked Lists

c)

Sorted arrays

d)

Hash Tables

34.

What is the best case complexity of Quick Sort?

a)

O(n log n)

b)

O(n)

c)

O(n^2)

d)

O(1)

35.

What is printed when you check if an element is in an array?

a)

Found

b)

Error

c)

Not Found

d)

None

36.

Which problem is solved by Dynamic Programming?

a)

Traveling Salesman

b)

Bubble Sort

c)

Heap Sort

d)

Binary Search

37.

Coin Change problem uses:

a)

Greedy always

b)

DP always

c)

DFS

d)

Stack

38.

Which is a greedy algorithm?

a)

Kruskal's

b)

Floyd-Warshall

c)

Bellman-Ford

d)

DP

39.

This initializes DP array for Fibonacci.

a)

Fibonacci

b)

Sorting

c)

DFS

d)

Heap

40.

Knapsack problem solved by greedy when:

a)

0/1 Knapsack

b)

Fractional Knapsack

c)

Subset Sum

d)

Graph coloring

41.

Which is the best data structure for LRU cache?

a)

Stack

b)

LinkedList + HashMap

c)

Queue

d)

Tree

42.

Huffman coding is used in:

a)

Searching

b)

Compression

c)

Encryption

d)

Graph traversal

43.

Which traversal is used in topological sorting?

a)

DFS

b)

BFS

c)

Inorder

d)

Preorder

44.

Which problem cannot be solved by greedy?

a)

Minimum Spanning Tree

b)

Fractional Knapsack

c)

0/1 Knapsack

d)

Job Scheduling

45.

This code prevents infinite loops.

a)

Infinite loop

b)

Memory allocation

c)

Stack overflow

d)

Sorting

46.

What's the complexity of BFS in a graph with V vertices and E edges?

a)

O(V)

b)

O(E)

c)

O(V+E)

d)

O(V*E)

47.

Which is an amortized O(1) operation in arrays?

a)

Insert at end

b)

Insert at start

c)

Delete middle

d)

Binary Search

48.

A red-black tree is a type of:

a)

Balanced BST

b)

Heap

c)

Graph

d)

Hash Table

49.

In recursion, stack overflow occurs due to:

a)

Too many nested calls

b)

Too many loops

c)

Large arrays

d)

Linked lists

50.

What is the output of the factorial function for 5?

a)

0

b)

120

c)

24

d)

Error