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 PYQ2026Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following program in C: #include <stdio.h> void func(int i, int j) { if(i < j) { int i = 0; while (i < 10) { j += 2; i++; } } printf("%d", i); } int main() { int i = 9, j = 10; func(i, j); return 0; } The output of the program is ______\_\_\_\_\_\_. (answer in integer) Note: Assume that the program compiles and runs successfully.
Official PYQ2026Programming and Data StructuresLinked ListsMCQ · 2 marks
Consider the following code snippet in C language that computes the number of nodes in a non-empty singly linked list pointed to by the pointer variable head. struct node{ int elt; struct node *next; }; int getListSize (struct node *head) { if( E1 ) return 1; return E2; } Which one of the following options gives the correct replacements for the expressions …
Official PYQ2026Programming and Data StructuresTreesMCQ · 1 mark
The set T\mathbf{T} represents various traversals over binary tree. The set S\mathbf{S} represents the order of visiting nodes during a traversal. …
Official PYQ2026Programming and Data StructuresProgramming in CMCQ · 1 mark
In C runtime environment, which one of the following is stored in heap?
Official PYQ2026Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following three ANSI-C programs, P1, P2,\text{P1, P2,} and P3\text{P3}. …
Official PYQ2026Programming and Data StructuresArrays, Stacks and QueuesMSQ · 2 marks
Consider a stack SS and a queue QQ. Both of them are initially empty and have the capacity to store ten elements each. The elements 1,2,3,41,2,3,4, and 55 arrive one by one, in that order. When an element arrives, it is assigned either to SS (pushed on SS ) or to QQ (enqueued to QQ ). Once all the five elements are stored, the output is …
Official PYQ2026Programming and Data StructuresProgramming in CNAT · 2 marks
Consider the following ANSI-C program. #include <stdio.h> int main(){ int *ptr, a, b, c; a=5; b=11; c=20; ptr=&a; *ptr=c; ptr=&c; a=*(&b); c=*ptr-a; printf("%d",c); return(0); } The output of this program is ____\_\_\_\_ . (answer in integer) Note: Assume that the program compiles and runs successfully.
Official PYQ2026Programming and Data StructuresRecursionNAT · 2 marks
Consider the following ANSI-C function. int func(int start, int end){ int length=end+1-start; if((length<1)||(start<0)||(end<0)){ return(0); } if(length%3==0){ return(func(start+1, end)); }else if(length%3==1){ return(1+func(start, end-1)); }else { return(func(start+2, end)); } } The maximum possible value that can be returned from this function is …
Official PYQ2025Programming and Data StructuresBinary Search TreesMSQ · 1 mark
Which of the following statement(s) is/are TRUE for any binary search tree (BST) having nn distinct integers?
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 1 mark
#include <stdio.h> void foo(int *p, int x) { *p=x; } int main(){ int *z; int a = 20, b = 25; z = &a; foo(z,b); printf("%d",a); return 0; } The output of the given C\text{C} program is __________. (Answer in integer)
Official PYQ2025Programming and Data StructuresBinary HeapsNAT · 1 mark
The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node. Suppose a Min-Heap T\text{T} stores 3232 keys. The height of T\text{T} is ___________. (Answer in integer)
Official PYQ2025Programming and Data StructuresRecursionNAT · 2 marks
#include <stdio.h> int foo(int S[],int size) { if(size == 0) return 0; if(size == 1) return 1; if(S[0] != S[1]) return 1+foo(S+1,size-1); return foo(S+1,size-1); } int main() { int A[]={0,1,2,2,2,0,0,1,1}; printf("%d",foo(A,9)); return 0; } The value printed by the given CC program is ___________. (Answer in integer)
Official PYQ2025Programming and Data StructuresLinked ListsNAT · 2 marks
Let LIST\mathrm{LIST} be a datatype for an implementation of linked list defined as follows: typedef struct list { int data; struct list *next; } LIST; Suppose a program has created two linked lists, L1L1 and L2L2, whose contents are given in the figure below (code for creating L1L1 and L2L2 is not provided here). L1L1 contains 99 nodes, and …
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 2 marks
Consider the following C program: #include <stdio.h> int gate (int n) { int d, t, newnum, turn; newnum = turn = 0; t=1; while (n>=t) t *= 10; t /=10; while (t>0) { d = n/t; n = n%t; t /= 10; if (turn) newnum = 10*newnum + d; turn = (turn + 1) % 2; } return newnum; } int main () { printf ("%d", gate(14362)); return 0; } The value printed by the …
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 2 marks
Consider the following C program: #include<stdio.h> int main(){ int a; int arr[5] = {30,50,10}; int *ptr; ptr = &arr[0] + 1; a = *ptr; (*ptr)++; ptr++; printf("%d", a + (*ptr) + arr[1]); return 0; } The output of the above program is _________. (Answer in integer)
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 2 marks
Consider the following C program: #include <stdio.h> int g(int n) { return (n+10); } int f(int n) { return g(n*2); } int main() { int sum, n; sum=0; for (n=1; n<3; n++) sum += g(f(n)); printf ("%d", sum); return 0; } The output of the given C program is ___________. (Answer in integer)
Official PYQ2025Programming and Data StructuresTreesMCQ · 1 mark
​​​​Consider a binary tree TT in which every node has either zero or two children. Let n>0n>0 be the number of nodes in TT. Which ONE of the following is the number of nodes in TT that have exactly two children?
Official PYQ2025Programming and Data StructuresProgramming in CMCQ · 1 mark
​​​​​Consider the following C program: #include <stdio.h> void stringcopy (char *, char *); int main() { char a[30] = "@#Hello World!"; stringcopy(a, a+2); printf("%s\n",a); return 0; } void stringcopy(char *s, char *t) { while (*t) *s++=*t++; } Which one of the following will be the output of the program?
Official PYQ2025Programming and Data StructuresProgramming in CNAT · 1 mark
int x=126,y=105; do { if(x>y) x=x-y; else y=y-x; } while(x!=y); printf("%d",x); The output of the given C code segment is _________. (Answer in integer)
Official PYQ2025Programming and Data StructuresBinary Search TreesNAT · 1 mark
Suppose the values 10,−4,15,30,20,5,60,1910,-4,15,30,20,5,60,19 are inserted in that order into an initially empty binary search tree. Let TT be the resulting binary search tree. The number of edges in the path from the node containing 1919 to the root node of TT is _________. (Answer in integer)