Trees questions

Q33

GATE CS 2026 CS-1Tree Data StructuresNAT1 mark
The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with 23 nodes is _________. (answer in integer)
Show answer without attempting

Answer: 11

Q12

GATE CS 2026 CS-2Tree Data StructuresMCQ1 mark−1/3 if wrong
The set T represents various traversals over binary tree. The set S represents the order of visiting nodes during a traversal.

| T | S |
|---|---|
| I: Inorder | L: left subtree, node, right subtree |
| II: Preorder | M: node, left subtree, right subtree |
| III: Postorder | N: left subtree, right subtree, node |

Which one of the following is the correct match from T to S ?
Show answer without attempting

Answer: A

Q13

GATE CS 2025 CS-2Tree Data StructuresMCQ1 mark−1/3 if wrong
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?
Show answer without attempting

Answer: B

Q47

GATE CS 2023 CSTree Data StructuresMCQ2 marks−2/3 if wrong
Consider the C function 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 is called with a pointer to the root node of the given binary tree, what will it print?
Question figure
Show answer without attempting

Answer: C

Q16

GATE CS 2021 CS-2Tree Data StructuresNAT1 mark
Consider a complete binary tree with 7 nodes. Let AA denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let BB denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root.
The value of ∣A−B∣|A - B| is ____________.
Show answer without attempting

Answer: 1

Q20

GATE CS 2018 CSTree Data StructuresNAT1 mark
The postorder traversal of a binary tree is 8,9,6,7,4,5,2,3,18,9,6,7,4,5,2,3,1. The inorder traversal of the same tree is 8,6,9,4,7,2,5,1,38,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 ______.
Show answer without attempting

Answer: 4

Q11

GATE CS 2016 CS-2Tree Data StructuresNAT1 mark
Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex tt at a distance four from the root. If tt is the nn-th vertex in this BFS traversal, then the maximum possible value of nn is _________.
Show answer without attempting

Answer: 31.0

Q36

GATE CS 2016 CS-2Tree Data StructuresMCQ2 marks−2/3 if wrong
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:
Show answer without attempting

Answer: C

Q21

GATE CS 2015 CS-3Tree Data StructuresNAT1 mark
Consider a binary tree T that has 200 leaf nodes. Then, the number of nodes in T that have exactly two children are ____________.
Show answer without attempting

Answer: 199

Q15

GATE CS 2015 CS-1Tree Data StructuresMCQ1 mark−1/3 if wrong
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 5 are
Show answer without attempting

Answer: A

Q23

GATE CS 2015 CS-2Tree Data StructuresNAT1 mark
A binary tree T has 20 leaves. The number of nodes in T having two children is _______.
Show answer without attempting

Answer: 19

Q39

GATE CS 2014 CS-2Tree Data StructuresNAT2 marks
Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of the expression represented by the tree is ___.
Question figure
Show answer without attempting

Answer: 6

Q12

GATE CS 2014 CS-3Tree Data StructuresMCQ1 mark−1/3 if wrong
Consider the following rooted tree with the vertex labeled P as the root:

The order in which the nodes are visited during an in-order traversal of the tree is
Question figure
Show answer without attempting

Answer: A

Q41

GATE CS 2014 CS-3Tree Data StructuresMCQ2 marks−2/3 if wrong
Consider the pseudocode given below. The function DoSomething() takes as argument a pointer to the root of an arbitrary tree represented by the leftMostChild-rightSibling representation. Each node of the tree is of type treeNode.
typedef struct treeNode* treeptr;
struct treeNode
{
  treeptr leftMostChild, rightSibling;
};
int DoSomething (treeptr tree)
{
  int value=0;
  if (tree != NULL) {
    if (tree->leftMostChild == NULL)
      value = 1;
    else
      value = DoSomething(tree->leftMostChild);
    value = value + DoSomething(tree->rightSibling);
  }
  return(value);
}
When the pointer to the root of a tree is passed as the argument to DoSomething, the value returned by the function corresponds to the
Show answer without attempting

Answer: D

Q12

GATE CS 2014 CS-1Tree Data StructuresNAT1 mark
Consider a rooted nn node binary tree represented using pointers. The best upper bound on the time required to determine the number of subtrees having exactly 4 nodes is O(nalog⁡bn)O(n^a \log^b n). Then the value of a+10ba + 10b is ___________.
Show answer without attempting

Answer: 1

Q47

GATE CS 2012 CSTree Data StructuresMCQ2 marks−2/3 if wrong
The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudocode 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] ;                // Box 1

  else { h1 = height (n -> left);
         if (n -> right == NULL) return (1+h1);
         else { h2 = height (n -> right);

                return [B2] ;           // Box 2
              }
       }
}
The appropriate expressions for the two boxes B1 and B2 are
Show answer without attempting

Answer: A

0/160 correct0 marks

Related topics in Tree Data Structures