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 PYQ2017Programming and Data StructuresBinary Search TreesMCQ · 1 mark
Let TT be a binary search tree with 1515 nodes. The minimum and maximum possible heights of TT are: Note: The height of a tree with a single node is 00.
Official PYQ2017Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following snippet of a C program. Assume that swap (&x,&y)(\&x, \&y) exchanges the content of xx and yy: int main () { int array[] = {3, 5, 1, 4, 6, 2}; int done =0; int i; while (done==0) { done =1; for (i=0; i<=4; i++) { if (array[i] < array[i+1]) { swap(&array[i], &array[i+1]); done=0; } } for (i=5; i>=1; i--) { if …
Official PYQ2017Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the C program fragment below which is meant to divide xx by yy using repeated subtractions. The variables xx, yy, qq and rr are all unsigned int. while (r >= y) { r=r-y; q=q+1; } Which of the following conditions on the variables x,y,qx, y, q and rr before the execution of the fragment will ensure that the loop terminated in a …
Official PYQ2017Programming and Data StructuresBinary Search TreesMCQ · 1 mark
The pre-order traversal of a binary search tree is given by 12,8,6,2,7,9,10,16,15,19,17,2012, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20. Then the post-order traversal of this tree is
Official PYQ2017Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program. #include<stdio.h> #include<string.h> int main() { char* c="GATECSIT2017"; char* p=c; printf("%d", (int)strlen(c+2[p]-6[p]-1)); return 0; } The output of the program is _______
Official PYQ2017Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program. #include<stdio.h> int main () { int m=10; int n, n1; n=++m; n1=m++; n--; --n1; n-=n1; printf(“%d”, n); return 0; } The output of the program is ______
Official PYQ2017Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
A circular queue has been implemented using a singly linked list where each node consists of a value and a single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR pointing to the front node and the rear node of the queue, respectively. Which of the following statements is/are CORRECT for such a circular queue, so …
Official PYQ2017Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following function implemented in C: void printxy(int x, int y) { int *ptr; x=0; ptr=&x; y=*ptr; *ptr=1; printf(“%d, %d”, x, y); } The output of invoking printxy(1,1)printxy(1,1) is:
Official PYQ2017Programming and Data StructuresProgramming in CMCQ · 1 mark
Match the following: …
Official PYQ2016Programming and Data StructuresGraphsNAT · 1 mark
Consider the weighted undirected graph with 44 vertices, where the weight of edge {i,j}\{i,j\} is given by the entry WijW_{ij} in the matrix WW. W=[02852058850x58x0]\begin{bmatrix} 0&2 &8 &5 \\ 2&0 &5 &8 \\ 8&5 &0 &x \\ 5& 8 &x &0 \end{bmatrix} The largest possible integer value of xx, for which at least one …
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
What will be the output of the following CC program? void count (int n) { static int d=1; printf ("%d",n); printf ("%d",d); d++; if (n>1) count (n-1); printf ("%d",d); } void main(){ count (3); }
Official PYQ2016Programming and Data StructuresBinary HeapsMCQ · 1 mark
An operator delete(i)(i) for a binary heap data structure is to be designed to delete the item in the ii-th node. Assume that the heap is implemented in an array and ii refers to the ii-th index of the array. If the heap tree has depth dd (number of edges on the path from the root to the farthest leaf ), then what is the time complexity to …
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
The following function computes the maximum value contained in an integer array P[ ]P[ \ ] of size nn (n>=1)(n>=1). int max (int *p,int n) { int a = 0, b=n-1; while (__________) { if (p[a]<= p[b]) {a = a+1;} else {b = b-1;} } return p[a]; } The missing loop condition is:
Official PYQ2016Programming and Data StructuresArrays, Stacks and QueuesNAT · 1 mark
Let QQ denote a queue containing sixteen numbers and SS be an empty stack. Head(Q)Head(Q) returns the element at the head of the queue QQ without removing it from QQ. Similarly Top(S)Top(S) returns the element at the top of SS without removing it from SS. Consider the algorithm given below. while Q is not Empty do if S is Empty OR Top(S) ≤ Head …
Official PYQ2016Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (nn refers to the number of items in the queue) ?
Official PYQ2016Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program. # include <stdio.h> void mystery (int *ptra, int *ptrb) { int *temp; temp = ptrb; ptrb =ptra; ptra = temp; } int main () { int a = 2016, b=0, c= 4, d = 42; mystery (&a, &b); if (a < c) mystery (&c, &a); mystery (&a, &d); printf("%d\n", a); } The output of the program is _________.
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following "C" program. void f(int, short); void main() { int i = 100; short s = 12; short *p = &s; ____________; // call to f() } Which one of the following expressions , when placed in the blank above, will NOT result in a type checking error?
Official PYQ2016Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following program: int f (int * p, int n) { if (n <= 1) return 0; else return max (f (p+1, n-1), p[0] - p[1]); } int main () { int a[] = {3, 5, 2, 6, 4}; printf(" %d", f(a, 5)); } Note: max⁡(x,y)\max (x, y) returns the maximum of xx and yy. The value printed by this program is ________.
Official PYQ2016Programming and Data StructuresTreesMCQ · 1 mark
Consider the following New-order strategy for traversing a binary tree: Visit the root; Visit the right subtree using New-order; Visit the left subtree using New-order; The New-order traversal of the expression tree corresponding to the reverse polish expression 3 4 * 5 - 2 ^ 6 7 * 1 + - is given by:
Official PYQ2016Programming and Data StructuresBinary Search TreesNAT · 1 mark
The number of ways in which the numbers 1,2,3,4,5,6,71, 2, 3, 4, 5, 6, 7 can be inserted in an empty binary search tree, such that the resulting tree has height 66, is _________. Note: The height of a tree with a single node is 00.