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 PYQ2022Programming and Data StructuresProgramming in CMCQ · 2 marks
What is printed by the following ANSI C\text{ANSI C} program? #include<stdio.h> int main(int argc, char *argv[]) { char a = ‘P’; char b = ‘x’; char c = (a&b) + ‘*’; char d = (a|b) – ‘-’; char e = (a^b) + ‘+’; printf(“%c %c %c\n”, c, d, e); return 0; } ASCII\text{ASCII} encoding for relevant characters is given below …
Official PYQ2022Programming and Data StructuresArrays, Stacks and QueuesMCQ · 2 marks
What is printed by the following ANSI C\text{ANSI C} program? #include<stdio.h> int main (int argc, char *argv[]) { int a[3][3][3] = {{1, 2, 3, 4, 5, 6, 7, 8, 9}, {10, 11, 12, 13, 14, 15, 16, 17, 18}, {19, 20, 21, 22, 23, 24, 25, 26, 27}}; int i = 0, j = 0, k = 0; for ( i = 0; i < 3; i ++) { for ( k = 0; k < 3; k++) printf(“%d”, a[i][j][k]); printf …
Official PYQ2022Programming and Data StructuresArrays, Stacks and QueuesNAT · 2 marks
Consider the queues Q1Q_{1} containing four elements and Q2Q_{2} containing none (shown as the Initial State\textsf{Initial State} in the figure). The only operations allowed on these two queues are Enqueue (Q, element)\textsf{Enqueue (Q, element)} and Dequeue (Q).\textsf{Dequeue (Q)}. The minimum number of Enqueue\textsf{Enqueue} operations on Q1Q_{1} required to place the elements of …
Official PYQ2021Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
​​​​​Let PP be an array containing nn integers. Let tt be the lowest upper bound on the number of comparisons of the array elements, required to find the minimum and maximum values in an arbitrary array of nn elements. Which one of the following choices is correct?
Official PYQ2021Programming and Data StructuresBinary Search TreesMCQ · 1 mark
A binary search tree TT contains nn distinct elements. What is the time complexity of picking an element in TT that is smaller than the maximum element in TT?
Official PYQ2021Programming and Data StructuresArrays, Stacks and QueuesNAT · 1 mark
Consider the following sequence of operations on an empty stack.push(54);push(52);pop();push(55);push(62);s=pop();\textsf{push}(54);\textsf{push}(52);\textsf{pop}();\textsf{push}(55);\textsf{push}(62);\textsf{s}=\textsf{pop}();Consider the following sequence of operations on an empty queue. …
Official PYQ2021Programming and Data StructuresProgramming in CMCQ · 2 marks
​​​​​Consider the following ANSI C\text{ ANSI C} program. #include <stdio.h> int main() { int i, j, count; count=0; i=0; for (j=-3; j<=3; j++) { if (( j >= 0) && (i++)) count = count + j; } count = count +i; printf("%d", count); return 0; } Which one of the following options is correct?
Official PYQ2021Programming and Data StructuresTreesMCQ · 2 marks
An articulationarticulation pointpoint in a connected graph is a vertex such that removing the vertex and its incident edges disconnects the graph into two or more connected components. Let TT be a DFS\text{DFS} tree obtained by doing DFS\text{DFS} in a connected undirected graph GG. Which of the following options is/are correct?
Official PYQ2021Programming and Data StructuresBinary HeapsMCQ · 1 mark
​​​​​Let HH be a binary min-heap consisting of nn elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in HH?
Official PYQ2021Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following ANSI C\text{ANSI C} program. #include <stdio.h> int main() { int arr[4][5]; int i, j; for (i=0; i<4; i++) ​​​​​​{ for (j=0; j<5; j++) { arr[i][j] = 10 * i + j; } } printf(“%d”, *(arr[1]+9)); return 0; } What is the output of the above program?
Official PYQ2021Programming and Data StructuresTreesNAT · 1 mark
Consider a complete binary tree with 77 nodes. Let AA denote the set of first 33 elements obtained by performing Breadth-First Search (BFS)\text{(BFS)} starting from the root. Let BB denote the set of first 33 elements obtained by performing Depth-First Search (DFS)\text{(DFS)} starting from the root. The value of ∣A−B∣\mid A-B \mid is …
Official PYQ2021Programming and Data StructuresProgramming in CMCQ · 2 marks
Consider the following ANSI C\text{ANSI C} program: #include <stdio.h> #include <stdlib.h> struct Node{ int value; struct Node *next;}; int main( ) { struct Node *boxE, *head, *boxN; int index=0; boxE=head= (struct Node *) malloc(sizeof(struct Node)); head → value = index; for (index =1; index<=3; index++){ boxN = (struct Node *) malloc …
Official PYQ2020Programming and Data StructuresBinary Search TreesMCQ · 1 mark
The preorder traversal of a binary search tree is 15,10,12,11,20,18,16,1915, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the postorder traversal of the tree?
Official PYQ2020Programming and Data StructuresTreesMCQ · 1 mark
What is the worst case time complexity of inserting n2n^{2} elements into an AVL-tree with nn elements initially?
Official PYQ2020Programming and Data StructuresLinked ListsMCQ · 1 mark
What is the worst case time complexity of inserting nn elements into an empty linked list, if the linked list needs to be maintained in sorted order?
Official PYQ2020Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program. #include <stdio.h> int main () { int a[4] [5] = {{1, 2, 3, 4, 5}, {6, 7,8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17,18, 19, 20}}; printf(“%d\n”, *(*(a+**a+2)+3)); return(0); } The output of the program is _______.
Official PYQ2020Programming and Data StructuresBinary Search TreesMCQ · 2 marks
In a balanced binary search tree with nn elements, what is the worst case time complexity of reporting all elements in range [a,b][a,b]? Assume that the number of reported elements is kk.
Official PYQ2020Programming and Data StructuresRecursionNAT · 2 marks
Consider the following C functions. int fun1(int n) { static int i= 0; if (n > 0) { ++i; fun1(n-1); } return (i); } int fun2(int n) { static int i= 0; if (n>0) { i = i+ fun1 (n) ; fun2(n-1) ; } return (i); } The return value of fun2(5)\text{fun}2 (5) is _________
Official PYQ2020Programming and Data StructuresBinary HeapsNAT · 2 marks
Consider the array representation of a binary min-heap containing 10231023 elements. The minimum number of comparisons required to find the maximum in the heap is ___________.
Official PYQ2019Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program : #include<stdio.h> int jumble(int x, int y){ x = 2*x+y; return x; } int main(){ int x=2, y=5; y=jumble(y,x); x=jumble(y,x); printf("%d \n",x); return 0; } The value printed by the program is ______________.