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 PYQ2010Programming and Data StructuresTreesMCQ · 1 mark
In a binary tree with nn nodes, every node has an odd number of descendants. Every node is considered to be its own descendant. What is the number of nodes in the tree that have exactly one child?
Official PYQ2009Programming and Data StructuresBinary HeapsMCQ · 1 mark
Consider a binary max-heap implemented using an array. Which one of the following array represents a binary max-heap?
Official PYQ2009Programming and Data StructuresBinary HeapsMCQ · 1 mark
Consider a binary max-heap implemented using an array. What is the content of the array after two delete operations on {25,14,16,13,10,8,12}\left\{25,14,16,13,10,8,12\right\}
Official PYQ2009Programming and Data StructuresBinary Search TreesMCQ · 1 mark
What is the maximum height of any AVL-tree with 77 nodes? Assume that the height of a tree with a single node is 00.
Official PYQ2009Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
The keys 12,18,13,2,3,23,512, 18, 13, 2, 3, 23, 5 and 1515 are inserted into an initially empty hash table of length 1010 using open addressing with hash function h(k)=kmod  10h(k) = k \mod 10 and linear probing. What is the resultant hash table?
Official PYQ2008Programming and Data StructuresLinked ListsMCQ · 1 mark
The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1,2,3,4,5,6,71, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after function completes execution? struct node { int value; struct node *next; }; void …
Official PYQ2008Programming and Data StructuresProgramming in CMCQ · 1 mark
Choose the correct option to fill ?1?1 and ?2?2 so that the program below prints an input string in reverse order. Assume that the input string is terminated by a new line character. void reverse(void) { int c; if(?1) reverse(); ?2 } main() { printf("Enter text"); printf("\n"); reverse(); printf("\n"); }
Official PYQ2008Programming and Data StructuresProgramming in CMCQ · 1 mark
What is printed by the following C program? int f(int x, int *py, int **ppz) { int y, z; **ppz += 1; z = **ppz; // corrected z = *ppz; to z = **ppz; *py += 2; y = *py; x += 3; return x+y+z; } void main() { int c, *b, **a; c = 4; b = &c; a = &b; printf("%d", f(c, b, a)); }
Official PYQ2008Programming and Data StructuresBinary Search TreesMCQ · 1 mark
You are given the postorder traversal, PP, of a binary search tree on the nn elements 1,2,…,n1, 2, \dots, n. You have to determine the unique binary search tree that has PP as its postorder traversal. What is the time complexity of the most efficient algorithm for doing this?
Official PYQ2008Programming and Data StructuresProgramming in CMCQ · 1 mark
Which combination of the integer variables x,y,x, y, and zz makes the variable aa get the value 44 in the following expression? a=(x>y)?((x>z)?x:z):((y>z)?y:z)a=(x > y)?((x > z) ?x:z): ((y > z) ?y:z)
Official PYQ2007Programming and Data StructuresBinary HeapsMCQ · 1 mark
Consider the process of inserting an element into a Max Heap\text{Max Heap}, where the Max Heap\text{Max Heap} is represented by an array. Suppose we perform a binary search on the path from the new leaf to the root to find the position for the newly inserted element, the number of comparisons performed is:
Official PYQ2007Programming and Data StructuresTreesMCQ · 1 mark
Consider the following C program segment where CellNode\text{CellNode} represents a node in a binary tree: struct CellNode { struct CellNode *leftChild; int element; struct CellNode *rightChild; }; int Getvalue (struct CellNode *ptr) { int value = 0; if (ptr != NULL) { if ((ptr->leftChild == NULL) && (ptr->rightChild == NULL)) value = 1; else value …
Official PYQ2007Programming and Data StructuresTreesMCQ · 1 mark
A complete n−aryn-ary tree is a tree in which each node has nn children or no children. Let II be the number of internal nodes and LL be the number of leaves in a complete n−aryn-ary tree. If L=41L = 41 and I=10I = 10, what is the value of nn?
Official PYQ2007Programming and Data StructuresRecursionMCQ · 1 mark
Consider the following C function: int f(int n) { static int r = 0; if (n <= 0) return 1; if (n > 3) { r = n; return f(n-2) + 2; } return f(n-1) + r; } What is the value of f(5)f(5)?
Official PYQ2007Programming and Data StructuresArrays, Stacks and QueuesMCQ · 1 mark
Consider a hash table of size seven, with starting index zero, and a hash function (3x+4)mod  7(3x + 4)\mod 7. Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence 1,3,8,101, 3, 8, 10 is inserted into the table using closed hashing? Note that − denotes an empty location in the table.
Official PYQ2007Programming and Data StructuresTreesMCQ · 1 mark
The inorder and preorder traversal of a binary tree are d b e a f c g\text{d b e a f c g} and a b d e c f g\text{a b d e c f g}, respectively The postorder traversal of the binary tree is:
Official PYQ2007Programming and Data StructuresTreesMCQ · 1 mark
The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height hh is:
Official PYQ2007Programming and Data StructuresTreesMCQ · 1 mark
The maximum number of binary trees that can be formed with three unlabeled nodes is:
Official PYQ2006Programming and Data StructuresBinary HeapsMCQ · 1 mark
Statement for Linked Answer Questions 76 & 77: A 33-ary max heap is like a binary max heap, but instead of 22 children, nodes have 33 children. A 33-ary heap can be represented by an array as follows: The root is stored in the first location, a[0]a[0], nodes in the next level, from left to right, is stored from a[1]a[1] to a[3]a[3]. The nodes …
Official PYQ2006Programming and Data StructuresBinary HeapsMCQ · 1 mark
Statement for Linked Answer Questions 76 & 77: A 33-ary max heap is like a binary max heap, but instead of 22 children, nodes have 33 children. A 33-ary heap can be represented by an array as follows: The root is stored in the first location, a[0]a[0], nodes in the next level, from left to right, is stored from a[1]a[1] to a[3]a[3]. The nodes …