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 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 …
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 …
An implementation of a queue , using two stacks and , 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 insert and delete operations be …
A scheme for storing binary trees in an array is as follows. Indexing of starts at instead of . the root is stored at . For a node stored at , the left child, if any, is stored in and the right child, if any, in . To be able to store any binary tree on n vertices the minimum size of should be
In a binary max heap containing numbers, the smallest element can be found in time
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 and stores the value of , as and when they are computed. With this modification the time complexity for function is significantly …
In a complete -ary tree, every internal node has exactly children. The number of leaves in such a tree with internal node is:
How many distinct binary search trees can be created out of distinct keys?
A priority queue is implemented as a Max-Heap. Initially, it has elements. The level-order traversal of the heap is: . Two new elements and are inserted into the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
Postorder traversal of a given binary search tree, produces the following sequence of keys Which one of the following sequences of keys can be the result of an in-order traversal of the tree ?
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 is deleted, the above code will show:
A program reads in integers in the range representing the scores of students. It then prints the frequency of each score above . What would be the best way for to store the frequencies?
A common property of logic programming languages and functional languages is:
An Abstract Data Type (ADT) is:
What does the following C-statement declare? int (*f) (int * );
Choose the best matching between the programming styles in Group 1 and their characteristics in Group 2. …
A program takes as input a balanced binary search tree with leaf nodes and computes the value of a function for each node . If the cost of computing is: …
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 …
Suppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among will be the slowest?
The elements are inserted one by one in the given order into a maxHeap. The resultant maxHeap is
