Practice tests · GATE

GATE data structures: 5 practice questions with answers

By the PrepMatic team · Updated · 4 min read

On this page
  1. What GATE tests in data structures
  2. Practice questions
  3. Answers and explanations
  4. How to prepare data structures
  5. Take the full topic test on PrepMatic

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

  1. 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.
  2. 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.
  3. 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].
  4. D. *(q - 2) is a[2] = 30 and *p is a[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 is 50 3.
  5. 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:
StructureSearchInsertDelete
Sorted arrayO(log n)O(n)O(n)
Linked listO(n)O(1) at headO(n)
BST, worst caseO(n)O(n)O(n)
Balanced BST (AVL)O(log n)O(log n)O(log n)
Binary heapO(n)O(log n)O(log n) for the root
Hash table, averageO(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 setup

Related

More in GATE

← All practice tests