• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Tree Traversal with Interview Question and Answers | DSA Quiz

Question 11

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 true? (GATE CS 2000)
  • LASTIN = LASTPOST
  • LASTIN = LASTPRE
  • LASTPRE = LASTPOST
  • None of the above

Question 12

The array representation of a complete binary tree contains the data in sorted order. Which traversal of the tree will produce the data in sorted form?
  • Preorder
  • Inorder
  • Postorder
  • Level order

Question 13

Consider the following rooted tree with the vertex P labeled as root GATECS2014Q19 The order in which the nodes are visited during in-order traversal is
  • SQPTRWUV
  • SQPTURWV
  • SQPTWUVR
  • SQPTRUWV

Question 14

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. C
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
  • number of internal nodes in the tree.
  • height of the tree.
  • number of nodes without a right sibling in the tree.
  • number of leaf nodes in the tree.

Question 15

Level order traversal of a rooted tree can be done by starting from the root and performing

  • preorder traversal

  • inorder traversal

  • depth first search

  • breadth first search

Question 16

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
  • (i) only
  • (ii), (iii)
  • (iii) only
  • (iv) only

Question 17

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 true?
  • LASTIN = LASTPOST
  • LASTIN = LASTPRE
  • LASTPRE = LASTPOST
  • None of the above

Question 18

Which one of the following binary trees has its inorder and preorder traversals as BCAD  and ABCD, respectively?
tree
  • A
  • B
  • C
  • D

Question 19

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
  • p
  • p + 1
  • n - p
  • n - p + 1

Question 20

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  
  • 8, 7, 6, 5, 4, 3, 2, 1
  • 1, 2, 3, 4, 8, 7, 6, 5
  • 2, 1, 4, 3, 6, 7, 8, 5
  • 2, 1, 4, 3, 7, 8, 6, 5

There are 42 questions to complete.

Last Updated :
Take a part in the ongoing discussion