GATE DA Programming, Data Structures & Algorithms Previous Year Questions

32 solved GATE DA questions on Programming, Data Structures & Algorithms, drawn from 3 exam years and grouped by year. Every question shows the official answer and a step-by-step solution.

Want to practise this topic and ask follow-up questions? Explore Success Tracker.

Revision companion

Programming & Algorithms: trace the code, then count the cost

Simulate code on small inputs before generalizing. Identify the data structure's invariant, the algorithm's loop structure, and the input size before claiming a complexity bound. These selected foundations connect Python-style pseudocode execution, fundamental data structures, sorting, searching, and asymptotic analysis. They are not a complete syllabus.

Our study notes and original examples support the PYQs below; they are not official exam questions or a replacement for the current syllabus.

Before you start

  • Variables, assignments, loops, conditionals, and functions in an imperative language.
  • Array indexing starting from 0, basic recursion, and simple arithmetic expressions.

Concepts to revise before solving

Control flow and code tracing

Trace each statement in order, updating variables after every assignment. For loops, record the variable at the start and end of each iteration. Off-by-one errors often come from confusing inclusive and exclusive bounds. A function call creates its own scope; local variables do not affect the caller's copies unless passed by reference.

Check yourself: What is the value of each variable at the start of this iteration?

Arrays, lists, and linked structures

Array access by index is O(1); inserting into the middle of a dynamic array is O(n) due to shifting. A singly linked list supports O(1) insertion at the head but O(n) search. A stack is last-in-first-out; a queue is first-in-first-out. Choose the structure whose fast operations match the problem's access pattern.

Check yourself: Does this operation require shifting elements or traversing nodes?

Trees and binary search trees

In a binary search tree, left descendants store smaller keys and right descendants store larger keys. Search, insert, and delete are O(h) where h is the height. A balanced BST keeps h = O(log n); inserting sorted data into a plain BST produces height O(n). Inorder traversal of a BST yields keys in sorted order.

Check yourself: Does the BST property hold at every node after your operation?

Sorting and searching

Comparison-based sorting has a lower bound of Ω(n log n). Merge sort achieves O(n log n) worst case; quicksort achieves O(n log n) expected case but O(n²) worst case. Binary search on a sorted array requires O(log n) comparisons. Verify the array is sorted before applying binary search.

Check yourself: Is the input sorted, and are you halving the search space at each step?

Asymptotic complexity

O denotes an asymptotic upper bound, Ω a lower bound, and Θ a tight bound. Analyze the innermost loop's iteration count as a function of the outer loop's variable. Nested loops with independent ranges multiply; nested loops where the inner bound depends on the outer require a summation. Drop lower-order terms and constant factors.

Check yourself: Are you counting the total iterations across all loop passes, not just one pass?

Mistakes to avoid

Claiming binary search is O(log n) on an unsorted array.
Binary search requires sorted input. On an unsorted array, linear search in O(n) is the baseline.
Confusing O(n log n) with O(n²) when nested loops have dependent bounds.
Sum the inner loop's iterations over all outer iterations: Σᵢ f(i). For i from 1 to n with inner loop running n/i times, the sum is n·Hₙ = O(n log n), not O(n²).
Assuming recursion depth equals the number of function calls.
Depth is the maximum number of frames on the stack at once; total calls can be much larger in a branching recursion.

Original teaching example · not a PYQ

Work through the reasoning

Original mini-example: trace selection sort on the array [29, 10, 14, 37, 13]. Show the array after each pass and count the total comparisons.

  1. Pass 1: scan indices 0–4, minimum is 10 at index 1. Swap with index 0 → [10, 29, 14, 37, 13]. Comparisons: 4.
  2. Pass 2: scan indices 1–4, minimum is 13 at index 4. Swap with index 1 → [10, 13, 14, 37, 29]. Comparisons: 3.
  3. Pass 3: scan indices 2–4, minimum is 14 at index 2. Already in place → [10, 13, 14, 37, 29]. Comparisons: 2.
  4. Pass 4: scan indices 3–4, minimum is 29 at index 4. Swap with index 3 → [10, 13, 14, 29, 37]. Comparisons: 1.

