wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Data Structures and Algorithms Quiz

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.

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

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

2.

Which of the following is true about arrays in C/C++?

a)

Arrays can dynamically grow

b)

Indexing starts from 1

c)

Array size must be known at compile time

d)

Arrays are always initialized automatically

3.

What will arr[5] return if arr has only 5 elements?

a)

The 5th element

b)

The 6th element

c)

Compilation error

d)

Runtime error only in C++

4.

Which data structure is best for implementing multiple stacks in a single array?

a)

Queue

b)

Linked List

c)

Two pointer method

d)

Binary Tree

5.

What’s the default garbage value in uninitialized array elements (in C++)?

a)

0

b)

-1

c)

Random/Undefined

d)

NULL

6.

Which is true about singly linked lists?

a)

Nodes have pointers to both previous and next

b)

Searching is O(1)

c)

Insertion at head is O(1)

d)

Memory is contiguous

7.

What is stored in the last node of a singly linked list?

a)

Pointer to head

b)

NULL

c)

Next element

d)

Garbage

8.

What’s the biggest drawback of singly linked lists?

a)

Too much memory

b)

No dynamic sizing

c)

No backward traversal

d)

Cannot insert in middle

9.

Which is best suited for implementing undo functionality in apps?

a)

Queue

b)

Stack using linked list

c)

Array

d)

HashMap

10.

Time complexity to delete the last node in singly linked list (without tail pointer)?

a)

O(1)

b)

O(n)

c)

O(log n)

d)

O(n²)

11.

What does LIFO stand for?

a)

Last In First Out

b)

Last In Fast Out

c)

Longest In First Out

d)

Last In Final Out

12.

Which operation is not part of a basic stack?

a)

Push

b)

Pop

c)

Insert

d)

Peek

13.

Which data structure is used in recursive function calls?

a)

Queue

b)

Stack

c)

Tree

d)

Linked List

14.

What will happen if you pop from an empty stack?

a)

Program crashes

b)

Returns 0

c)

Stack is reset

d)

Inserts null

15.

Stack is most useful in which of the following?

a)

File handling

b)

Backtracking algorithms

c)

Hashing

d)

Sorting

16.

A college bus picks students using a circular queue system for 6 stops. At stop 6, the driver moves to stop 1 and continues pickup. What concept does this show?

a)

Linear queue

b)

Stack

c)

Circular queue

d)

Priority queue

17.

What is the front of the queue now after the following operations: enqueue(5); enqueue(10); enqueue(15); dequeue(); enqueue(20); dequeue(); dequeue();

a)

10

b)

20

c)

15

d)

Queue is empty

18.

In a perfect binary tree (all levels filled), what is the relationship between number of leaf nodes and total nodes?

a)

Leaves = n/ 2

b)

Leaves = (n+1)/ 2

c)

Leaves = log₂(n)

d)

Leaves = n - 1

19.

What does this function return? int count(Node* root) { if (!root) return 0; return 1 + count(root->left) + count(root->right); }

a)

Height of tree

b)

Number of edges

c)

Number of nodes

d)

Number of leaves

20.

What is the time complexity? void run(int n) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= 1000; j++) { // constant work } } }

a)

O(n × 1000)

b)

O(n²)

c)

O(1)

d)

O(n)