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 PYQ2015Programming and Data StructuresProgramming in CNAT · 1 mark
Consider the following C program #include<stdio.h> int main() { static int a[] = {10, 20, 30, 40, 50}; static int *p[] = {a, a+3, a+4, a+1, a+2}; int **ptr = p; ptr++; printf("%d%d", ptr-p, **ptr); } The output of the program is _______.
Official PYQ2015Programming and Data StructuresTreesNAT · 1 mark
Consider a binary tree T that has 200200 leaf nodes. Then the number of nodes in T that have exactly two children are ______.
Official PYQ2015Programming and Data StructuresBinary HeapsMCQ · 1 mark
Consider the following array of elements. ⟨89,19,50,17,12,15,2,5,7,11,6,9,100⟩\langle 89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100 \rangle The minimum number of interchanges needed to convert it into a max-heap is
Official PYQ2015Programming and Data StructuresArrays, Stacks and QueuesNAT · 1 mark
Given that hash table TT with 2525 slots that stores 20002000 elements, the load factor aa for TT is _________.
Official PYQ2015Programming and Data StructuresBinary Search TreesMCQ · 1 mark
While inserting the elements 71,65,84,69,67,8371, 65, 84, 69, 67, 83 in an empty binary search tree (BST) in the sequence shown, the element in the lowest level is
Official PYQ2015Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
The result evaluating the postfix expression 10 5+60 6/∗8−10 \ 5 + 60 \ 6 / * 8 - is
Official PYQ2015Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Consider the following C program segment. # include <stdio.h> int main() { char s1[7] = "1234", *p; p = s1 + 2; *p = '0'; printf("%s", s1); } What will be printed by the program?
Official PYQ2014Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Consider a hash table with 99 slots. The hash function is h(k)=kmod  9h(k)= k \mod 9. The collisions are resolved by chaining. The following 99 keys are inserted in the order: 5,28,19,15,20,33,12,17,105, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are
Official PYQ2014Programming and Data StructuresTreesNAT · 1 mark
Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of subtrees having exactly 44 nodes is O(nalog⁡bn)O(n^a\log^bn). Then the value of a+10ba+10b is __________.
Official PYQ2014Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the following program in C language: #include <stdio.h> main() { int i; int*pi = &i; scanf("%d",pi); printf("%d\n", i+5); } Which one of the following statements is TRUE?
Official PYQ2014Programming and Data StructuresGraphsMCQ · 1 mark
Let G=(V,E)G=(V,E) be a directed graph where VV is the set of vertices and EE the set of edges. Then which one of the following graphs has the same strongly connected components as GG ?
Official PYQ2014Programming and Data StructuresProgramming in CMCQ · 1 mark
Consider the C function given below. int f(int j) { static int i = 50; int k; if (i == j) { printf("something"); k = f(i); return 0; } else return 0; } Which one of the following is TRUE?
Official PYQ2014Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Suppose a stack implementation supports an instruction REVERSE\text{REVERSE}, which reverses the order of elements on the stack, in addition to the PUSH\text{PUSH} and POP\text{POP} instructions. Which one of the following statements is TRUE\text{TRUE} (with respect to this modified stack)?
Official PYQ2014Programming and Data StructuresRecursionNAT · 1 mark
Consider the following function. double f(double x){ if( abs(x*x - 3) < 0.01) return x; else return f(x/2 + 1.5/x); } Give a value qq (to 22 decimals) such that f(q)f(q) will return qq:_____.
Official PYQ2014Programming 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 PYQ2014Programming and Data StructuresProgramming in CMCQ · 1 mark
Suppose nn and pp are unsigned int variables in a C program. We wish to set pp to nC3^nC_3. If nn is large, which one of the following statements is most likely to set pp correctly?
Official PYQ2014Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Consider the C function given below. Assume that the array listAlistA contains n(>0)n (>0) elements, sorted in ascending order. int ProcessArray(int *listA, int x, int n) { int i, j, k; i = 0; j = n-1; do { k = (i+j)/2; if (x <= listA[k]) j = k-1; if (listA[k] <= x) i = k+1; } while (i <= j); if (listA[k] == x) return(k); else return -1; } Which …
Official PYQ2014Programming and Data StructuresTreesMCQ · 1 mark
Consider the pseudocode given below. The function DoSomething()DoSomething() takes as argument a pointer to the root of an arbitrary tree represented by the leftMostChild−rightSiblingleftMostChild-rightSibling representation. Each node of the tree is of type treeNodetreeNode. typedef struct treeNode* treeptr; struct treeNode { treeptr leftMostChild, rightSibling; }; int DoSomething (treeptr …
Official PYQ2014Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Consider a hash table with 100100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 33 slots are unfilled after the first 33 insertions?
Official PYQ2014Programming and Data StructuresBinary Search TreesNAT · 1 mark
Suppose we have a balanced binary search tree TT holding nn numbers. We are given two numbers LL and HH and wish to sum up all the numbers in TT that lie between LL and HH. Suppose there are mm such numbers in TT. If the tightest upper bound on the time to compute the sum is O(nalog⁡bn+mclog⁡dn)O(n^a\log^bn+m^c\log^dn), the value of …