Sorted array: [10, 13, 14, 29, 37]. Total comparisons: 4 + 3 + 2 + 1 = 10 = n(n−1)/2 for n = 5.

Try it before reading the answer

Separate original check: how many comparisons does binary search need in the worst case for a sorted array of 15 elements?

Show answer and reasoning

4 comparisons.

Each comparison halves the search space. Starting from 15 elements: 15 → 7 → 3 → 1 → found or not found. The worst case is ⌊log₂(15)⌋ + 1 = 3 + 1 = 4 comparisons.

Go deeper with free learning resources

Supplemental reading, not an official GATE reading list or an endorsement of these notes.

Apply this to the previous-year questions

Previous-year questions by year

This page shows 32 recent questions from the released archive, newest first. For older questions and complete papers, browse all GATE DA papers. Questions can carry more than one subject tag; counts are not marks weightage.

GATE DA 20269 questions

  1. Set 1 Q15Consider that the quick sort algorithm is used to sort an array of nn distinct randomly ordered elements. In every call, the pivot is chosen as the first…MCQ · +1 marks · Medium
  2. Set 1 Q16Consider the given Python program. [code] Which of the following is the correct output of this program?MCQ · +1 marks · Medium
  3. Set 1 Q25You are given the following Pre-order and In-order traversals of a Binary Tree T with nodes E, F, G, P, Q, R, S. Pre-order: P Q S E R F G In-order: S Q E P F R…MSQ · +1 marks · Easy
  4. Set 1 Q31Let A be a sorted array containing 1000 distinct integers. You perform a recursive binary search on A to find an element y. Suppose each comparison checks…NAT · +1 marks · Medium
  5. Set 1 Q39A recursive function in Python is given. [code] Now, consider the following function call: mystery(4) Assume that a typical runtime stack is used to manage…MCQ · +2 marks · Medium
  6. Set 1 Q40Consider a directed graph G=(V,E)G = (V, E), where VV is the finite set of vertices and EE is the set of directed edges between the vertices. GG may contain…MCQ · +2 marks · Medium
  7. Set 1 Q49Consider the problem of sorting the given array in ascending order: P=[1,2,3,5,4]P = [1, 2, 3, 5, 4] Consider two sorting algorithms Bubble Sort (BS) and Insertion Sort…MSQ · +2 marks · Medium
  8. Set 1 Q50Consider the given Python program. [code] Which of the following options is/are correct?MSQ · +2 marks · Medium
  9. Set 1 Q58Consider the given Python program. [code] The output of the program is __________ . (Answer in integer)NAT · +2 marks · Medium

GATE DA 202510 questions

  1. Set 1 Q12The number of additions and multiplications involved in performing Gaussian elimination on any n×nn \times n upper triangular matrix is of the orderMCQ · +1 marks · Medium
  2. Set 1 Q18Consider a hash table of size 10 with indices {0,1,,9}\{0, 1, \dots, 9\}, with the hash function h(x)=3x(mod10),h(x) = 3x \pmod{10}, where linear probing is used to handle…MCQ · +1 marks · Easy
  3. Set 1 Q23Consider the following Python declarations of two lists. [code] Which one of the following statements results in A= [1, 2, 3, 4, 5, 6]?MCQ · +1 marks · Easy
  4. Set 1 Q27For which of the following inputs does binary search take time O(logn)O(\log n) in the worst case?MSQ · +1 marks · Easy
  5. Set 1 Q29Suppose that insertion sort is applied to the array [1,3,5,7,9,11,x,15,13][1, 3, 5, 7, 9, 11, x, 15, 13] and it takes exactly two swaps to sort the array. Select all possible…MSQ · +1 marks · Medium
  6. Set 1 Q47Consider the following Python code snippet. [code] When the above program is executed, at the end, which of the following sets contains "this"?MCQ · +2 marks · Medium
  7. Set 1 Q58Let GG be a simple, unweighted, and undirected graph. A subset of the vertices and edges of GG are shown below. [figure] It is given that abcda - b - c - d is…MSQ · +2 marks · Medium
  8. Set 1 Q63Consider the following Python code snippet. [code] The value printed by the code snippet is __________ (Answer in integer)NAT · +2 marks · Medium
  9. Set 1 Q64Consider the following pseudocode. [code] The value of sum output by a program executing the above pseudocode is ________ (Answer in integer)NAT · +2 marks · Medium
  10. Set 1 Q65Consider a directed graph G=(V,E)G = (V, E), where V={0,1,2,,100}V = \{0, 1, 2, \dots, 100\} and E={(i,j):0<ji2,for all i,jV}E = \{(i, j) : 0 < j - i \le 2, \text{for all } i, j \in V \}. Suppose the…NAT · +2 marks · Hard

