Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Tests  >  Test: Trees - 1 - Computer Science Engineering (CSE) MCQ

Test: Trees - 1 - Computer Science Engineering (CSE) MCQ


Test Description

15 Questions MCQ Test - Test: Trees - 1

Test: Trees - 1 for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Test: Trees - 1 questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Trees - 1 MCQs are made for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Trees - 1 below.
Solutions of Test: Trees - 1 questions in English are available as part of our course for Computer Science Engineering (CSE) & Test: Trees - 1 solutions in Hindi for Computer Science Engineering (CSE) course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Trees - 1 | 15 questions in 45 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
Test: Trees - 1 - Question 1

Which of the following is a true about Binary Trees

Detailed Solution for Test: Trees - 1 - Question 1

A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in which every node other than the leaves has two children.

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

A) is incorrect. For example, the following Binary tree is neither complete nor full

     12
   /  
  20
 /
30
B) is incorrect. The following binary tree is complete but not full

     12
   /   \
  20    30
 /
30
C) is incorrect. Following Binary tree is full, but not complete

     12
   /   \
  20    30
       /  \  
      20   40
D) is incorrect. Following Binary tree is both complete and full

      12
    /   \
   20    30
  /  \  
 10   40

Test: Trees - 1 - Question 2

In a complete k-ary tree, every internal node has exactly k children or no child. The number of leaves in such a tree with n internal nodes is:

Detailed Solution for Test: Trees - 1 - Question 2

For an k-ary tree where each node has k children or no children, following relation holds
L = (k-1)*n + 1

Where L is the number of leaf nodes and n is the number of internal nodes.
since its a complete k tree, so every internal node will have K child
Let us see following for example

k = 3
Number of internal nodes n = 4
Number of leaf nodes = (k-1)*n + 1
= (3-1)*4 + 1
= 9

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Trees - 1 - Question 3

The maximum number of binary trees that can be formed with three unlabeled nodes is:

Detailed Solution for Test: Trees - 1 - Question 3

Following are all possible unlabeled binary trees


Note that nodes are unlabeled. If the nodes are labeled, we get more number of trees.
We can find the number of binary tree by Catalan number number:
Here n = 3
Number of binary tree = (2nCn)/ n+1
= (2*3C3)/ 4+1
= 5.
So, option (B) is correct.

Test: Trees - 1 - Question 4

The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:

Detailed Solution for Test: Trees - 1 - Question 4

Let L be the number of leaf nodes and I be the number of internal nodes, then following relation holds for above given tree.

  L = (3-1)I + 1 = 2I + 1
Total number of nodes(n) is sum of leaf nodes and internal nodes

  n = L + I
After solving above two, we get L = (2n+1)/3

Test: Trees - 1 - Question 5

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?

Detailed Solution for Test: Trees - 1 - Question 5

For an n-ary tree where each node has n children or no children, following relation holds

    L = (n-1)*I + 1
Where L is the number of leaf nodes and I is the number of internal nodes.

Let us find out the value of n for the given data.

  L = 41 , I = 10
  41 = 10*(n-1) + 1
  (n-1) = 4
  n = 5

Test: Trees - 1 - Question 6

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.

Detailed Solution for Test: Trees - 1 - Question 6

 For a right skewed binary tree, number of nodes will be 2n – 1. For example, in below binary tree, node ‘A’ will be stored at index 1, ‘B’ at index 3, ‘C’ at index 7 and ‘D’ at index 15.

Test: Trees - 1 - Question 7

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 in-order traversal of the tree T? (GATE CS 2005)

Detailed Solution for Test: Trees - 1 - Question 7

Inorder traversal of a BST always gives elements in increasing order. Among all four options, a) is the only increasing order sequence.

Test: Trees - 1 - Question 8

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?

Detailed Solution for Test: Trees - 1 - Question 8

(1 (2 3 4)(5 6 7)) represents following binary tree 

A) (1 2 (4 5 6 7)) is not fine as there are 4 elements in one bracket.

B) (1 (2 3 4) 5 6) 7) is not fine as there are 2 opening brackets and 3 closing.

