Skip to content

GATE CS Trees questions

Practise Trees questions for GATE CS. Explore official PYQs and original topic-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 PYQ2026Programming and Data StructuresTreesMCQ · 1 mark
The set T\mathbf{T} represents various traversals over binary tree. The set S\mathbf{S} represents the order of visiting nodes during a traversal. …
Official PYQ2025Programming and Data StructuresTreesMCQ · 1 mark
​​​​Consider a binary tree TT in which every node has either zero or two children. Let n>0n>0 be the number of nodes in TT. Which ONE of the following is the number of nodes in TT that have exactly two children?
Official PYQ2023Programming and Data StructuresTreesMCQ · 2 marks
Consider the C\text{C} function foo\text{foo} 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 foo\textsf{foo} is called with a pointer to the …
Official PYQ2021Programming and Data StructuresTreesMCQ · 2 marks
An articulationarticulation pointpoint in a connected graph is a vertex such that removing the vertex and its incident edges disconnects the graph into two or more connected components. Let TT be a DFS\text{DFS} tree obtained by doing DFS\text{DFS} in a connected undirected graph GG. Which of the following options is/are correct?
Official PYQ2021Programming and Data StructuresTreesNAT · 1 mark
Consider a complete binary tree with 77 nodes. Let AA denote the set of first 33 elements obtained by performing Breadth-First Search (BFS)\text{(BFS)} starting from the root. Let BB denote the set of first 33 elements obtained by performing Depth-First Search (DFS)\text{(DFS)} starting from the root. The value of ∣A−B∣\mid A-B \mid is …
Official PYQ2020Programming and Data StructuresTreesMCQ · 1 mark
What is the worst case time complexity of inserting n2n^{2} elements into an AVL-tree with nn elements initially?
Official PYQ2019Programming and Data StructuresTreesNAT · 2 marks
Let TT be a full binary tree with 88 leaves. (A full binary tree has every level full.) Suppose two leaves aa and bb of TT are chosen uniformly and independently at random. The expected value of the distance between aa and bb in TT (ie., the number of edges in the unique path between aa and bb) is (rounded off to 22 decimal …
Official PYQ2018Programming and Data StructuresTreesNAT · 1 mark
The postorder traversal of a binary tree is 8, 9, 6, 7, 4, 5, 2, 3, 1\text{8, 9, 6, 7, 4, 5, 2, 3, 1}. The inorder traversal of the same tree is 8,6,9,4,7,2,5,1,3{8, 6, 9, 4, 7, 2, 5, 1, 3}. The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is _____
Official PYQ2017Programming and Data StructuresTreesNAT · 1 mark
Let TT be a tree with 1010 vertices. The sum of the degrees of all the vertices in TT is ________
Official PYQ2016Programming and Data StructuresTreesMCQ · 1 mark
Consider the following New-order strategy for traversing a binary tree: Visit the root; Visit the right subtree using New-order; Visit the left subtree using New-order; The New-order traversal of the expression tree corresponding to the reverse polish expression 3 4 * 5 - 2 ^ 6 7 * 1 + - is given by:
Official PYQ2015Programming and Data StructuresTreesMCQ · 1 mark
The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a binary tree of height 55 are
Official PYQ2015Programming and Data StructuresTreesNAT · 1 mark
A binary tree T has 2020 leaves. The number of nodes in T having two children 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 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 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 StructuresTreesMCQ · 1 mark
Consider the following rooted tree with the vertex labeled PP as the root: The order in which the nodes are visited during an in-order traversal of the tree is
Official PYQ2012Programming and Data StructuresTreesMCQ · 1 mark
The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudo-code below is invoked as height (root) to compute the height of a binary tree rooted at the tree pointer root. int height(treeptr n) { if(n == NULL) return -1; if(n -> left == NULL) if(n -> right == NULL) return 0; else return B1; // …
Official PYQ2011Programming and Data StructuresTreesMCQ · 1 mark
We are given a set of nn distinct elements and an unlabeled binary tree with nn nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
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 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 …