Trees · Data Structures · GATE CSE

Start Practice

Marks 1

1

Which one of the following sequences when stored in an array at locations $$A[1],....,A[10]$$ forms a max-heap?

GATE CSE 2023
2

Suppose a binary search tree with 1000 distinct elements is also a complete binary tree. The tree is stored using the array representation of binary heap trees. Assuming that the array indices start with 0, the 3rd largest element of the tree is stored at index ___________.

GATE CSE 2022
3

Consider a complete binary tree with 7 nodes. Let A denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let B denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root.

The value of |A - B| is _______

GATE CSE 2021 Set 2
4

Consider the following statements.

S1 : The sequence of procedure calls corresponds to a preorder traversal of the activation tree.

S2 : The sequence of procedure returns corresponds to a postorder traversal of the activation tree.

Which one of the following options is correct?

GATE CSE 2021 Set 1
5
What is the worst case time complexity of inserting n2 elements into an AVL-tree with n elements initially?
GATE CSE 2020
6
The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the postorder traversal of the tree?
GATE CSE 2020
7
The postorder traversal of a binary tree is $$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.$$ 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 ______.
GATE CSE 2018
8
What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
GATE CSE 2015 Set 1
9
Which of the following is/are correct inorder traversal sequence(s) of binary search tree(s)?

I. 3, 5, 7, 8, 15, 19, 25
II. 5, 8, 9, 12, 10, 15, 25
III. 2, 7, 10, 8, 14, 16, 20
IV. 4, 6, 7, 9 18, 20, 25

GATE CSE 2015 Set 1
10
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
GATE CSE 2015 Set 1
11
While inserting the elements $$71, 65, 84, 69, 67, 83$$ in an empty binary search tree $$(BST)$$ in the sequence shown, the element in the lowest level is
GATE CSE 2015 Set 3
12
Consider a binary tree $$T$$ that has $$200$$ leaf nodes. Then, the number of nodes in $$T$$ that have exactly two children are ________.
GATE CSE 2015 Set 3
13
A binary tree $$T$$ has $$20$$ leaves. The number of nodes in $$T$$ having two children is _______________.
GATE CSE 2015 Set 2
14
Consider a complete binary tree where the left and the right sub-trees of the root are max-heaps. The lower bound for the number of operations to convert the tree to a heap is
GATE CSE 2015 Set 2
15
Consider the following rooted tree with the vertex labelled P as the root GATE CSE 2014 Set 3 Data Structures - Trees Question 63 English The order in which the nodes are visited during an in-order traversal of the tree is
GATE CSE 2014 Set 3
16
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 4 nodes O(na Logbn ). Then the value of a + 10b is _________
GATE CSE 2014 Set 1
17
A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?
GATE CSE 2011
18
Which of the following is TRUE?
GATE CSE 2008
19
The maximum number of binary trees that can be formed with three unlabeled nodes is:
GATE CSE 2007
20
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 h is:
GATE CSE 2007
21
A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. the root is stored at X[1]. For a node stored at X[i], the left child, if any, is stored in X[2i] and the right child, if any, in X[2i+1]. To be able to store any binary tree on n vertices the minimum size of X should be
GATE CSE 2006
22
In a binary tree, the number of internal nodes of degree 1 is 5, and the number of internal nodes of degree 2 is 10. The number of leaf nodes in the binary tree is
GATE CSE 2006
23
The numbers 1, 2, ........, n are inserted in a binary search tree in some order. In the resulting tree, the right subtree of the root contains p nodes. The first number to be inserted in the tree must be
GATE CSE 2005
24
Level order traversal of a rooted tree can be done by starting from the root and performing
GATE CSE 2004
25
The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?
GATE CSE 2004
26
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?
GATE CSE 2003
27
Consider the following nested representation of binary trees: (X Y Z) indicates Y and Z are the left and right sub stress, respectively, of node X. Note that Y and Z may be NULL, or further nested. Which of the following represents a valid binary tree?
GATE CSE 2000
28
Which of the following statements is false?
GATE CSE 1998
29
In the balanced binary tree in Fig. given below, how many nodes will become unbalanced when a node is inserted as a child of the node “g”? GATE CSE 1996 Data Structures - Trees Question 76 English
GATE CSE 1996
30
Which of the following sequences denotes the post order traversal sequence of the tree of previous question?
GATE CSE 1996
31
A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is:
GATE CSE 1995
32
It is possible to construct a binary tree uniquely whose pre-order and post-order traversals are given.
GATE CSE 1987
33
If the no of leaves in a tree is not a power of 2,then the tree is not a binary tree.
GATE CSE 1987

