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 PYQ2014Programming and Data StructuresTreesMCQ · 1 mark
Consider the following rooted tree with the vertex labeled PP as the root: The order in which the nodes are visited during an in-order traversal of the tree is
Official PYQ2013Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
The procedure given below is required to find and replace certain characters inside an input character string supplied in array AA. The characters to be replaced are supplied in array oldcoldc, while their respective replacement characters are supplied in array newcnewc. Array AA has a fixed length of five characters, while arrays oldcoldc and newcnewc …
Official PYQ2013Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
The procedure given below is required to find and replace certain characters inside an input character string supplied in array AA. The characters to be replaced are supplied in array oldcoldc, while their respective replacement characters are supplied in array newcnewc. Array AA has a fixed length of five characters, while arrays oldcoldc and newcnewc …
Official PYQ2013Programming and Data StructuresBinary Search TreesMCQ · 1 mark
The preorder traversal sequence of a binary search tree is 30,20,10,15,25,23,39,35,4230, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?
Official PYQ2013Programming and Data StructuresBinary Search TreesMCQ · 1 mark
Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary search tree of nn nodes?
Official PYQ2013Programming and Data StructuresProgramming in CNAT · 1 mark
What is the return value of f(p,p)f(p,p), if the value of pp is initialized to 55 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value. int f (int &x, int c) { c = c - 1; if (c==0) return 1; x = x + 1; return f(x,c) * x; }
Official PYQ2013Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Consider the following operation along with Enqueue and Dequeue operations on queues, where kk is a global parameter. MultiDequeue(Q){ m = k while (Q is not empty) and (m > 0) { Dequeue(Q) m = m – 1 } } What is the worst case time complexity of a sequence of nn queue operations on an initially empty queue?
Official PYQ2012Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following C code segment. int a, b, c = 0; void prtFun(void); main() { static int a = 1; /* Line 1 */ prtFun(); a += 1; prtFun(); printf(“ \n %d %d ”, a, b); } void prtFun(void) { static int a = 2; /* Line 2 */ int b = 1; a += ++b; printf(“ \n %d %d ”, a, b); } What output will be generated by the given code segment if: Line 1 is replaced by …
Official PYQ2012Programming and Data StructuresTreesMCQ · 1 mark
The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudo-code below is invoked as height (root) to compute the height of a binary tree rooted at the tree pointer root. int height(treeptr n) { if(n == NULL) return -1; if(n -> left == NULL) if(n -> right == NULL) return 0; else return B1; // …
Official PYQ2012Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following C code segment. int a, b, c = 0; void prtFun(void); main() { static int a = 1; /* Line 1 */ prtFun(); a += 1; prtFun(); printf(“ \n %d %d ”, a, b); } void prtFun(void) { static int a = 2; /* Line 2 */ int b = 1; a += ++b; printf(“ \n %d %d ”, a, b); } What output will be generated by the given code segment?
Official PYQ2012Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Suppose a circular queue of capacity (n−1)(n −1) elements is implemented with an array of nn elements. Assume that the insertion and deletion operations are carried out using REAR\textsf{REAR} and FRONT\textsf{FRONT} as array index variables, respectively. Initially, REAR=FRONT=0\textsf{REAR} = \textsf{FRONT} = 0. The conditions to detect queue full and queue empty …
Official PYQ2012Programming and Data StructuresBinary Search TreesMCQ · 1 mark
The worst case running time to search for an element in a balanced binary search tree with n2nn2^{n} elements is
Official PYQ2012Programming and Data StructuresProgramming in CMCQ · 1 mark
What will be the output of the following C program segment? char inChar = 'A'; switch ( inChar ) { case 'A' : printf ("Choice A \ n"); case 'B' : case 'C' : printf ("Choice B"); case 'D' : case 'E' : default : printf ("No Choice"); }
Official PYQ2011Programming and Data StructuresTreesMCQ · 1 mark
We are given a set of nn distinct elements and an unlabeled binary tree with nn nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
Official PYQ2011Programming and Data StructuresBinary HeapsMCQ · 1 mark
A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?
Official PYQ2011Programming and Data StructuresProgramming in CMCQ · 1 mark
What does the following fragment of C program print? char c[] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p[1]);
Official PYQ2010Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
A hash table of length 1010 uses open addressing with hash function h(k)=k mod   10h(k) = k \: \mod \: 10, and linear probing. After inserting 66 values into an empty hash table, the table is shown as below …
Official PYQ2010Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
A hash table of length 1010 uses open addressing with hash function h(k)=kmod  10h(k) = k \mod 10, and linear probing. After inserting 66 values into an empty hash table, the table is shown as below …
Official PYQ2010Programming and Data StructuresLinked ListsMCQ · 1 mark
The following C function takes a singly-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank. typedef struct node { int value; struct node *next; } Node; Node *move_to-front(Node *head) { Node *p, *q; if ((head == NULL) || (head -> next == …
Official PYQ2010Programming and Data StructuresProgramming in CMCQ · 1 mark
What does the following program print? #include<stdio.h> void f(int *p, int *q) { p=q; *p=2; } int i=0, j=1; int main() { f(&i, &j); printf("%d %d\n", i,j); return 0; }