Practice tests · GATE
GATE data structures: 5 practice questions with answers
On this page
In GATE CS this topic sits in "Programming and Data Structures" (programming in C), and in GATE DA in "Programming, Data Structures and Algorithms" (Python). Questions are rarely theoretical: you get a code fragment or a sequence of operations and must say what the structure looks like at the end, so tracing by hand earns the marks. The five original questions below practise exactly that.
What GATE tests in data structures
The 2027 CS paper has a section called Programming and Data Structures, with the programming in C. Arrays, stacks, queues, linked lists, trees, binary search trees, heaps and graphs are the usual content, but the syllabus was revised for 2027, so match your notes against the official syllabus page. The real paper also has MSQ and NAT questions; all five below are MCQ.
Practice questions
Question 1
The postfix expression 5 3 + 2 * 4 6 2 / - + is evaluated using a stack. The value left on the stack is:
- A. 15
- B. 17
- C. 19
- D. 21
Question 2
Keys 50, 30, 70, 20, 40, 60, 80 are inserted in this order into an empty binary search tree. The node 30 is then deleted; since it has two children, it is replaced by its inorder successor. The preorder traversal of the resulting tree is:
- A. 50 20 40 70 60 80
- B. 50 40 70 60 80 20
- C. 50 20 70 60 80 40
- D. 50 40 20 70 60 80
Question 3
The keys 10, 4, 8, 2, 6, 1 are inserted one by one into an initially empty binary min-heap stored in an array, with the root at index 1. The array contents from index 1 to 6 are:
- A. 1 4 2 10 6 8
- B. 1 2 4 10 6 8
- C. 1 4 2 6 10 8
- D. 1 2 8 10 6 4
Question 4
In a C program, int a[5] = {10, 20, 30, 40, 50}; int *p = a + 1; int *q = &a[4]; is declared. What does printf("%d %d", *(q - 2) + *p, (int)(q - p)); print?
- A.
50 12 - B.
70 3 - C.
40 3 - D.
50 3
Question 5
A hash table of size 10 uses h(k) = k mod 10 and linear probing. The keys 12, 25, 35, 15, 22, 42 are inserted in this order. The index at which 42 is stored is:
- A. 2
- B. 3
- C. 4
- D. 8
Answers and explanations
- B. Scan left to right.
5 3 +gives 8;2 *gives 16. Push 4, 6 and 2;/takes 6 / 2 = 3 (second-from-top divided by top), leaving 16, 4, 3.-gives 4 − 3 = 1, and the final+gives 16 + 1 = 17. Reversing the operand order for-or/is the standard mistake. - D. The initial tree has 50 at the root, 30 and 70 below it, then 20, 40, 60 and 80 as leaves. The inorder successor of 30 is the smallest key in its right subtree, which is 40. Replace 30 by 40 and remove the old 40 leaf. The preorder (root, left, right) is 50, 40, 20, 70, 60, 80. Option A is what you get using the inorder predecessor.
- A. After 10, 4: the 4 moves above 10, giving [4, 10]. Insert 8: [4, 10, 8]. Insert 2: it swaps with its parent 10, then with 4, giving [2, 4, 8, 10]. Insert 6: its parent is 4, so it stays: [2, 4, 8, 10, 6]. Insert 1: it swaps with parent 8, then with 2, giving [1, 4, 2, 10, 6, 8].
- D.
*(q - 2)isa[2]= 30 and*pisa[1]= 20, so the sum is 50. Subtracting pointers gives the number of elements between them, not bytes:q - p= 4 − 1 = 3. The output is50 3. - C. 12 goes to slot 2, 25 to slot 5, 35 collides at 5 and takes slot 6, and 15 collides at 5 and 6 and takes slot 7. Key 22 hashes to slot 2 (occupied), so it takes slot 3. Key 42 hashes to 2, finds 2 and 3 occupied, and lands in slot 4.
How to prepare data structures
- Trace on paper, never in your head. Draw the tree, write the heap array, or make a table of variable values for each line of C.
- Master C pointer arithmetic and recursion: array-pointer equivalence, pointer subtraction,
*p++versus(*p)++, and how a recursive call unwinds. For DA, practise the same on Python lists and slicing. - Keep a complexity table in your head:
| Structure | Search | Insert | Delete |
|---|---|---|---|
| Sorted array | O(log n) | O(n) | O(n) |
| Linked list | O(n) | O(1) at head | O(n) |
| BST, worst case | O(n) | O(n) | O(n) |
| Balanced BST (AVL) | O(log n) | O(log n) | O(log n) |
| Binary heap | O(n) | O(log n) | O(log n) for the root |
| Hash table, average | O(1) | O(1) | O(1) |
- Memorise the tree counting facts: a binary tree with n nodes has n − 1 edges; a full binary tree with L leaves has L − 1 internal nodes; the height of a complete tree is ⌊log₂ n⌋.
Once you can trace reliably, move to previous year papers and the algorithms practice page. The GATE CSE preparation guide has the full CS roadmap.
Take the full topic test on PrepMatic
PrepMatic's topic tests run about 15 questions in 30 minutes, which suits tracing-heavy topics like this one. The free assessment shows your weakest subjects first.
Turn the GATE syllabus into a plan you can finish
Take a free GATE assessment on PrepMatic. It shows where you stand in your branch, turns the syllabus into a plan around the hours you actually have, and builds mock tests focused on your weak subjects.
Start free assessment →Free forever plan · No credit card · 2-minute setupRelated
- GATE algorithms practiceFive GATE-style algorithm MCQs on recurrences, Dijkstra, 0/1 knapsack, minimum comparisons and loop analysis, with worked solutions and a preparation plan.
- GATE operating systems practiceFive GATE-style operating system MCQs on SRTF scheduling, deadlock, LRU page replacement, effective access time and SCAN disk scheduling, with traced solutions.
- GATE DBMS practiceFive GATE-style database MCQs on candidate keys, normal forms, SQL NULL handling, conflict serializability and foreign-key joins, with worked answers and tips.
- GATE CSE preparationPlan GATE CS 2027: the revised syllabus section by section, the order to study the nine core subjects, standard books and a 26-week plan from first pass to mocks.
- GATE Data Science and AIThe GATE DA 2027 paper: seven syllabus sections for 85 marks, who should pick DA over CS, Python and maths priorities, books, and a six-month order of study.
More in GATE
- GATE DA probability practiceFive GATE Data Science and AI probability and statistics MCQs on covariance, confidence intervals, the z-test, the central limit theorem and chi-squared tests.
- GATE control systems practiceFive GATE-style control systems MCQs on damping ratio, Routh stability, steady-state error, root locus breakaway points and gain margin for EE and EC.
- GATE differential equations practiceFive GATE-level differential equation MCQs on linear ODEs, repeated roots, particular integrals, Laplace transforms and the wave equation, with solutions.
- GATE computer organization practiceFive GATE-style computer organization MCQs on cache tag bits, pipeline CPI, expanding opcodes, DMA cycle stealing and memory access time, with worked answers.
- GATE digital logic practiceFive GATE-style digital logic MCQs on K-map minimisation, two's complement overflow, counter modulus, multiplexer design and clock frequency, with answers.
- GATE computer networks practiceFive GATE-style computer networks MCQs on subnetting, CSMA/CD frame size, Go-Back-N, TCP congestion control and IP fragmentation, with step-by-step solutions.
- GATE EC digital circuits practiceFive GATE EC digital circuits MCQs on DAC output, memory expansion, Johnson counters, hazard removal and address decoding, with worked solutions.
- GATE compiler design practiceFive GATE-style compiler design MCQs on FOLLOW sets, LR(0) states, expression DAGs, basic blocks and lexical tokens, each with a full step-by-step explanation.