GATE DA 202413 questions

  1. Set 1 Q14Consider performing depth-first search (DFS) on an undirected and unweighted graph GG starting at vertex ss. For any vertex uu in GG, d[u]d[u] is the length…MCQ · +1 marks · Medium
  2. Set 1 Q16Match the items in Column 1 with the items in Column 2 in the following table: | Column 1 | Column 2 | |---|---| | (p) First In First Out | (i) Stacks…MCQ · +1 marks · Easy
  3. Set 1 Q21Consider performing uniform hashing on an open address hash table with load factor α=nm<1\alpha = \frac{n}{m} < 1, where nn elements are stored in the table with…MCQ · +1 marks · Medium
  4. Set 1 Q28Consider the following tree traversals on a full binary tree: (i) Preorder (ii) Inorder (iii) Postorder Which of the following traversal options is/are…MSQ · +1 marks · Medium
  5. Set 1 Q30Consider sorting the following array of integers in ascending order using an in-place Quicksort algorithm that uses the last element as the pivot. [figure] The…NAT · +1 marks · Medium
  6. Set 1 Q32The fundamental operations in a double-ended queue D are: insertFirst(e) – Insert a new element e at the beginning of D. insertLast(e) – Insert a new…NAT · +1 marks · Easy
  7. Set 1 Q38Consider the following Python code: [code] Which ONE of the following is the output of this code?MCQ · +2 marks · Easy
  8. Set 1 Q39Consider the function computeS(XX) whose pseudocode is given below: [code] Which ONE of the following values is returned by the function…MCQ · +2 marks · Easy
  9. Set 1 Q40Let F(n)F(n) denote the maximum number of comparisons made while searching for an entry in a sorted array of size nn using binary search. Which ONE of the…MCQ · +2 marks · Easy
  10. Set 1 Q41Consider the following Python function: [code] What does this Python function fun() do? Select the ONE appropriate option below.MCQ · +2 marks · Easy
  11. Set 1 Q45Consider the following sorting algorithms: (i) Bubble sort (ii) Insertion sort (iii) Selection sort Which ONE among the following choices of sorting…MCQ · +2 marks · Medium
  12. Set 1 Q51Consider the directed acyclic graph (DAG) below: [figure] Which of the following is/are valid vertex orderings that can be obtained from a topological sort of…MSQ · +2 marks · Medium
  13. Set 1 Q52Let H,I,LH, I, L, and NN represent height, number of internal nodes, number of leaf nodes, and the total number of nodes respectively in a rooted binary tree.…MSQ · +2 marks · Medium

Other GATE DA topics

Continue learning with Success Tracker

Keep working on Programming, Data Structures & Algorithms

Reading a solution is a useful start. In Success Tracker, you can attempt questions yourself, review mistakes and return to the topics that need another pass.

AI-powered practice· Unlimited practice on eligible plans
PYQs with solutions
Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
Practice that adapts
Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
AI doubt support
Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.

Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.

This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.