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
Consider the following rooted tree with the vertex labeled as the root: The order in which the nodes are visited during an in-order traversal of the tree is
The procedure given below is required to find and replace certain characters inside an input character string supplied in array . The characters to be replaced are supplied in array , while their respective replacement characters are supplied in array . Array has a fixed length of five characters, while arrays and …
The procedure given below is required to find and replace certain characters inside an input character string supplied in array . The characters to be replaced are supplied in array , while their respective replacement characters are supplied in array . Array has a fixed length of five characters, while arrays and …
The preorder traversal sequence of a binary search tree is . Which one of the following is the postorder traversal sequence of the same tree?
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 nodes?
What is the return value of , if the value of is initialized to 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; }
Consider the following operation along with Enqueue and Dequeue operations on queues, where 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 queue operations on an initially empty queue?
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 …
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; // …
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?
Suppose a circular queue of capacity elements is implemented with an array of elements. Assume that the insertion and deletion operations are carried out using and as array index variables, respectively. Initially, . The conditions to detect queue full and queue empty …
The worst case running time to search for an element in a balanced binary search tree with elements is
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"); }
We are given a set of distinct elements and an unlabeled binary tree with nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
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?
What does the following fragment of C program print? char c[] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p[1]);
A hash table of length uses open addressing with hash function , and linear probing. After inserting values into an empty hash table, the table is shown as below …
A hash table of length uses open addressing with hash function , and linear probing. After inserting values into an empty hash table, the table is shown as below …
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 == …
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; }