Marks 2

1

You are given a set $V$ of distinct integers. A binary search tree $T$ is created by inserting all elements of $V$ one by one, starting with an empty tree. The tree $T$ follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in which these values were inserted into $T$, and you do not have access to $T$.

Which one of the following statements is TRUE?

GATE CSE 2024 Set 2
2

Consider a binary min-heap containing 105 distinct elements. Let k be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of k is

GATE CSE 2024 Set 1
3

Let A be a priority queue for maintaining a set of elements. Suppose A is implemented using a max-heap data structure. The operation EXTRACT-MAX(A) extracts and deletes the maximum element from A. The operation INSERT(A, key) inserts a new element key in A. The properties of a max-heap are preserved at the end of each of these operations.

When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?

GATE CSE 2023
4

Consider the C function foo and the binary tree shown.

GATE CSE 2023 Data Structures - Trees Question 3 English
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?

GATE CSE 2023
5
In a balanced binary search tree with n elements, what is the worst case time complexity of reporting all elements in range [a, b]? Assume that the number of reported elements is k.
GATE CSE 2020
6
Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap is _______.
GATE CSE 2020
7
Let T be a full binary tree with 8 leaves. (A full binary tree has every level full). Suppose two leaves a and b of T are chosen uniformly and independently at random. The expected value of the distance between a and b in T (i.e., the number of edges in the unique path between a and b) is (rounded off to 2 decimal places) _____.
GATE CSE 2019
8
Consider the following $$New-order$$ strategy for traversing a binary tree:

$$\,\,\,\,\,\,\, \bullet \,\,\,\,\,$$ Visit the root;
$$\,\,\,\,\,\,\, \bullet \,\,\,\,\,$$ Visit the right subtree using $$New-order;$$
$$\,\,\,\,\,\,\, \bullet \,\,\,\,\,$$ 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:

GATE CSE 2016 Set 2
9
The number of ways in which the numbers $$1, 2, 3, 4, 5, 6, 7$$ can be inserted in an empty binary search tree, such that the resulting tree has height $$6,$$ is _____________.

$$Note:\,\,\,The\,\,height\,\,of\,\,a\,tree\,\,with\,\,a\,\,\sin gle\,\,node\,\,is\,\,0$$

