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 PYQ2016Programming and Data StructuresBinary HeapsNAT · 1 mark
A complete binary min-heap is made by including each integer in [1,1023][1, 1023] exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is at depth 00. The maximum depth at which integer 99 can appear is _________.
Official PYQ2016Programming and Data StructuresProgramming in CMCQ · 1 mark
The following function computes XYX^{Y} for positive integers XX and YY. int exp (int X, int Y) { int res =1, a = X, b = Y; while (b != 0) { if (b % 2 == 0) {a = a * a; b = b/2; } else {res = res * a; b = b - 1; } } return res; } Which one of the following conditions is TRUE before every iteration of the loop?
Official PYQ2016Programming and Data StructuresProgramming in CNAT · 1 mark
The value printed by the following program is _______. void f (int * p, int m) { m = m + 5; *p = *p + m; return; } void main () { int i=5, j=10; f (&i, j); printf ("%d", i+j); }
Official PYQ2016Programming and Data StructuresLinked ListsMCQ · 1 mark
NN items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the list in this order: Θ(N)\Theta \left(N\right) delete, …
Official PYQ2015Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
What is the output of the following C code? Assume that the address of xx is 20002000 (in decimal) and an integer requires four bytes of memory. int main () { unsigned int x [4] [3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; printf ("%u, %u, %u", x + 3, *(x + 3), *(x + 2) + 3); }
Official PYQ2015Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following pseudo code, where xx and yy are positive integers. begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end end The post condition that needs to be satisfied after the program terminates is
Official PYQ2015Programming and Data StructuresBinary HeapsMCQ · 1 mark
Consider a max heap, represented by the array: 40,30,20,10,15,16,17,8,440, 30, 20, 10, 15, 16, 17, 8, 4. …
Official PYQ2015Programming and Data StructuresTreesMCQ · 1 mark
The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a binary tree of height 55 are
Official PYQ2015Programming and Data StructuresBinary Search TreesMCQ · 1 mark
What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
Official PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
The output of the following C program is_____________. void f1 ( int a, int b) { int c; c = a; a = b; b = c; } void f2 ( int * a, int * b) { int c; c = * a; *a = *b; *b = c; } int main () { int a = 4, b = 5, c = 6; f1 ( a, b); f2 (&b, &c); printf ("%d", c - a - b); }
Official PYQ2015Programming and Data StructuresBinary Search TreesMCQ · 1 mark
Which of the following is/are correct in order traversal sequence(s) of binary search tree(s)? 3,5,7,8,15,19,253, 5, 7, 8, 15, 19, 25 5,8,9,12,10,15,255, 8, 9, 12, 10, 15, 25 2,7,10,8,14,16,202, 7, 10, 8, 14, 16, 20 4,6,7,9,18,20,254, 6, 7, 9, 18, 20, 25
Official PYQ2015Programming and Data StructuresArrays, Stacks and QueuesNAT · 1 mark
Consider the C program below #include <stdio.h> int *A, stkTop; int stkFunc (int opcode, int val) { static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1; } int main() { int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc …
Official PYQ2015Programming and Data StructuresGraphsMCQ · 1 mark
Which one of the following hash functions on integers will distribute keys most uniformly over 1010 buckets numbered 00 to 99 for ii ranging from 00 to 20202020?
Official PYQ2015Programming and Data StructuresArrays, Stacks and QueuesNAT · 1 mark
A Young tableau is a 2D2D array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked with ∞\infty, and hence there cannot be any entry to the right of, or below a ∞\infty. The following Young tableau consists of unique entries. …
Official PYQ2015Programming and Data StructuresBinary HeapsMCQ · 1 mark
Consider a complete binary tree where the left and right subtrees of the root are max-heaps. The lower bound for the number of operations to convert the tree to a heap is
Official PYQ2015Programming and Data StructuresRecursionMCQ · 1 mark
Consider the following function written in the C programming langauge : void foo(char *a) { if (*a && *a != ' ') { foo(a+1); putchar(*a); } } The output of the above function on input "ABCD EFGHABCD \ EFGH" is
Official PYQ2015Programming and Data StructuresTreesNAT · 1 mark
A binary tree T has 2020 leaves. The number of nodes in T having two children is ______.
Official PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program: #include<stdio.h> int f1(void); int f2(void); int f3(void); int x=10; int main() { int x=1; x += f1() + f2 () + f3() + f2(); printf("%d", x); return 0; } int f1() { int x = 25; x++; return x;} int f2() { static int x = 50; x++; return x;} int f3() { x *= 10; return x;} The output of the program is ______.
Official PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program: #include<stdio.h> int main() { int i, j, k = 0; j=2 * 3 / 4 + 2.0 / 5 + 8 / 5; k-=--j; for (i=0; i<5; i++) { switch(i+k) { case 1: case 2: printf("\n%d", i+k); case 3: printf("\n%d", i+k); default: printf("\n%d", i+k); } } return 0; } The number of times printf statement is executed is _______.
Official PYQ2015Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Consider the following two C code segments. YY and XX are one and two dimensional arrays of size nn and n×nn \times n respectively, where 2≤n≤102 \leq n \leq 10. Assume that in both code segments, elements of YY are initialized to 00 and each element X[i][j]X[i][j] of array XX is initialized to i+ji+j. Further assume that when stored in main …