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 PYQ2006Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code. subroutine swap(ix,iy) it = ix L1 : ix = iy L2 : iy = it end ia = 3 ib = 8 call swap (ia, ib+5) print *, ia, ib end S1: The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the …
Official PYQ2006Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider this C code to swap two integers and these five statements: the code void swap (int *px, int *py) { *px = *px - *py; *py = *px + *py; *px = *py - *px; } S1: will generate a compilation error S2: may generate a segmentation fault at runtime depending on the arguments passed S3: correctly implements the swap procedure for all input pointers referring …
Official PYQ2006Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
An implementation of a queue QQ, using two stacks S1S1 and S2S2, is given below: void insert (Q, x) { push (S1, x); } void delete (Q) { if (stack-empty(S2)) then if (stack-empty(S1)) then { print(“Q is empty”); return; } else while (!(stack-empty(S1))){ x=pop(S1); push(S2,x); } x=pop(S2); } Let nn insert and m(≤n)m(\leq n) delete operations be …
Official PYQ2006Programming and Data StructuresTreesMCQ · 1 mark
A scheme for storing binary trees in an array XX is as follows. Indexing of XX starts at 11 instead of 00. the root is stored at X[1]X[1]. For a node stored at X[i]X[i], the left child, if any, is stored in X[2i]X[2i] and the right child, if any, in X[2i+1]X[2i+1]. To be able to store any binary tree on n vertices the minimum size of XX should be
Official PYQ2006Programming and Data StructuresBinary HeapsMCQ · 1 mark
In a binary max heap containing nn numbers, the smallest element can be found in time
Official PYQ2005Programming and Data StructuresRecursionMCQ · 1 mark
double foo(int n) { int i; double sum; if(n == 0) { return 1.0; } else { sum = 0.0; for(i = 0; i < n; i++) { sum += foo(i); } return sum; } } Suppose we modify the above function foo()foo() and stores the value of foo(i) 0≤i<nfoo(i) \ 0 \leq i < n, as and when they are computed. With this modification the time complexity for function foo()foo() is significantly …
Official PYQ2005Programming and Data StructuresTreesMCQ · 1 mark
In a complete kk-ary tree, every internal node has exactly kk children. The number of leaves in such a tree with nn internal node is:
Official PYQ2005Programming and Data StructuresBinary Search TreesMCQ · 1 mark
How many distinct binary search trees can be created out of 44 distinct keys?
Official PYQ2005Programming and Data StructuresBinary HeapsMCQ · 1 mark
A priority queue is implemented as a Max-Heap. Initially, it has 55 elements. The level-order traversal of the heap is: 10,8,5,3,210, 8, 5, 3, 2. Two new elements 11 and 77 are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
Official PYQ2005Programming and Data StructuresBinary Search TreesMCQ · 1 mark
Postorder traversal of a given binary search tree, TT produces the following sequence of keys 10,9,23,22,27,25,15,50,95,60,40,2910, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an in-order traversal of the tree TT?
Official PYQ2005Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following C program: double foo (double); /* Line 1 */ int main() { double da, db; //input da db = foo(da); } double foo (double a) { return a; } The above code compiled without any error or warning. If Line 11 is deleted, the above code will show:
Official PYQ2005Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
A program PP reads in 500500 integers in the range [0,100][0, 100] representing the scores of 500500 students. It then prints the frequency of each score above 5050. What would be the best way for PP to store the frequencies?
Official PYQ2005Programming and Data StructuresProgramming in CMCQ · 1 mark
A common property of logic programming languages and functional languages is:
Official PYQ2005Programming and Data StructuresTreesMCQ · 1 mark
An Abstract Data Type (ADT) is:
Official PYQ2005Programming and Data StructuresProgramming in CMCQ · 1 mark
What does the following C-statement declare? int (*f) (int * );
Official PYQ2004Programming and Data StructuresProgramming in CMCQ · 1 mark
Choose the best matching between the programming styles in Group 1 and their characteristics in Group 2. …
Official PYQ2004Programming and Data StructuresBinary Search TreesMCQ · 1 mark
A program takes as input a balanced binary search tree with nn leaf nodes and computes the value of a function g(x)g(x) for each node xx. If the cost of computing g(x)g(x) is: min⁡(number of leaf-nodesin left-subtree of x  ,  number of leaf-nodesin right-subtree of x)\Large \min \left ( \substack{\text{number of leaf-nodes}\\\text{in left-subtree of $x$}}\;,\; \substack{\text{number of leaf-nodes}\\\text{in right-subtree of $x$}}\right ) …
Official PYQ2004Programming and Data StructuresTreesMCQ · 1 mark
Consider the following C program segment struct CellNode{ struct CellNode *leftChild int element; struct CellNode *rightChild; }; int Dosomething (struct CellNode *ptr) { int value = 0; if(ptr != NULL) { if (ptr -> leftChild != NULL) value = 1 + DoSomething (ptr -> leftChild); if (ptr -> rightChild != NULL) value = max(value, 1 + Dosomething (ptr …
Official PYQ2004Programming and Data StructuresLinked ListsMCQ · 1 mark
Suppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among union, intersection, membership, cardinality\text{union, intersection, membership, cardinality} will be the slowest?
Official PYQ2004Programming and Data StructuresBinary HeapsMCQ · 1 mark
The elements 32,15,20,30,12,25,16,32, 15, 20, 30, 12, 25, 16, are inserted one by one in the given order into a maxHeap. The resultant maxHeap is