Aspirant Academy

MCQ

Paper - II (vi) — Data structures and Algorithms MCQ - Practice Questions with Answers

Solve 45 Paper - II (vi) — Data structures and Algorithms questions for RAS/RPSC preparation.

Practice questions

Q1In a binary search tree, a node z with two children is deleted by replacing its key with its inorder successor's key and then deleting that successor node. Which property makes the second deletion simpler than deleting z directly?

A The inorder successor of z is always a leaf node
B The inorder successor of z has no left child
C The inorder successor of z is always z's immediate right child
D The inorder successor of z has no parent pointer
Explanation

The inorder successor of a two-child node is the smallest key in its right subtree. By definition, that node cannot have a left child, because any left child would contain an even smaller key still greater than z. Therefore after copying the successor's key into z, the actual node removed has at most one child, reducing the deletion to a simpler splice operation.

Q2For an undirected graph with V vertices and E edges, which representation is usually more space-efficient for a sparse graph and still permits iteration over all neighbours of a vertex in time proportional to its degree?

A Adjacency matrix
B Sorted edge array only
C Adjacency list
D Incidence matrix
Explanation

Sparse graphs have far fewer edges than V^2, so an adjacency matrix wastes space on absent edges. An adjacency-list representation stores a list of neighbours for each vertex, taking Θ(V + E) space in an undirected graph representation and allowing all neighbours of a vertex to be visited by scanning just that vertex's list.

Q3A stack S receives the operations push(4), push(7), push(1), pop(), push(9), pop(), pop(). Which value is returned by the final pop operation?

A 7
B 1
C 4
D 9
Explanation

A stack follows last-in-first-out order. After push(4), push(7), push(1), the first pop removes 1. push(9) puts 9 on top, and the next pop removes 9. The remaining stack from bottom to top is 4, 7, so the final pop returns 7.

Q4A dictionary ADT is implemented for compiler symbol-table use. It must support insert, delete and search by identifier, and the workload has many failed searches. Which implementation choice best preserves expected constant-time search without requiring identifiers to remain in sorted order?

A A stack of recently declared identifiers with only push and pop operations
B A sorted array maintained after every insertion
C A hash table with a good hash function and a collision-resolution method such as chaining or open addressing
D An unsorted array scanned linearly for every lookup
Explanation

A symbol table is a dictionary-like ADT: it stores bindings and retrieves them by key. A hash table is the standard fit when ordering is not required, because a well-distributed hash function plus collision handling gives expected O(1) search, insertion and deletion. Sorted arrays trade this for O(log n) search and costly updates; stacks are too restrictive for arbitrary lookup.

Q5For an undirected simple graph with V vertices and E edges, which statement correctly compares adjacency matrix and adjacency list representations for the operation 'test whether edge (u, v) exists'?

A An adjacency matrix uses O(V + E) space, so it is normally preferred for sparse graphs.
B A plain adjacency list uses O(V^2) space, because each vertex must reserve a slot for every other vertex.
C An adjacency matrix tests edge existence in O(1), while a plain adjacency list may require scanning u's neighbour list.
D An adjacency list always tests edge existence in O(1), because every vertex stores its neighbours directly.
Explanation

An adjacency matrix is a two-dimensional table, so the presence of edge (u, v) can be checked by one indexed lookup. A plain adjacency list is more space-efficient for sparse graphs, but checking a specific edge can require searching through the neighbours of u. Thus the matrix wins on direct edge-existence testing, while the list usually wins on sparse-space usage.

You've seen 5 of 45 sample questions

Unlimited practice on Paper - II (vi) — Data structures and Algorithms comes with the RAS Test Series + Practice pack or Gate Pass.

More questions

6A queue is implemented in an array of size m using front and rear indices with one array slot deliberately left unused to distinguish full from empty. Which condition is correct for a full queue?

A(rear + 1) mod m == front
Bfront == rear
Cfront == (rear + 2) mod m
Drear == m - 1

7A file containing 1,024 sorted records is stored in an array. The target key is absent. If standard binary search is implemented with inclusive low and high indices, what is the maximum number of key comparisons before the search reports failure?

A10
B1,024
C11
D9

8An undirected simple graph has 10 vertices and 12 edges. Which comparison between adjacency matrix and adjacency list representations is correct for this graph?

AAn adjacency matrix uses space proportional to 100 cells, while adjacency lists store 24 neighbor entries plus vertex headers.
BAn adjacency matrix stores exactly 12 entries, while an adjacency list stores 100 entries.
CBoth representations must use the same asymptotic space because the graph has no parallel edges.
DAn adjacency list stores 12 neighbor entries, one per edge, because the graph is undirected.

9Consider the postfix expression 8 2 3 ^ / 2 3 * +, where ^ has already been converted to postfix and evaluation uses the usual stack algorithm. What value is produced?

A13
B7
C10
D6

10For a simple undirected graph with n vertices and e edges, an examiner asks which representation is asymptotically better for listing all neighbours of every vertex exactly once when e is much smaller than n^2. Which answer is most accurate?

ASorted edge array, because binary search gives logarithmic neighbour lookup.
BAdjacency matrix, because every neighbour test is constant time.
CIncidence matrix, because each edge appears in exactly two rows.
DAdjacency list, because total neighbour-list traversal is Theta(n + e).

11In the shunting-yard style conversion of an infix expression to postfix, the input token is an operator op. Which rule is correct for left-associative operators of ordinary precedence?

APop and output operators from the stack while their precedence is greater than or equal to op, stopping at a left parenthesis.
BEmpty the whole stack before pushing op, because postfix notation cannot contain parentheses.
CPush op immediately, because precedence is checked only when a right parenthesis is seen.
DPop only operators of strictly lower precedence, because higher precedence must remain closer to operands.

12A sequence stores n records. The workload is 90% random access by rank, 9% appending at the end, and 1% deletion from the middle after the position is already known. Memory locality is important. Which representation is generally the best fit?

ABinary search tree, because every operation becomes worst-case logarithmic.
BSingly linked list, because middle deletion after position is known is constant time.
CDynamic array, because rank access is constant time and append is amortized constant time.
DQueue, because append and deletion are both restricted operations.

13Which statement correctly compares arrays and singly linked lists for storing a dynamic sequence of records?

ALinked lists eliminate all memory overhead because they store only data fields and no links.
BSingly linked lists provide O(1) access to the kth element for every k, while arrays require O(k) traversal.
CArrays never require resizing and linked lists always require contiguous free memory.
DArrays provide O(1) random access by index, while singly linked lists allow O(1) insertion after a known node but require traversal for indexed access.

14A stack is implemented using two queues Q1 and Q2. The designer wants push to be O(1) and pop to return the most recently pushed item. Which method correctly implements pop when Q1 contains the stack items in their normal queue order?

AReverse Q1 by repeatedly enqueueing dequeued items back into Q1, then return the front
BDequeue and return the front item of Q1 directly
CMove all but the last item from Q1 to Q2, return the last item from Q1, then swap Q1 and Q2
DMove the front item of Q1 to Q2 and return the new front of Q1

15A compiler symbol table is implemented by hashing with separate chaining. If the hash function maps every identifier in a program to the same bucket, what is the worst-case time to search one identifier among n stored identifiers?

AO(n), because the search may scan the entire chain in that one bucket
BO(n log n), because each comparison recomputes the whole table
CO(log n), because the bucket automatically becomes a balanced tree
DO(1), because hash tables always give constant-time search

More topics in Programming & Data Structures (Senior CI)

Explore other subjects