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
A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures: P. Unsorted doubly linked list with pointers to the head node and tail node of the list. Q. Min-heap implemented using an array. R. Binary Search Tree. Which ONE of the following options gives the …
Consider a stack data structure into which we can PUSH and POP records. Assume that each record pushed in the stack has a positive integer key and that all keys are distinct. We wish to augment the stack data structure with an time MIN operation that returns a pointer to the record with smallest key present in the stack without deleting the …
Consider the following program: #include <stdio.h> int main() { int a=6; int b = 0; while (a<10) { a = a / 12+1 ; a += b ;} printf ("%d", a); return 0 ; } Which one of the following statements is CORRECT?
Consider the following program: #include <stdio.h> void fX (); int main(){ fX(); return 0 }; void fX () { char a; if ((a=g e t c h a r()) ! = '\n') fX(); if (a ! = '\n') putchar (a); } Assume that the input to the program from the command line is followed by a newline character. Which one of the following statements is …
Consider a binary min-heap containing distinct elements. Let be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of is
Consider the following function definition. int f (int x, int y){ for (int i=0 ; i<y ; i++ ) { x= x + x + y; } return x; } Which of the following statements is/are TRUE about the above function?
Consider the following program. Assume parameters to a function are evaluated from right to left. #include <stdio.h> int g(int p) { printf("%d", p); return p; } int h(int q) { printf("%d", q); return q; } void f(int x, int y) { g(x); h(y); } int main() { f(g(10), h(20)); } Which one of the following options is the CORRECT output of the …
Consider the following function definition. int fX(char *a) { char *b = a; while (*b) b++; return b - a; } Which of the following statements is/are TRUE?
What is the output of the following program? #include <stdio.h> int main() { double a[2]={20.0,25.0},* p,* q; p=a ; q=p+1 ; printf("%d,%d", (int) (q-p),( int)(* q- * p)); return 0;}
You are given a set of distinct integers. A binary search tree is created by inserting all elements of one by one, starting with an empty tree. The tree follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in …
Let and be two stacks. has capacity of elements. has capacity of elements. already has elements: , and , whereas is empty, as shown below. …
Which one of the following sequences when stored in an array at locations forms a max-heap?
Let be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list. Let denote the number of nodes in each …
The integer value printed by the program given below is _______________ #include<stdio.h> int funcp(){ static int x = 1; x++; return x; } int main(){ int x,y; x = funcp(); y = funcp()+x; printf("%d\n", (x+y)); return 0; }
Let be a priority queue for maintaining a set of elements. Suppose is implemented using a max-heap data structure. The operation extracts and deletes the maximum element from . The operation inserts a new element in . The properties of a max-heap are preserved at the …
Consider the function and the binary tree shown. typedef struct node { int val; struct node *left, *right; } node; int foo(node *p) { int retval; if (p == NULL) return 0; else { retval = p->val + foo(p->left) + foo(p->right); printf("%d ", retval); return retval; } } When is called with a pointer to the …
Consider a sequence of elements , and . The following operations are performed on a stack and a queue both of which are initially empty. the elements of from to in that order into . the elements of from …
Consider the problem of reversing a singly linked list. To take an example, given the linked list below, the reversed linked list should look like Which one of the following statements is about the time complexity of algorithms that solve the above problem in space?
What is printed by the following program? #include<stdio.h> int main(int argc, char *argv[]) { int x = 1, z[2] = {10, 11}; int *p = NULL; p = &x; *p = 10; p = &z[1]; *(&z[0] + 1) += 3; printf(“%d, %d, %d\n”, x, z[0], z[1]); return 0; }
Suppose a binary search tree with distinct elements is also a complete binary tree. The tree is stored using the array representation of binary heap trees. Assuming that the array indices start with the largest element of the tree is stored at index ______________ .
