NEW
Font size
WorksheetsData Structures and Algorithms Quiz
Total questions: 20
Worksheet time: 15mins
What is the time complexity of accessing an element in an array by index?
O(1)
O(n)
O(log n)
O(n²)
Which of the following is true about arrays in C/C++?
Arrays can dynamically grow
Indexing starts from 1
Array size must be known at compile time
Arrays are always initialized automatically
What will arr[5] return if arr has only 5 elements?
The 5th element
The 6th element
Compilation error
Runtime error only in C++
Which data structure is best for implementing multiple stacks in a single array?
Queue
Linked List
Two pointer method
Binary Tree
What’s the default garbage value in uninitialized array elements (in C++)?
0
-1
Random/Undefined
NULL
Which is true about singly linked lists?
Nodes have pointers to both previous and next
Searching is O(1)
Insertion at head is O(1)
Memory is contiguous
What is stored in the last node of a singly linked list?
Pointer to head
NULL
Next element
Garbage
What’s the biggest drawback of singly linked lists?
Too much memory
No dynamic sizing
No backward traversal
Cannot insert in middle
Which is best suited for implementing undo functionality in apps?
Queue
Stack using linked list
Array
HashMap
Time complexity to delete the last node in singly linked list (without tail pointer)?
O(1)
O(n)
O(log n)
O(n²)
What does LIFO stand for?
Last In First Out
Last In Fast Out
Longest In First Out
Last In Final Out
Which operation is not part of a basic stack?
Push
Pop
Insert
Peek
Which data structure is used in recursive function calls?
Queue
Stack
Tree
Linked List
What will happen if you pop from an empty stack?
Program crashes
Returns 0
Stack is reset
Inserts null
Stack is most useful in which of the following?
File handling
Backtracking algorithms
Hashing
Sorting
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?
Linear queue
Stack
Circular queue
Priority queue
What is the front of the queue now after the following operations: enqueue(5); enqueue(10); enqueue(15); dequeue(); enqueue(20); dequeue(); dequeue();
10
20
15
Queue is empty
In a perfect binary tree (all levels filled), what is the relationship between number of leaf nodes and total nodes?
Leaves = n/ 2
Leaves = (n+1)/ 2
Leaves = log₂(n)
Leaves = n - 1
What does this function return? int count(Node* root) { if (!root) return 0; return 1 + count(root->left) + count(root->right); }
Height of tree
Number of edges
Number of nodes
Number of leaves
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 } } }
O(n × 1000)
O(n²)
O(1)
O(n)
