Data Structures Implementation # MCQs Practice set

Q.1 Which data structure is most suitable for implementing recursion?

Queue
Stack
Linked List
Graph
Explanation - Recursion uses the call stack internally, so a stack is the most suitable data structure to implement it.
Correct answer is: Stack

Q.2 Which of the following operations can be efficiently performed using a linked list?

Random access
Insertion at beginning
Binary search
Indexing by position
Explanation - Linked lists allow O(1) insertion at the beginning, unlike arrays which require shifting elements.
Correct answer is: Insertion at beginning

Q.3 In a singly linked list, deleting a node at the end requires:

O(1) time
O(n) time
O(log n) time
O(n^2) time
Explanation - Since singly linked lists don’t have a previous pointer, we must traverse the entire list to find the node before the last to delete the last node.
Correct answer is: O(n) time

Q.4 Which data structure is best for implementing a priority queue?

Array
Stack
Heap
Linked List
Explanation - Heaps (usually a binary heap) provide efficient insertion and deletion operations for priority queues, with O(log n) complexity.
Correct answer is: Heap

Q.5 In a circular queue implemented using an array, the queue is full when:

front == rear
(rear + 1) % size == front
front == 0
rear == size-1
Explanation - In a circular queue, the next position of rear equals front when the queue is full.
Correct answer is: (rear + 1) % size == front

Q.6 Which of the following is NOT a disadvantage of an array compared to a linked list?

Fixed size
Expensive insertion/deletion at the middle
Contiguous memory allocation
Ease of random access
Explanation - Ease of random access is an advantage of arrays, not a disadvantage.
Correct answer is: Ease of random access

Q.7 In a doubly linked list, which operation is faster than in a singly linked list?

Traversal from head to tail
Insertion at beginning
Deletion of a given node
Searching for a value
Explanation - Doubly linked lists store previous pointers, so deletion of a given node does not require traversal from the head.
Correct answer is: Deletion of a given node

Q.8 Which of the following is true for a stack implemented using a linked list?

Overflow occurs when memory is full
Underflow occurs when stack has one element
Accessing middle elements is efficient
It cannot dynamically grow
Explanation - A linked list based stack dynamically grows, so overflow occurs only when system memory is exhausted.
Correct answer is: Overflow occurs when memory is full

Q.9 Which data structure is most suitable for implementing undo functionality in applications?

Queue
Stack
Heap
Binary Tree
Explanation - Undo operations follow LIFO order, which is naturally implemented by a stack.
Correct answer is: Stack

Q.10 In which scenario would a hash table provide the most efficient operations?

Sequential access of elements
Searching by key
Maintaining sorted order
Traversing all elements
Explanation - Hash tables provide O(1) average time complexity for searching by key.
Correct answer is: Searching by key

Q.11 What is the time complexity of inserting an element at the end of a singly linked list if a tail pointer is maintained?

O(1)
O(n)
O(log n)
O(n^2)
Explanation - Maintaining a tail pointer allows direct access to the end, so insertion is O(1).
Correct answer is: O(1)

Q.12 Which data structure can be used to implement a deque?

Stack
Queue
Linked List
Graph
Explanation - A deque allows insertion and deletion at both ends, which can be efficiently implemented using a doubly linked list.
Correct answer is: Linked List

Q.13 In an adjacency list representation of a graph, the space complexity is:

O(V^2)
O(E)
O(V+E)
O(log V)
Explanation - An adjacency list stores all vertices and edges explicitly, resulting in O(V+E) space complexity.
Correct answer is: O(V+E)

Q.14 Which operation is faster in an array compared to a linked list?

Insertion at beginning
Deletion at middle
Random access
Insertion at middle
Explanation - Arrays allow direct access via index in O(1), whereas linked lists require traversal.
Correct answer is: Random access

Q.15 What is the main advantage of a circular linked list over a singly linked list?

Random access
Ease of insertion at head
Efficient traversal from any node
Simpler implementation
Explanation - A circular linked list allows traversal starting from any node and looping back to it.
Correct answer is: Efficient traversal from any node

Q.16 Which of the following is a disadvantage of using a dynamic array over a linked list?

Contiguous memory allocation
Expensive insertion at the middle
Access by index
Flexibility in size
Explanation - Dynamic arrays require shifting elements for middle insertions, unlike linked lists.
Correct answer is: Expensive insertion at the middle

Q.17 Which of these is an application of a queue?

Function call management
Job scheduling in OS
Undo operation
Priority management
Explanation - Queues operate on FIFO principle, suitable for scheduling tasks in operating systems.
Correct answer is: Job scheduling in OS

Q.18 Which is true about stack overflow?

Occurs when memory is full
Occurs when popping from an empty stack
Occurs when stack is implemented using a linked list
Occurs due to circular references
Explanation - Stack overflow occurs when memory allocated to the stack is exhausted.
Correct answer is: Occurs when memory is full

Q.19 What is the worst-case time complexity of searching an element in a linked list?

O(1)
O(log n)
O(n)
O(n log n)
Explanation - Linked lists do not support direct indexing, so searching requires traversal of up to n elements.
Correct answer is: O(n)

Q.20 In a doubly linked list, to delete a given node, what is required?

Pointer to previous node only
Pointer to next node only
Pointer to the node itself
Traversal from head always
Explanation - In a doubly linked list, deletion can be done in O(1) if we have a pointer to the node to be deleted.
Correct answer is: Pointer to the node itself

Q.21 Which data structure is most suitable for implementing a cache?

Stack
Queue
Deque
Hash Table with Doubly Linked List
Explanation - LRU caches are efficiently implemented using a hash table for quick lookup and a doubly linked list to track order.
Correct answer is: Hash Table with Doubly Linked List

Q.22 Which representation of a graph is best for a sparse graph?

Adjacency matrix
Adjacency list
Edge list
Incidence matrix
Explanation - Adjacency lists are space-efficient for sparse graphs, storing only existing edges.
Correct answer is: Adjacency list

Q.23 Which operation is O(1) in a circular queue?

Enqueue
Dequeue
Check if full
All of the above
Explanation - All main operations in a circular queue—enqueue, dequeue, and checking full/empty—can be done in O(1) time.
Correct answer is: All of the above

Q.24 In an array implementation of a stack, popping an element is:

O(1)
O(n)
O(log n)
O(n^2)
Explanation - Popping from the top of an array-based stack requires no shifting, so it's O(1).
Correct answer is: O(1)