GATE CSE 2016 Set 2
10
Suppose we have a balanced binary search tree T holding n numbers. We are given two numbers L and H and wish to sum up all the numbers in T that lie between L and H. Suppose there are m such numbers in T. If the tightest upper bound on the time to compute the sum is O( na logb n + mc logd n ), the value of a + 10b + 100c + 1000d is _______.
GATE CSE 2014 Set 3
11
Consider the C function given below. Assume that the array listA contains n (> 0) elements, sored 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 one of the following statements about the function ProcessArray is CORRECT?
GATE CSE 2014 Set 3
12
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, rightSibiling; 
}; 
Int Dosomething (treeptr tree) 
{ 
    int value =0; 
    if (tree ! = NULL) { 
      If (tree -> leftMostchild = = NULL) 
          value=1; 
    else 
        value = Dosomething (tree->leftMostchild); 
        value = value + Dosometing (tree->rightsibiling); 
    } 
    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
GATE CSE 2014 Set 3
13
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 ___. GATE CSE 2014 Set 2 Data Structures - Trees Question 31 English
GATE CSE 2014 Set 2
14
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 expression for the two boxes B1 and B2 are
GATE CSE 2012
15
We are given a set of n distinct elements and an unlabeled binary tree with n nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
GATE CSE 2011
16
What is the maximum height of any AVL-tree with 7 nodes? Assume that the height of a tree with a single node is 0.
GATE CSE 2009
17
The following three are known to be the preorder, inorder and postorder sequences of a binary tree. But it is not known which is which. MBCAFHPYK KAMCBYPFH MABCKYFPH Pick the true statement from the following.
GATE CSE 2008
18
A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.
I. 81, 537, 102, 439, 285, 376, 305
II. 52, 97, 121, 195, 242, 381, 472
III. 142, 248, 520, 386, 345, 270, 307
IV. 550, 149, 507, 395, 463, 402, 270
Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could have encountered them in the search?
GATE CSE 2008
19
A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.
I. 81, 537, 102, 439, 285, 376, 305
II. 52, 97, 121, 195, 242, 381, 472
III. 142, 248, 520, 386, 345, 270, 307
IV. 550, 149, 507, 395, 463, 402, 270
Which of the following statements is TRUE?
GATE CSE 2008
20
How many distinct BSTs can be constructed with 3 distinct keys?
GATE CSE 2008
21
You are given the postorder traversal, P, of a binary search tree on the n elements 1, 2,..........., n. You have to determine the unique binary search tree that has P as its postorder traversal. What is the time complexity of the most efficient algorithm for doing this?
GATE CSE 2008
22
A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I = 10, what is the value of n?
GATE CSE 2007
23
Consider the following C program segment where 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 = value + GetValue(ptr->leftChild) 
             + GetValue(ptr->rightChild); 
     } 
     return(value); 
} 
The value returned by GetValue() when a pointer to the root of a binary tree is passed as its argument is:
GATE CSE 2007
24
When searching for the key value 60 in a binary search tree, nodes containing the key values 10, 20, 40, 50, 70 80, 90 are traversed, not necessarily in the order given. How many different orders are possible in which these key values can occur on the search path from the root to the node containing the value 60?
GATE CSE 2007
25
The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively. The postorder traversal of the binary tree is:
GATE CSE 2007
26
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. If the root node is at level 0, the level of element X[i], i ≠ 0, is
GATE CSE 2006
27
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. If only the root node does not satisfy the heap property, the algorithm to convert the complete binary tree into a heap has the best asymptotic time complexity of
GATE CSE 2006
28
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. The index of the parent of element X[i],i≠0 is?
GATE CSE 2006
29
Which of the following sequences of array elements forms a heap?
GATE CSE 2006
30
Suppose that we have numbers between 1 and 100 in a binary search tree and want to search for the number 55. Which of the following sequences CANNOT be the sequence of nodes examined?
GATE CSE 2006
31
Postorder traversal of a given binary search tree T produces the following sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an inorder traversal of the tree T?
GATE CSE 2005
32
How many distinct binary search trees can be created out of 4 distinct keys?
GATE CSE 2005
33
In a binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most 2. If the height of the tree is h > 0, then the minimum number of nodes in the tree is:
GATE CSE 2005
34
In a complete k-ary tree, every internal node has exactly k children. The number of leaves in such a tree with n internal nodes is
GATE CSE 2005
35
A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed in pre-order and the values in each node printed out, the sequence of values obtained is 5, 3, 1, 2, 4, 6, 8, 7. If the tree is traversed in post-order, the sequence obtained would be
GATE CSE 2005
36
A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the heap is given below: 10, 8, 5, 3, 2 Two new elements ”1‘ and ”7‘ are inserted in the heap in that order. The level-order traversal of the heap after the insertion of the elements is:
GATE CSE 2005
37
Consider the label sequences obtained by the following pairs of traversals on a labeled binary tree. Which of these pairs identify a tree uniquely?
i) preorder and postorder
ii) inorder and postorder
iii) preorder and inorder
iv) level order and postorder
GATE CSE 2004
38
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 - > rightChild)); 
          } 
      return (value); 
} 
The value returned by the function DoSomething when a pointer to the root of a non-empty tree is passed as argument is
GATE CSE 2004
39
A program takes as input a balanced binary search tree with n leaf nodes and computes the value of a function g(x) for each node x. If the cost of computing g(x) is min{ no. of leaf-nodes in left-subtree of x, no. of leaf-nodes in right-subtree of x } then the worst-case time complexity of the program is
GATE CSE 2004
40
The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:
GATE CSE 2002
41
Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited in a postorder, inorder and preorder traversal. Respectively, of a complete binary tree. Which of the following is always tree?
GATE CSE 2000
42
A complete n-ary tree is one in which every node has O or n sons. If x is the number of internal nodes of a complete n-ary tree, the number of leaves in it is given by
GATE CSE 1998
43
A binary search tree contains the value 1, 2, 3, 4, 5, 6, 7, 8. The tree is traversed in pre-order and the values are printed out. Which of the following sequences is a valid output?
GATE CSE 1997
44
A binary search tree is generated by inserting in order the following integers: 50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24 The number of nodes in the left subtree and right subtree of the root respectively is
GATE CSE 1996
45
A binary search tree is used to locate the number 43. Which of the following probe sequences are not possible?
GATE CSE 1996
46
If the binary tree in figure is traversed in inorder, then the order in which the nodes will be visited is ______ GATE CSE 1991 Data Structures - Trees Question 62 English
GATE CSE 1991
EXAM MAP
Medical
NEETAIIMS
Graduate Aptitude Test in Engineering
GATE CSEGATE ECEGATE EEGATE MEGATE CEGATE PIGATE IN
Civil Services
UPSC Civil Service
Defence
NDA
Staff Selection Commission
SSC CGL Tier I
CBSE
Class 12