Data Structures — One Question at a Time
Practise 150 Data Structures multiple-choice questions covering arrays, stacks, queues, linked lists, sorting, searching, hashing, trees and graph algorithms. Work through one question at a time, check the correct answer with an explanation, and select Next Question to continue. This is self-paced practice without automatic scoring.
Before you practise: Read Data Structures study material and examples. You can also browse all 1,576 interactive MCQs.
Question 1. Which notation describes an asymptotic upper bound?
Show Answer and Explanation
Correct answer: C. Big O
Big O provides an upper bound on asymptotic growth.
Question 2. What is the worst-case time of linear search in an array of n elements?
Show Answer and Explanation
Correct answer: A. O(n)
If the target is last or absent, all n elements are checked.
Question 3. What order does a stack follow?
Show Answer and Explanation
Correct answer: D. LIFO
The most recently pushed item is the first popped.
Question 4. Push 4, push 7, then pop. Which value is returned?
Show Answer and Explanation
Correct answer: B. 7
7 is at the top of the stack.
Question 5. Which structure naturally holds active recursive function calls?
Show Answer and Explanation
Correct answer: B. Stack
Call frames are managed as a stack in common runtime implementations.
Question 6. What order does a conventional queue follow?
Show Answer and Explanation
Correct answer: D. FIFO
The first item added is the first removed.
Question 7. Enqueue A, B and C; dequeue twice. Which item remains at the front?
Show Answer and Explanation
Correct answer: A. C
A and B leave in order, so C is next.
Question 8. What determines removal order in a priority queue?
Show Answer and Explanation
Correct answer: C. Item priority
A priority queue serves according to priority (with tie behaviour dependent on implementation).
Question 9. What does a singly linked list node typically contain?
Show Answer and Explanation
Correct answer: D. Value and reference to the next node
A node stores an item and a link to the next node.
Question 10. Given a head pointer, what is the cost of inserting at the front of a singly linked list?
Show Answer and Explanation
Correct answer: B. O(1)
Only a constant number of pointer updates is required.
Question 11. Which linked-list property generally differs from a contiguous array?
Show Answer and Explanation
Correct answer: C. Nodes need not be stored adjacently
Links connect nodes that may occupy separate memory locations.
Question 12. What is the worst-case time of insertion sort on n elements?
Show Answer and Explanation
Correct answer: A. O(n²)
A reverse-ordered input can require a quadratic number of shifts/comparisons.
Question 13. What is typical worst-case time for merge sort?
Show Answer and Explanation
Correct answer: A. O(n log n)
Divide-and-conquer merging gives O(n log n) time.
Question 14. Which simple sorting algorithm repeatedly selects the smallest remaining value?
Show Answer and Explanation
Correct answer: C. Selection sort
Selection sort selects the minimum from the unsorted portion each pass.
Question 15. When can ordinary binary search be applied correctly?
Show Answer and Explanation
Correct answer: B. On sorted, indexable data
Binary search depends on sorted order to eliminate half the candidates.
Question 16. Binary search on 16 sorted elements needs at most how many comparisons for a successful or unsuccessful search under a standard midpoint algorithm?
Show Answer and Explanation
Correct answer: D. 5
An unsuccessful search can examine up to five midpoints as an interval of length 16 shrinks to zero.
Question 17. A hash-table collision occurs when what happens?
Show Answer and Explanation
Correct answer: C. Two keys map to the same bucket or slot
Collisions arise from distinct keys sharing a computed location.
Question 18. Which collision-resolution method stores multiple items in buckets using a list or similar collection?
Show Answer and Explanation
Correct answer: D. Separate chaining
Chaining stores colliding entries in a bucket-associated structure.
Question 19. In a binary tree, how many children can a node have at most?
Show Answer and Explanation
Correct answer: B. 2
Each binary-tree node has at most a left child and a right child.
Question 20. For a binary search tree with distinct keys, which traversal outputs keys in increasing order?
Show Answer and Explanation
Correct answer: A. Inorder
Visiting left subtree, root and right subtree yields ascending keys.
Question 21. What is the height of a single-node tree when height is measured in edges?
Show Answer and Explanation
Correct answer: B. 0
There are no edges along the longest root-to-leaf path.
Question 22. Which graph search normally uses a queue to discover vertices by increasing distance in an unweighted graph?
Show Answer and Explanation
Correct answer: A. BFS
Breadth-first search explores neighbours layer by layer using a queue.
Question 23. Which search is naturally implemented using a stack or recursion?
Show Answer and Explanation
Correct answer: D. Depth-first search
DFS follows a branch deeply and backtracks, often through recursion or an explicit stack.
Question 24. What does an adjacency matrix entry at (i,j) usually record for a simple unweighted graph?
Show Answer and Explanation
Correct answer: C. Whether an edge connects vertices i and j
The matrix stores edge incidence, usually 1 for an edge and 0 otherwise.
Question 25. In a connected, unweighted graph, what does BFS find from a given source?
Show Answer and Explanation
Correct answer: D. A path with the fewest edges to each reachable vertex
BFS distances count edges and are shortest in unweighted graphs.
Question 26. A loop increments i by 1 from 0 to n−1; what is its iteration count?
Show Answer and Explanation
Correct answer: C. n
The loop executes once for each of n indices.
Question 27. Starting with i = 1, a loop doubles i while i < n, with n ≥ 2. How does its iteration count grow?
Show Answer and Explanation
Correct answer: A. O(log n)
The number of iterations is the smallest k with 2^k ≥ n, namely ⌈log₂ n⌉, and therefore is Θ(log n).
Question 28. What is the auxiliary space of an iterative in-place selection sort?
Show Answer and Explanation
Correct answer: B. O(1)
Only a constant number of temporary variables is needed.
Question 29. A stack receives push(2), push(3), pop(), push(4). What does pop() return next?
Show Answer and Explanation
Correct answer: A. 4
After removing 3, 4 becomes the new top.
Question 30. A circular queue with fixed capacity is useful primarily for what?
Show Answer and Explanation
Correct answer: D. Reusing freed array slots efficiently
Circular indexing allows wraparound and reuse of available storage.
Question 31. Which structure is commonly used to evaluate postfix expressions?
Show Answer and Explanation
Correct answer: C. Stack
Operands are pushed and operators consume the top stack values.
Question 32. What is a deque?
Show Answer and Explanation
Correct answer: B. A double-ended queue
A deque supports insertion and removal at both ends.
Question 33. For a singly linked list without a tail pointer, how long can appending take?
Show Answer and Explanation
Correct answer: C. O(n)
Without a tail pointer, reaching the last node requires traversal.
Question 34. Which pointer update inserts node N immediately after P in a singly linked list?
Show Answer and Explanation
Correct answer: A. N.next=P.next; P.next=N
Preserve the old successor before linking P to N.
Question 35. What extra reference does a doubly linked list node commonly have?
Show Answer and Explanation
Correct answer: D. Previous node
Doubly linked nodes usually store both next and previous references.
Question 36. Which algorithm is stable in its standard merge-based implementation?
Show Answer and Explanation
Correct answer: B. Merge sort
A conventional merge implementation preserves the order of equal keys.
Question 37. For a reverse-sorted list, how many comparisons does basic selection sort perform asymptotically?
Show Answer and Explanation
Correct answer: B. O(n²)
Basic selection sort scans the unsorted suffix regardless of initial order.
Question 38. Why can quicksort reach O(n²) time?
Show Answer and Explanation
Correct answer: D. Highly unbalanced partitions
A sequence of near-empty partitions yields a quadratic sum of work.
Question 39. Which sorting method is non-comparison-based for bounded integer keys?
Show Answer and Explanation
Correct answer: A. Counting sort
Counting sort uses key frequencies rather than pairwise ordering comparisons.
Question 40. What is a load factor for a typical chained hash table?
Show Answer and Explanation
Correct answer: C. Number of entries divided by number of buckets
Load factor α = n/m measures average entries per bucket.
Question 41. In linear probing, where is the next collision candidate usually sought?
Show Answer and Explanation
Correct answer: D. A nearby slot in a fixed probe sequence
Open addressing examines alternate slots according to a probe sequence.
Question 42. What are the nodes with no children called?
Show Answer and Explanation
Correct answer: B. Leaves
A leaf has no child nodes.
Question 43. In a complete binary tree, where is the last level filled?
Show Answer and Explanation
Correct answer: C. From left to right
All levels except possibly the last are full; the last is filled left to right.
Question 44. Which heap property defines a min-heap?
Show Answer and Explanation
Correct answer: A. Every parent key is ≤ its children
A min-heap keeps each parent no greater than its children.
Question 45. What is the worst-case height of an unbalanced BST with n nodes?
Show Answer and Explanation
Correct answer: A. O(n)
Sorted insertions can create a chain of n nodes.
Question 46. For an undirected graph with 5 vertices and 4 edges, what is the sum of all vertex degrees?
Show Answer and Explanation
Correct answer: C. 8
The handshaking lemma gives total degree 2m = 8.
Question 47. What is a topological ordering defined for?
Show Answer and Explanation
Correct answer: B. Directed acyclic graphs
A DAG admits a vertex ordering respecting every directed edge.
Question 48. Which representation uses O(V²) space for V vertices?
Show Answer and Explanation
Correct answer: D. Adjacency matrix
A V×V adjacency matrix has V² entries.
Question 49. For unweighted shortest paths from a source, which algorithm is appropriate?
Show Answer and Explanation
Correct answer: C. Breadth-first search
BFS visits vertices by increasing distance in edge count.
Question 50. Dijkstra’s algorithm requires what edge-weight condition for its standard correctness guarantee?
Show Answer and Explanation
Correct answer: D. Nonnegative edge weights
The standard algorithm assumes all edge weights are nonnegative.
Question 51. Which traversal follows a path deeply before backtracking?
Show Answer and Explanation
Correct answer: B. DFS
Depth-first search explores descendants before returning to alternatives.
Question 52. For T(n)=2T(n/2)+n with T(1)=Θ(1), what is T(n) for powers of 2?
Show Answer and Explanation
Correct answer: A. Θ(n log n)
The merge-sort recurrence has log n levels, each with Θ(n) work.
Question 53. For T(n)=T(n−1)+1, T(1)=1, what is asymptotic growth?
Show Answer and Explanation
Correct answer: B. Θ(n)
The recurrence adds one unit for each decrease from n to 1.
Question 54. A recursive function calls itself once with n−1 until n=0. What is maximum call-stack depth?
Show Answer and Explanation
Correct answer: A. Θ(n)
There are n+1 active levels before the base case.
Question 55. Starting at i = 1, a loop doubles i while i < n for integer n ≥ 2 and performs constant work each time. What is its runtime?
Show Answer and Explanation
Correct answer: D. Θ(log n)
The loop makes ⌈log₂ n⌉ iterations, each doing constant work, so the runtime is Θ(log n).
Question 56. Evaluate the postfix expression 5 2 + 3 *.
Show Answer and Explanation
Correct answer: C. 21
First 5+2=7; then 7×3=21.
Question 57. Which structure is best suited to managing undo operations when only the latest change is undone?
Show Answer and Explanation
Correct answer: D. Stack
The latest action is reversed first, a last-in-first-out pattern.
Question 58. A queue initially contains [A,B,C] front to back. After dequeue and enqueue D, what is the order?
Show Answer and Explanation
Correct answer: C. [B,C,D]
Dequeue removes A; enqueue adds D at the back.
Question 59. If a queue is implemented by a circular array, what does wrapping mean?
Show Answer and Explanation
Correct answer: A. After last array index, the next index is zero
Circular indexing uses the array modulo its capacity.
Question 60. With only a head pointer, deleting the first node of a nonempty singly linked list takes what time?
Show Answer and Explanation
Correct answer: B. O(1)
The head can be advanced to its successor in constant time.
Question 61. Which condition identifies the final node in a conventional null-terminated singly linked list?
Show Answer and Explanation
Correct answer: A. Its next reference is null
The last node has no successor link.
Question 62. What is the worst-case comparison count for linear search on a list of 8 items?
Show Answer and Explanation
Correct answer: D. 8
The searched-for item may be last or absent, requiring eight comparisons.
Question 63. How many comparisons does selection sort make on 5 elements using the standard minimum-selection procedure?
Show Answer and Explanation
Correct answer: C. 10
The passes compare 4+3+2+1=10 pairs regardless of original order.
Question 64. Which common sorting algorithm is stable when implemented by merging equal keys from the left half first?
Show Answer and Explanation
Correct answer: B. Merge sort
Keeping left-half equal keys first preserves their original relative order.
Question 65. Which data are needed for an ordinary binary search on an array?
Show Answer and Explanation
Correct answer: C. Sorted values
Binary search requires ordering; duplicate values are permitted.
Question 66. In separate chaining, what does a hash table typically store at each bucket?
Show Answer and Explanation
Correct answer: A. A collection of colliding entries
Each bucket can hold multiple items whose keys map there.
Question 67. If a table has 12 entries across 8 buckets, what is its load factor?
Show Answer and Explanation
Correct answer: D. 1.5
Load factor is n/m = 12/8 = 1.5 for separate chaining.
Question 68. What happens when open-addressing insertion probes a slot already occupied by another key?
Show Answer and Explanation
Correct answer: B. It follows the probing sequence to another slot
Open addressing resolves collisions by examining alternate locations.
Question 69. A tree has one root and exactly three edges along its longest root-to-leaf path. What is its height in edges?
Show Answer and Explanation
Correct answer: B. 3
Height counts edges on the longest downward path, giving 3.
Question 70. In a min-heap, which position contains a minimum element?
Show Answer and Explanation
Correct answer: D. The root
Each parent has a key no greater than its children, so the root is minimal.
Question 71. What is the worst-case complexity of searching for a key in a skewed, unbalanced BST with n nodes?
Show Answer and Explanation
Correct answer: A. O(n)
A skewed BST can form a chain with n nodes.
Question 72. What order does postorder traversal use for a binary tree?
Show Answer and Explanation
Correct answer: C. Left-right-root
Postorder processes left subtree, then right subtree, then root.
Question 73. In an undirected simple graph with 6 vertices each of degree 2, how many edges are there?
Show Answer and Explanation
Correct answer: D. 6
The sum of degrees is 12; dividing by two gives six edges.
Question 74. For a directed graph with a cycle, what is true about a topological ordering of all its vertices?
Show Answer and Explanation
Correct answer: B. It cannot exist
A topological ordering exists exactly for directed acyclic graphs.
Question 75. Which shortest-path method works for unweighted graphs using a queue?
Show Answer and Explanation
Correct answer: C. BFS
BFS discovers vertices at increasing edge-distance.
Question 76. For a dense graph with V vertices, which representation directly tests whether edge (u,v) exists in O(1) time?
Show Answer and Explanation
Correct answer: A. Adjacency matrix
A matrix entry indexed by u and v provides constant-time lookup.
Question 77. What is the sum of outdegrees in any finite directed graph?
Show Answer and Explanation
Correct answer: A. Number of edges
Each directed edge contributes one to its source’s outdegree.
Question 78. How many comparisons are needed to find the maximum of n≥1 elements by linear scanning?
Show Answer and Explanation
Correct answer: C. n−1
After choosing the first item, compare the remaining n−1 items.
Question 79. Which recurrence represents binary search with constant work per step?
Show Answer and Explanation
Correct answer: B. T(n)=T(n/2)+O(1)
Each step narrows the search to approximately half the elements.
Question 80. Two sequential loops each visit n elements and do constant work. What is their combined runtime?
Show Answer and Explanation
Correct answer: D. Θ(n)
Their running times add to n+n=2n, which is Θ(n).
Question 81. A binary-search procedure on a sorted array starts left=0, right=7. What initial midpoint does (left+right)//2 give?
Show Answer and Explanation
Correct answer: C. 3
Integer division of 7 by 2 yields index 3.
Question 82. Starting with an empty stack, push 1, push 2, pop, push 5. What is at the top?
Show Answer and Explanation
Correct answer: D. 5
After removing 2, pushing 5 makes it the top element.
Question 83. What structure is used by BFS to process discovered vertices in arrival order?
Show Answer and Explanation
Correct answer: B. Queue
A FIFO queue processes vertices layer by layer.
Question 84. What is a standard use of a stack in parsing?
Show Answer and Explanation
Correct answer: A. Matching nested parentheses
Opening delimiters are pushed and checked against closing delimiters.
Question 85. In a nonempty singly linked list with a head pointer, removing the head is what time complexity?
Show Answer and Explanation
Correct answer: B. O(1)
Update the head to the successor in constant time.
Question 86. What extra pointer is typically stored by doubly linked nodes?
Show Answer and Explanation
Correct answer: A. Previous pointer
Nodes reference both next and previous neighbours.
Question 87. After applying one standard left-to-right pass of bubble sort to [5, 2, 4, 1], what is the array?
Show Answer and Explanation
Correct answer: B. [2, 4, 1, 5]
Compare adjacent pairs and swap if out of order: [2,5,4,1], then [2,4,5,1], then [2,4,1,5]. The largest element reaches the final position.
Question 88. Which algorithm has Θ(n log n) worst-case time under a standard merge sort implementation?
Show Answer and Explanation
Correct answer: C. Merge sort
Merge sort recursively divides and merges, producing n log n work.
Question 89. What input commonly triggers Θ(n²) work for standard insertion sort?
Show Answer and Explanation
Correct answer: D. Reverse sorted
Each new element must shift past nearly all previously seen values.
Question 90. A chained hash table has 18 keys and 12 buckets. What is its load factor?
Show Answer and Explanation
Correct answer: C. 1.5
Load factor is keys divided by buckets: 18/12=1.5.
Question 91. What is a collision in hashing?
Show Answer and Explanation
Correct answer: A. Two distinct keys map to the same bucket
A hash function can map different keys to one bucket.
Question 92. In a BST with distinct integer keys, what order does inorder traversal produce?
Show Answer and Explanation
Correct answer: B. Increasing
The left-root-right traversal follows the BST key ordering.
Question 93. For a min-heap, where is one smallest key always located?
Show Answer and Explanation
Correct answer: A. Root
The heap-order property places a minimum at the root.
Question 94. An undirected graph has 7 edges. What is the sum of its vertex degrees?
Show Answer and Explanation
Correct answer: D. 14
Each edge contributes two to the sum of degrees.
Question 95. Which algorithmic technique underlies topological sorting using indegree counts?
Show Answer and Explanation
Correct answer: C. Kahn’s algorithm
Kahn’s algorithm repeatedly selects vertices with indegree zero, removes their outgoing edges, and produces a topological order when the graph is acyclic.
Question 96. Which algorithm gives shortest paths by number of edges in an unweighted graph?
Show Answer and Explanation
Correct answer: B. BFS
Breadth-first search explores vertices by distance layers.
Question 97. In a dense graph with V vertices, what space does a conventional adjacency matrix use?
Show Answer and Explanation
Correct answer: C. O(V²)
Its V by V entries require quadratic storage.
Question 98. Which algorithm processes keys digit by digit, commonly relying on stable passes?
Show Answer and Explanation
Correct answer: A. Radix sort
Radix sort sorts keys by individual digits or positions.
Question 99. What is a practical limitation of counting sort?
Show Answer and Explanation
Correct answer: D. A very large key range may use excessive memory
Counting sort uses an array sized to the key range.
Question 100. What does stable sorting preserve?
Show Answer and Explanation
Correct answer: B. Relative order of records having equal keys
Equal-key elements keep their original relative ordering.
Question 101. Which algorithm computes shortest paths from a source in graphs with nonnegative edge weights?
Show Answer and Explanation
Correct answer: B. Dijkstra’s algorithm
Dijkstra’s greedy relaxation is correct for nonnegative weights.
Question 102. A directed acyclic graph has edges A→C and B→C. Which sequence is a valid topological order?
Show Answer and Explanation
Correct answer: D. B, A, C
Both A and B must occur before C. The order B, A, C respects both directed edges.
Question 103. Which common graph representation is typically more memory-efficient for sparse graphs?
Show Answer and Explanation
Correct answer: A. Adjacency lists
Adjacency lists store vertices and actual edges, taking O(V+E) space.
Question 104. What does a topological sorting algorithm do when it detects a directed cycle?
Show Answer and Explanation
Correct answer: C. Report that a full topological ordering is impossible
Every directed cycle creates contradictory precedence requirements.
Question 105. Which balancing scheme uses red and black node colours to constrain BST height?
Show Answer and Explanation
Correct answer: D. Red-black trees
Red-black invariants keep the height logarithmic.
Question 106. What is the worst-case search complexity of an AVL tree with n nodes?
Show Answer and Explanation
Correct answer: B. O(log n)
Height-balancing maintains logarithmic tree height.
Question 107. What is the main purpose of garbage collection?
Show Answer and Explanation
Correct answer: C. Reclaim memory that is no longer reachable or needed
Garbage collectors reclaim unused managed allocations according to their reachability/liveness model.
Question 108. What is a trie particularly suited for?
Show Answer and Explanation
Correct answer: A. Prefix-based string lookup
Trie edges commonly encode successive symbols of keys, supporting prefix queries.
Question 109. Why do cache-friendly contiguous arrays often outperform linked lists in sequential scans?
Show Answer and Explanation
Correct answer: A. Spatial locality reduces memory-access overhead
Nearby array elements tend to benefit from cache locality.
Question 110. What property makes an array suitable for constant-time indexed access?
Show Answer and Explanation
Correct answer: D. Contiguous storage with direct address calculation
Array indexing computes an element address from its index under the standard array model.
Question 111. When is a dynamic array likely to reallocate its storage?
Show Answer and Explanation
Correct answer: A. When an insertion exceeds current capacity
Growing past capacity may require allocating a larger contiguous block.
Question 112. What is amortized analysis used to describe?
Show Answer and Explanation
Correct answer: B. Average cost per operation over a sequence of operations
Amortized bounds spread occasional costly steps across many operations.
Question 113. What is a circular linked list?
Show Answer and Explanation
Correct answer: C. A linked list whose final node links back into the list
In a circular list the final link returns to a node, commonly the head.
Question 114. Why can linked lists be less cache-friendly than arrays?
Show Answer and Explanation
Correct answer: D. Successive nodes may be scattered in memory
Noncontiguous nodes often cause poorer spatial locality.
Question 115. What is stack underflow?
Show Answer and Explanation
Correct answer: A. Attempting to remove an item from an empty stack
A pop on an empty stack cannot return a valid stored item.
Question 116. What is queue overflow in a bounded queue?
Show Answer and Explanation
Correct answer: B. Attempting to insert when the queue is full
A capacity-limited queue needs to handle an enqueue with no free slot.
Question 117. What does a queue’s front operation usually do?
Show Answer and Explanation
Correct answer: C. Inspect the next item without removing it
Front or peek returns the item scheduled to leave next.
Question 118. Which data structure is naturally used by an event scheduler based on event times?
Show Answer and Explanation
Correct answer: D. Priority queue
A priority queue efficiently selects the event with the earliest scheduled time.
Question 119. What is the primary requirement of a balanced binary search tree?
Show Answer and Explanation
Correct answer: A. Its height remains controlled relative to the number of nodes
Balancing avoids the linear-height degeneration of ordinary BSTs.
Question 120. What does an AVL rotation maintain?
Show Answer and Explanation
Correct answer: B. Binary search ordering while restoring height balance
AVL rotations locally restructure links without changing sorted key order.
Question 121. What is a graph’s adjacency list?
Show Answer and Explanation
Correct answer: C. For each vertex, a collection of its neighbors
Adjacency lists store edges by listing neighbors at each vertex.
Question 122. What is a connected component of an undirected graph?
Show Answer and Explanation
Correct answer: D. A maximal set of mutually reachable vertices
Every pair of vertices within a connected component is joined by a path.
Question 123. How can DFS be used to detect a cycle in an undirected graph?
Show Answer and Explanation
Correct answer: A. Find an edge to a visited vertex other than the current parent
During undirected DFS, such a non-parent visited neighbor indicates a cycle.
Question 124. What is a spanning tree of a connected undirected graph?
Show Answer and Explanation
Correct answer: B. A connected acyclic subgraph containing all vertices
A spanning tree connects every vertex using exactly V−1 edges.
Question 125. Which classical algorithm constructs a minimum spanning tree using edge weights in increasing order?
Show Answer and Explanation
Correct answer: C. Kruskal’s algorithm
Kruskal processes candidate edges by weight while avoiding cycles.
Question 126. Which data structure is commonly used by Kruskal’s algorithm to track components?
Show Answer and Explanation
Correct answer: D. Disjoint-set union
Union-find efficiently determines whether two endpoints are already connected.
Question 127. What is path compression in a disjoint-set forest?
Show Answer and Explanation
Correct answer: A. Making nodes point closer to the representative during find
Path compression flattens parent links and improves future find operations.
Question 128. Why is a min-heap often used with Dijkstra’s algorithm?
Show Answer and Explanation
Correct answer: B. To extract a vertex with the smallest tentative distance
A priority queue supports efficient selection of the smallest tentative distance.
Question 129. Which graph algorithm can handle negative edge weights and detect reachable negative cycles?
Show Answer and Explanation
Correct answer: C. Bellman-Ford
Bellman-Ford relaxes edges repeatedly and checks for reachable negative cycles.
Question 130. When can a shortest path be undefined due to negative weights?
Show Answer and Explanation
Correct answer: D. When a reachable negative cycle can lead to the destination
Repeated traversal of a relevant negative cycle can reduce path cost without bound.
Question 131. What is a hash function used for in a hash table?
Show Answer and Explanation
Correct answer: A. Map keys to hash values or bucket locations
A hash function determines where to seek a key, with collisions handled separately.
Question 132. Why does a high load factor often slow a chained hash table?
Show Answer and Explanation
Correct answer: B. More entries tend to occupy each bucket
Longer chains can increase expected search work.
Question 133. What does rehashing usually involve?
Show Answer and Explanation
Correct answer: C. Reassigning entries into a new bucket arrangement
After changing capacity or hashing parameters, keys are redistributed into buckets.
Question 134. What is the worst-case time of a hash-table lookup without favorable distribution assumptions?
Show Answer and Explanation
Correct answer: D. O(n)
Pathological collisions can force examination of many entries.
Question 135. Which sorting algorithm repeatedly swaps adjacent out-of-order items?
Show Answer and Explanation
Correct answer: A. Bubble sort
Bubble sort scans neighboring pairs and swaps them when needed.
Question 136. Which sorting algorithm partitions data around a pivot?
Show Answer and Explanation
Correct answer: B. Quicksort
Quicksort recursively orders elements relative to a pivot.
Question 137. Why is stable sorting useful for records with multiple keys?
Show Answer and Explanation
Correct answer: C. It preserves earlier ordering among equal keys
Stability enables sorting by secondary and then primary keys.
Question 138. What does breadth-first traversal of a rooted tree visit first?
Show Answer and Explanation
Correct answer: D. Nodes at smaller depths
BFS visits the root and then successive depth levels.
Question 139. Which tree traversal visits the root before either subtree?
Show Answer and Explanation
Correct answer: A. Preorder
Preorder processes root, then left and right subtrees.
Question 140. What is a binary tree’s height in edges?
Show Answer and Explanation
Correct answer: B. The maximum number of edges on a root-to-leaf path
Height measures the longest downward path from the root.
Question 141. What is the maximum number of nodes at level d in a binary tree if the root is level 0?
Show Answer and Explanation
Correct answer: C. 2^d
Each binary level can double the number of nodes, giving at most 2^d.
Question 142. How many edges does a tree with 12 vertices contain?
Show Answer and Explanation
Correct answer: D. 11
Every finite tree with V vertices has V−1 edges.
Question 143. What is a trie node commonly associated with?
Show Answer and Explanation
Correct answer: A. A prefix of stored keys
Paths from the root encode successive symbols and their prefixes.
Question 144. What is a suffix of a string?
Show Answer and Explanation
Correct answer: B. A contiguous portion ending at the string’s last character
A suffix begins at some position and continues to the end of the string.
Question 145. Which abstract data type supports insert, delete and find-min operations?
Show Answer and Explanation
Correct answer: C. Min-priority queue
A min-priority queue maintains items to retrieve and remove the minimum.
Question 146. How many vertex-degree units does an undirected edge contribute overall?
Show Answer and Explanation
Correct answer: D. 2
Each undirected edge contributes one to each endpoint degree, counting loops twice.
Question 147. Which condition is necessary for an undirected graph to have an Euler circuit?
Show Answer and Explanation
Correct answer: A. Every vertex with a nonzero degree lies in one component and every vertex has even degree
A connected edge-containing component with all even degrees admits an Euler circuit.
Question 148. What is the time complexity of BFS using adjacency lists for a graph with V vertices and E edges?
Show Answer and Explanation
Correct answer: B. O(V+E)
BFS processes vertices and scans their adjacency lists, totaling O(V+E).
Question 149. Why are dynamic programming tables useful?
Show Answer and Explanation
Correct answer: C. They store solutions of subproblems to avoid repeated computation
Memoization or tabulation reuses results of overlapping subproblems.
Question 150. What is memoization?
Show Answer and Explanation
Correct answer: D. Caching results of previously solved subproblems
Memoization trades storage for avoiding redundant computation.