D) (1 (2 3 NULL) (4 5)) is not fine one bracket has only two entries (4 5)

Test: Trees - 1 - Question 9

In a binary tree with n 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?

Detailed Solution for Test: Trees - 1 - Question 9

It is mentioned that each node has odd number of descendants including node itself, so all nodes must have even number of descendants 0, 2, 4 so on. Which means each node should have either 0 or 2 children. So there will be no node with 1 child. Hence 0 is answer.

Following are few examples.

       a
    /    \
   b      c


      a
    /   \
   b     c  
  /  \
 d    e
Such a binary tree is full binary tree (a binary tree where every node has 0 or 2 children).

Test: Trees - 1 - Question 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

Detailed Solution for Test: Trees - 1 - Question 10

Number of nodes is maximum for a perfect binary tree.
A perfect binary tree of height h has 2h+1 - 1 nodes

Number of nodes is minimum for a skewed binary tree.
A perfect binary tree of height h has h+1 nodes.

Test: Trees - 1 - Question 11

A binary tree T has 20 leaves. The number of nodes in T having two children is

Detailed Solution for Test: Trees - 1 - Question 11

Sum of all degrees = 2 * |E|.

Here considering tree as a k-ary tree :

Sum of degrees of leaves + Sum of degrees for Internal Node except root + Root's degree = 2 * (No. of nodes - 1).
Putting values of above terms,
L + (I-1)*(k+1) + k = 2 * (L + I - 1)
L + k*I - k + I -1 + k = 2*L + 2I - 2
L + K*I + I - 1 = 2*L + 2*I - 2
K*I + 1 - I = L
(K-1)*I + 1 = L
Given k = 2, L=20
==> (2-1)*I + 1 = 20
==> I = 19
==> T has 19 internal nodes which are having two children.

Test: Trees - 1 - Question 12

Consider a complete binary tree where the left and the right subtrees of the root are max-heaps. The lower bound for the number of operations to convert the tree to a heap is

Detailed Solution for Test: Trees - 1 - Question 12

The answer to this question is simply max-heapify function. Time complexity of max-heapify is O(Log n) as it recurses at most through height of heap.

// A recursive method to heapify a subtree with root at given index
// This method assumes that the subtrees are already heapified
void MinHeap::MaxHeapify(int i)
{
    int l = left(i);
    int r = right(i);
    int largest = i;
    if (l < heap_size && harr[l] < harr[i])
        largest = l;
    if (r < heap_size && harr[r] < harr[smallest])
        largest = r;
    if (largest != i)
    {
        swap(&harr[i], &harr[largest]);
        MinHeapify(largest);
    }
}

Test: Trees - 1 - Question 13

Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the maximum possible value of n is ________.

Detailed Solution for Test: Trees - 1 - Question 13

It would be node number 31 for given distance 4.

For example if we consider at distance 2, below highlighted node G can be the farthest node at position 7.

            A
         /    \
        B       C
       / \     / \
      D   E   F   G
Alternative Solution :
t is the n-th vertex in this BFS traversal at distance four from the root. So height of tree is 4.
Max number of nodes = 2{h+1} − 1 = 2{5} − 1 = 31
At distance four, last node is 31. option (C)

Test: Trees - 1 - Question 14

The number of structurally different possible binary trees with 4 nodes is

Detailed Solution for Test: Trees - 1 - Question 14

The total number of structurally different possible binary trees can be found out using the Catalon number which is (2n)!/ (n! *(n+1)!).
Here n=4, so, answer is 14.

Test: Trees - 1 - Question 15

A full binary tree with n leaves contains

Detailed Solution for Test: Trees - 1 - Question 15

A Binary Tree is full if every node has 0 or 2 children. Following are examples of full binary tree. We can also say a full binary tree is a binary tree in which all nodes except leaves have two children. A full binary tree with n leaves contains 2 * n – 1 nodes.
So, option (C) is correct.

Information about Test: Trees - 1 Page
In this test you can find the Exam questions for Test: Trees - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Trees - 1, EduRev gives you an ample number of Online tests for practice

Top Courses for Computer Science Engineering (CSE)

Download as PDF

Top Courses for Computer Science Engineering (CSE)