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
Let be a binary search tree with nodes. The minimum and maximum possible heights of are: Note: The height of a tree with a single node is .
Consider the following snippet of a C program. Assume that swap exchanges the content of and : 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 …
Consider the C program fragment below which is meant to divide by using repeated subtractions. The variables , , and are all unsigned int. while (r >= y) { r=r-y; q=q+1; } Which of the following conditions on the variables and before the execution of the fragment will ensure that the loop terminated in a …
The pre-order traversal of a binary search tree is given by . Then the post-order traversal of this tree is
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 _______
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 ______
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 …
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 is:
Match the following: …
Consider the weighted undirected graph with vertices, where the weight of edge is given by the entry in the matrix . W= The largest possible integer value of , for which at least one …
What will be the output of the following 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); }
An operator delete for a binary heap data structure is to be designed to delete the item in the -th node. Assume that the heap is implemented in an array and refers to the -th index of the array. If the heap tree has depth (number of edges on the path from the root to the farthest leaf ), then what is the time complexity to …
The following function computes the maximum value contained in an integer array of size . 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:
Let denote a queue containing sixteen numbers and be an empty stack. returns the element at the head of the queue without removing it from . Similarly returns the element at the top of without removing it from . Consider the algorithm given below. while Q is not Empty do if S is Empty OR Top(S) ≤ Head …
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT ( refers to the number of items in the queue) ?
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 _________.
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?
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: returns the maximum of and . The value printed by this program is ________.
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:
The number of ways in which the numbers can be inserted in an empty binary search tree, such that the resulting tree has height , is _________. Note: The height of a tree with a single node is .
