What is the index of the first element in an array?
- A
0
- B
1
- C
-1
- D
Depends on language
Master Data Structures with 130+ curated MCQs covering arrays, linked lists, stacks, queues, trees, graphs, hashing, sorting, and searching. Perfect for exams, interviews, and placements.
What is the index of the first element in an array?
0
1
-1
Depends on language
Which of the following operations is efficient on an array?
Access by index
Insertion at the beginning
Deletion from the middle
Searching unsorted
What is a multidimensional array?
An array of arrays
A one-dimensional array
A dynamic array
A sorted array
What is the time complexity of searching an element in an unsorted array?
O(1)
O(log n)
O(n)
O(n^2)
What is the time complexity of inserting an element at the end of a dynamic array?
O(1) amortized
O(n)
O(log n)
O(n^2)
Which of the following is true about a circular array?
It uses a fixed-size buffer
It can be implemented using modulo
Both A and B
It is a linked list
What is a linked list?
A linear data structure where elements are stored at contiguous memory locations
A linear data structure where elements are stored at non-contiguous memory locations
A data structure that uses hashing
A data structure that uses trees
What is the time complexity of inserting a node at the beginning of a singly linked list?
O(1)
O(n)
O(log n)
O(n^2)
What is the time complexity of searching for an element in a singly linked list?
O(1)
O(log n)
O(n)
O(n^2)
What is a doubly linked list?
Each node has two pointers: next and prev
Each node has only one pointer
It is a circular list
It is a sorted list
What is the advantage of a doubly linked list over a singly linked list?
Can traverse in both directions
Uses less memory
Faster insertion
Easier to implement
What is a circular linked list?
The last node points to the first node
The list has no end
Both A and B
It uses circular array
What is a stack?
A data structure that follows LIFO (Last In First Out)
A data structure that follows FIFO (First In First Out)
A data structure that stores elements in sorted order
A data structure that uses hashing
Which operation is used to add an element to a stack?
push
pop
peek
enqueue
Which operation is used to remove an element from a stack?
pop
push
top
dequeue
What is the time complexity of push and pop operations in a stack implemented using an array?
O(1)
O(n)
O(log n)
O(n^2)
Which of the following is a common application of stacks?
Expression evaluation
Function call management
Undo operations
All of the above
What is the meaning of stack overflow?
Trying to push onto a full stack
Trying to pop from an empty stack
Stack memory is corrupted
Stack pointer is lost
What is a queue?
A data structure that follows FIFO (First In First Out)
A data structure that follows LIFO
A data structure that sorts elements
A data structure for priority
Which operation is used to add an element to a queue?
enqueue
dequeue
push
pop
Which operation is used to remove an element from a queue?
dequeue
enqueue
front
rear
What is a circular queue?
A queue where the last position wraps around to the first
A queue implemented using a circular linked list
A queue with no end
A queue that uses priority
What is a priority queue?
Each element has a priority; higher priority elements are dequeued first
Elements are enqueued in priority order
It is implemented using a heap
All of the above
What is the time complexity of enqueue and dequeue in a simple queue implemented with an array?
O(1)
O(n)
O(log n)
O(n^2)
What is a tree data structure?
A hierarchical data structure with a root and child nodes
A linear data structure
A cyclic data structure
A data structure with no ordering
What is a binary tree?
Each node has at most two children
Each node has exactly two children
Each node has any number of children
It is a tree with only one node
What is a binary search tree (BST)?
Left child < parent < right child
Left child > parent > right child
All nodes are equal
No ordering is maintained
What is the time complexity of searching in a balanced BST?
O(1)
O(log n)
O(n)
O(n^2)
What is a tree traversal?
Visiting each node in the tree in a specific order
Adding nodes to the tree
Removing nodes from the tree
Finding the height of the tree
What is the difference between a full binary tree and a complete binary tree?
Full: every node has 0 or 2 children; Complete: all levels filled except possibly last
Full: all levels filled; Complete: every node has 2 children
They are the same
Full is a subset of complete
What is a heap data structure?
A specialized tree-based structure that satisfies the heap property
A queue with priorities
A binary tree with no ordering
A linked list
What is a min-heap?
Parent is less than or equal to children
Parent is greater than or equal to children
Children are less than parent
No ordering property
What is a max-heap?
Parent is greater than or equal to children
Parent is less than or equal to children
Children are greater than parent
No ordering
What is the time complexity to find the maximum element in a max-heap?
O(1)
O(log n)
O(n)
O(n^2)
What is the time complexity to insert an element into a heap?
O(1)
O(log n)
O(n)
O(n^2)
Which data structure is commonly used to implement a priority queue?
Heap
Array
Linked List
Stack
What is a graph?
A data structure consisting of vertices and edges
A tree with no cycles
A linear data structure
A hashing structure
What is a directed graph?
Edges have a direction
Edges have no direction
All vertices are connected
It is a tree
What is the degree of a vertex in an undirected graph?
The number of edges incident to it
The number of vertices connected to it
The number of outgoing edges
The number of incoming edges
What is the time complexity of Breadth-First Search (BFS) on a graph with V vertices and E edges?
O(V + E)
O(V^2)
O(E^2)
O(V * E)
What is the time complexity of Depth-First Search (DFS) on a graph with V vertices and E edges?
O(V + E)
O(V^2)
O(E^2)
O(V * E)
Which algorithm is used to find the shortest path in an unweighted graph?
BFS
DFS
Dijkstra
Bellman-Ford
What is hashing?
A technique to map data to a fixed-size value
A technique to sort data
A technique to link nodes
A technique to traverse trees
What is a hash table?
A data structure that uses a hash function to map keys to buckets
A sorted array
A linked list
A tree
What is a collision in hashing?
Two different keys map to the same index
Two same keys map to different indices
The hash table is full
The hash function is not defined
What is the load factor of a hash table?
Number of elements / table size
Table size / number of elements
Number of collisions
Hash function output
Which collision resolution technique uses linked lists?
Chaining
Open addressing
Double hashing
Linear probing
What is the average time complexity for search, insert, and delete in a well-designed hash table?
O(1)
O(log n)
O(n)
O(n^2)
What is the time complexity of Bubble Sort in the worst case?
O(n)
O(n log n)
O(n^2)
O(log n)
What is the time complexity of Merge Sort in all cases?
O(n log n)
O(n^2)
O(n)
O(log n)
Which sorting algorithm has the best average-case time complexity?
Quick Sort
Bubble Sort
Selection Sort
Insertion Sort
What is the time complexity of Quick Sort in the worst case?
O(n log n)
O(n^2)
O(n)
O(log n)
Which sorting algorithm is stable?
Merge Sort
Quick Sort
Heap Sort
Selection Sort
Which sorting algorithm is in-place?
Quick Sort
Merge Sort
Radix Sort
Counting Sort
What is the time complexity of linear search?
O(1)
O(log n)
O(n)
O(n^2)
What is the time complexity of binary search?
O(1)
O(log n)
O(n)
O(n^2)
What is the prerequisite for binary search?
The array must be sorted
The array must be unsorted
The array must contain unique elements
The array must be circular
What is the time complexity of interpolation search?
O(1)
O(log log n) average
O(n)
O(n^2)
What is the worst-case time complexity of interpolation search?
O(n)
O(log n)
O(1)
O(n^2)
Which search algorithm works on the principle of divide and conquer?
Binary Search
Linear Search
Jump Search
Exponential Search
What is the result of rotating an array by one position?
The first element moves to the last
The last element moves to the first
All elements shift right
All elements shift left
What is the advantage of a circular linked list over a singly linked list?
Traversal can start from any node
Uses less memory
Faster insertion
Easier to implement
What is the output of the following operations: push(5), push(10), pop(), push(15), pop(), pop()?
10, 15, 5
15, 10, 5
5, 10, 15
Error
What is the output of the following queue operations: enqueue(1), enqueue(2), dequeue(), enqueue(3), dequeue(), dequeue()?
1, 2, 3
2, 3, 1
1, 3, 2
3, 2, 1
What is the height of a tree with a single node?
0
1
2
Undefined
What is the time complexity to build a heap from an array of n elements?
O(n)
O(n log n)
O(n^2)
O(log n)
What is a spanning tree?
A subgraph that includes all vertices and is a tree
A subgraph with minimum edges
A complete graph
A graph with no cycles
What is double hashing?
Using two hash functions to resolve collisions
Using two hash tables
Hashing twice
Hash function with two parameters
What is the time complexity of Counting Sort?
O(n + k)
O(n log n)
O(n^2)
O(k log n)
What is the time complexity of Jump Search?
O(√n)
O(log n)
O(n)
O(n^2)
What is the difference between an array and a linked list?
Array is static; linked list is dynamic
Array uses contiguous memory; linked list uses non-contiguous
Both A and B
They are the same
What is the time complexity to delete a node given only a pointer to it in a singly linked list?
O(1)
O(n)
O(log n)
O(n^2)
What is the meaning of stack underflow?
Trying to pop from an empty stack
Trying to push onto a full stack
Stack memory is corrupted
Stack pointer is lost
What is a deque?
A double-ended queue
A queue with priority
A circular queue
A stack
What is an AVL tree?
A self-balancing BST
A tree with all nodes at same depth
A tree with no rotation
A tree with left and right subtrees of equal height
What is the time complexity to delete the root from a heap?
O(log n)
O(1)
O(n)
O(n^2)
What is a weighted graph?
Edges have weights or costs
Vertices have weights
Graph has cycles
Graph is directed
What is the difference between separate chaining and open addressing?
Chaining uses linked lists; open addressing probes
Open addressing uses linked lists; chaining probes
Both are the same
Chaining is for arrays; open addressing for trees
What is the time complexity of Heap Sort?
O(n log n)
O(n^2)
O(n)
O(log n)
What is the time complexity of Ternary Search?
O(log n) base 3
O(log n) base 2
O(n)
O(n^2)
What is the time complexity of inserting an element at the beginning of an array?
O(1)
O(n)
O(log n)
O(n^2)
What is the time complexity of inserting a node at the end of a singly linked list with a tail pointer?
O(1)
O(n)
O(log n)
O(n^2)
Which data structure is used for recursion?
Stack
Queue
Heap
Array
What is the time complexity of checking if a queue is empty?
O(1)
O(n)
O(log n)
O(n^2)
What is a trie?
A tree used for efficient retrieval of keys
A binary tree
A heap
A graph
What is the time complexity to find the minimum element in a min-heap?
O(1)
O(log n)
O(n)
O(n^2)
What is Dijkstra's algorithm used for?
Shortest path in weighted graphs
Shortest path in unweighted graphs
Minimum spanning tree
Topological sorting
What is a perfect hash function?
Injective mapping with no collisions
A hash function with many collisions
A hash function with no load factor
A hash function that maps all keys to same value
What is the time complexity of Insertion Sort in the worst case?
O(n)
O(n log n)
O(n^2)
O(log n)
What is the time complexity of Exponential Search?
O(log n)
O(n)
O(n^2)
O(1)
What is the difference between a static array and a dynamic array?
Static array has fixed size; dynamic array can grow
Static array uses heap; dynamic uses stack
Both are the same
Static array is faster
What is the time complexity to find the length of a singly linked list?
O(1)
O(n)
O(log n)
O(n^2)
Which of the following is true about a stack implemented using a linked list?
Push and pop are O(1)
Push and pop are O(n)
Memory is contiguous
It can't be implemented
What is the difference between a simple queue and a circular queue?
Circular queue reuses space; simple queue doesn't
Simple queue is faster
Both are the same
Circular queue uses linked list
What is the time complexity to search for a value in a BST in the worst case?
O(n)
O(log n)
O(1)
O(n^2)
What is the time complexity to find the maximum element in a max-heap?
O(1)
O(log n)
O(n)
O(n^2)
What is a cycle in a graph?
A path that starts and ends at the same vertex
A path with no repeated vertices
A path with no edges
A path with all vertices distinct
What is a hash collision?
Two different keys hash to same value
Two same keys hash to different values
Hash table is full
Hash function is broken
What is the time complexity of Radix Sort?
O(nk)
O(n log n)
O(n^2)
O(k)
What is the worst-case time complexity of Fibonacci Search?
O(log n)
O(n)
O(n^2)
O(1)
What is a sparse array?
An array with mostly zero or default values
An array with all elements filled
An array of objects
A two-dimensional array
What is a skip list?
A linked list with multiple levels for fast search
A list with no nodes
A circular linked list
A doubly linked list
What is the time complexity of evaluating a postfix expression using a stack?
O(n)
O(n^2)
O(log n)
O(1)
What is the time complexity of enqueue and dequeue in a linked list-based queue?
O(1)
O(n)
O(log n)
O(n^2)
What is a B-tree?
A balanced tree with multiple children per node
A binary tree
A heap
A graph
What is the time complexity to increase the priority of an element in a heap?
O(log n)
O(1)
O(n)
O(n^2)
What is the time complexity of Prim's algorithm for minimum spanning tree?
O(E log V)
O(V^2)
O(E + V log V)
Both A and C depending on implementation
What is the worst-case time complexity of search in a hash table using chaining?
O(1)
O(n)
O(log n)
O(n^2)
Which sorting algorithm is based on the divide and conquer paradigm?
Merge Sort
Bubble Sort
Selection Sort
Insertion Sort
What is the time complexity of Linear Search in the average case?
O(n)
O(n/2)
O(1)
O(n^2)
What is a jagged array?
An array of arrays where each inner array can have different length
A 2D array with equal rows and columns
A sorted array
A dynamic array
What is the time complexity to reverse a singly linked list?
O(n)
O(1)
O(log n)
O(n^2)
What is the output of the following: push(2), push(3), pop(), push(5), pop(), pop()?
3, 5, 2
2, 5, 3
5, 3, 2
2, 3, 5
What is the time complexity of checking the front element of a queue?
O(1)
O(n)
O(log n)
O(n^2)
What is the time complexity to insert an element into a balanced BST?
O(log n)
O(n)
O(1)
O(n^2)
What is the time complexity to delete an arbitrary element from a heap?
O(log n)
O(n)
O(1)
O(n^2)
What is the time complexity of DFS using an adjacency list?
O(V + E)
O(V^2)
O(E^2)
O(V * E)
What is the time complexity of insertion in a hash table with open addressing?
O(1) average
O(n) worst case
O(log n)
Both A and B
What is the time complexity of Quick Sort in the average case?
O(n log n)
O(n^2)
O(n)
O(log n)
What is the time complexity of Binary Search in the worst case?
O(log n)
O(n)
O(1)
O(n^2)
What is the time complexity of finding the maximum element in an unsorted array?
O(n)
O(log n)
O(1)
O(n^2)
What is the time complexity to insert a node after a given node in a singly linked list?
O(1)
O(n)
O(log n)
O(n^2)
What is the use of a stack in compilers?
Syntax analysis and expression evaluation
Code generation
Memory allocation
All of the above
What is a priority queue implemented using?
Heap
Array
Linked List
Stack
What is the time complexity to find the height of a binary tree?
O(n)
O(log n)
O(1)
O(n^2)
What is the space complexity of a heap?
O(n)
O(log n)
O(1)
O(n^2)
What is a bipartite graph?
Vertices can be divided into two sets with no edges within a set
A graph with edges only in one direction
A complete graph
A graph with cycles
What is the purpose of a hash function?
To map keys to indices in a hash table
To sort data
To link nodes
To balance trees
What is the time complexity of Shell Sort in the worst case?
O(n^2)
O(n log n)
O(n)
O(log n)
What is the time complexity of Sentinel Linear Search?
O(n)
O(log n)
O(1)
O(n^2)
What is the time complexity of accessing an element in an array by index?
O(1)
O(log n)
O(n)
O(n^2)