Skip to content

GATE CS Programming and Data Structures questions

Practise Programming and Data Structures questions for GATE CS. Explore official PYQs and original subject-wise quizzes, check answers and view available solutions. Free, no sign-in.

Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.

20 on this page
Official PYQ2025Programming and Data StructuresArrays, Stacks and QueuesMCQ · 2 marks
​A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures: P. Unsorted doubly linked list with pointers to the head node and tail node of the list. Q. Min-heap implemented using an array. R. Binary Search Tree. Which ONE of the following options gives the …
Official PYQ2025Programming and Data StructuresArrays, Stacks and QueuesMCQ · 2 marks
​​​Consider a stack data structure into which we can PUSH and POP records. Assume that each record pushed in the stack has a positive integer key and that all keys are distinct. We wish to augment the stack data structure with an O(1)O(1) time MIN operation that returns a pointer to the record with smallest key present in the stack without deleting the …
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following C\mathrm{C} program: #include <stdio.h> int main() { int a=6; int b = 0; while (a<10) { a = a / 12+1 ; a += b ;} printf ("%d", a); return 0 ; } Which one of the following statements is CORRECT?
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 1 mark
​​​Consider the following C\mathrm{C} program: #include <stdio.h> void fX (); int main(){ fX(); return 0 }; void fX () { char a; if ((a=g e t c h a r()) ! = '\n') fX(); if (a ! = '\n') putchar (a); } Assume that the input to the program from the command line is 12341234 followed by a newline character. Which one of the following statements is …
Official PYQ2024Programming and Data StructuresBinary HeapsMCQ · 2 marks
Consider a binary min-heap containing 105105 distinct elements. Let kk be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of kk is
Official PYQ2024Programming and Data StructuresProgramming in CMSQ · 2 marks
​​Consider the following C\mathrm{C} function definition. int f (int x, int y){ for (int i=0 ; i<y ; i++ ) { x= x + x + y; } return x; } Which of the following statements is/are TRUE about the above function?
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following C\text{C} program. Assume parameters to a function are evaluated from right to left. #include <stdio.h> int g(int p) { printf("%d", p); return p; } int h(int q) { printf("%d", q); return q; } void f(int x, int y) { g(x); h(y); } int main() { f(g(10), h(20)); } Which one of the following options is the CORRECT output of the …
Official PYQ2024Programming and Data StructuresProgramming in CMSQ · 1 mark
​​​Consider the following C\mathrm{C} function definition. int fX(char *a) { char *b = a; while (*b) b++; return b - a; } Which of the following statements is/are TRUE?
Official PYQ2024Programming and Data StructuresProgramming in CMCQ · 2 marks
​​​​​What is the output of the following C\text{C} program? #include <stdio.h> int main() { double a[2]={20.0,25.0},* p,* q; p=a ; q=p+1 ; printf("%d,%d", (int) (q-p),( int)(* q- * p)); return 0;}
Official PYQ2024Programming and Data StructuresBinary Search TreesMCQ · 2 marks
​​​​​​You are given a set VV of distinct integers. A binary search tree TT is created by inserting all elements of VV one by one, starting with an empty tree. The tree TT follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in …
Official PYQ2024Programming and Data StructuresArrays, Stacks and QueuesMSQ · 2 marks
​​​​​Let S1\mathrm{S} 1 and S2\mathrm{S} 2 be two stacks. S1\mathrm{S} 1 has capacity of 44 elements. S2\mathrm{S} 2 has capacity of 22 elements. S1\text{S1} already has 44 elements: 100,200,300100,200,300, and 400400, whereas S2\text{S2} is empty, as shown below. …
Official PYQ2023Programming and Data StructuresBinary HeapsMCQ · 1 mark
Which one of the following sequences when stored in an array at locations A[1],…,A[10]A[1], \ldots, A[10] forms a max-heap?
Official PYQ2023Programming and Data StructuresLinked ListsMCQ · 1 mark
Let SLLdel\textsf{SLLdel} be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLLdel\textsf{DLLdel} be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list. Let nn denote the number of nodes in each …
Official PYQ2023Programming and Data StructuresProgramming in CNAT · 1 mark
The integer value printed by the ANSI-C\textsf{ANSI-C} program given below is _______________ #include<stdio.h> int funcp(){ static int x = 1; x++; return x; } int main(){ int x,y; x = funcp(); y = funcp()+x; printf("%d\n", (x+y)); return 0; }
Official PYQ2023Programming and Data StructuresBinary HeapsMCQ · 2 marks
Let AA be a priority queue for maintaining a set of elements. Suppose AA is implemented using a max-heap data structure. The operation EXTRACT-MAX(A)\text{EXTRACT-MAX} (A) extracts and deletes the maximum element from AA. The operation INSERT⁡(A,key)\operatorname{INSERT}(A, key ) inserts a new element keykey in AA. The properties of a max-heap are preserved at the …
Official PYQ2023Programming and Data StructuresTreesMCQ · 2 marks
Consider the C\text{C} function foo\text{foo} and the binary tree shown. typedef struct node { int val; struct node *left, *right; } node; int foo(node *p) { int retval; if (p == NULL) return 0; else { retval = p->val + foo(p->left) + foo(p->right); printf("%d ", retval); return retval; } } When foo\textsf{foo} is called with a pointer to the …
Official PYQ2023Programming and Data StructuresArrays, Stacks and QueuesNAT · 2 marks
Consider a sequence aa of elements a0=1,a1=5,a2=7,a3=8,a4=9a_{0}=1, a_{1}=5, a_{2}=7, a_{3}=8, a_{4}=9, and a5=2a_{5}=2. The following operations are performed on a stack SS and a queue Q,Q, both of which are initially empty. push\textsf{push} the elements of aa from a0a_{0} to a5a_{5} in that order into SS. enqueue\textsf{enqueue} the elements of aa from …
Official PYQ2022Programming and Data StructuresLinked ListsMCQ · 1 mark
Consider the problem of reversing a singly linked list. To take an example, given the linked list below, the reversed linked list should look like Which one of the following statements is TRUE\text{TRUE} about the time complexity of algorithms that solve the above problem in O(1)O(1) space?
Official PYQ2022Programming and Data StructuresProgramming in CMCQ · 1 mark
What is printed by the following ANSI C\text{ANSI C} program? #include<stdio.h> int main(int argc, char *argv[]) { int x = 1, z[2] = {10, 11}; int *p = NULL; p = &x; *p = 10; p = &z[1]; *(&z[0] + 1) += 3; printf(“%d, %d, %d\n”, x, z[0], z[1]); return 0; }
Official PYQ2022Programming and Data StructuresBinary Search TreesNAT · 1 mark
Suppose a binary search tree with 10001000 distinct elements is also a complete binary tree. The tree is stored using the array representation of binary heap trees. Assuming that the array indices start with 0,0, the 3rd3^{\text{rd}} largest element of the tree is stored at index ______________ .