Quiz On Tree Data Structure

Last Updated : 26 Dec, 2023

Tree Data Structure is a hierarchical data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes.

More on Tree Data Structure

Tree Data structure

Tree Data structure

Question 1

For the expression (7-(4*5))+(9/3) which of the following is the post order tree traversal?

Cross

*745-93/+

Cross

93/+745*-

Tick

745*-93/+

Cross

74*+593/-



Question 1-Explanation: 

First build a binary tree for the expression then find out the postorder traversal of that tree and after that the answer will be 745*-93/+.

Question 2

Which traversal's pseudo code is written here?

order(node)
Q → Queue()
Q.push(node)
while !Q.empty():
    current_node = Q.pop()
    print current_node.value
if current_node.left is not NULL:
    Q.push(current_node.left)
if current_node.right is not NULL:
    Q.push(current_node.right)
Tick

Level order

Cross

Pre-order

Cross

Post-order

Cross

In-order



Question 2-Explanation: 

This is the pseudo code of level-order traversal.

Question 3

Which traversal is shown by this pseudo code?

Order(node):
  if node is not null:
   Order(node.left)
  print node.value
    Order(node.right)
Tick

In-order

Cross

Level Order

Cross

Post-order

Cross

Pre-order



Question 3-Explanation: 

This is the code for in-order traversal.

Question 4

The time complexity of calculating the sum of all leaf nodes in an n-order binary tree is __________

Cross

O(n2)

Cross

O(n+1)

Cross

O(1)

Tick

O(n)
 



Question 4-Explanation: 

The approach is to traverse the binary tree in any fashion and check if the node is the leaf node(child node)or not. After that, add node data to the sum variable. So, after summing up all leaf nodes, the time complexity of the operation should be O(n).

Question 5

What is a full binary tree?

Tick

Each node has exactly zero or two children

Cross

Each node has exactly two children

Cross

All the leaves are at the same level

Cross

Each node has exactly one or two children



Question 5-Explanation: 

A full binary tree is a tree in which each node has exactly 0 or 2 children.

Question 6

An important application of binary tree is ______

Tick

Huffman coding

Cross

stack implementation

Cross

queue implementation

Cross

traverse a cyclic graph



Question 6-Explanation: 

A binary tree is used to sort a list of elements; the inorder traversal will do this automatically. Better tree sorting algorithm will involve balancing the trees. The binary coding, in particular for the Huffman coding is an immediate application of binary trees.

Question 7

In a full binary tree if there are L leaves, then total number of nodes N are?

Cross

N = 2*L

Cross

N = L + 1

Cross

N = L – 1

Tick

N = 2*L – 1



Question 7-Explanation: 

The relation between number of nodes(N) and leaves(L) is N=2*L-1.

Question 8

Which among the following is the pseudo code for post-order traversal?

Tick
Order(node):
    if node is not null:
       Order(node.left)
       Order(node.right)
       print node.value
Cross
Order(node):
    if node is not null:
       Order(node.right)
       Order(node.left)
        print node.value
Cross
Order(node):
    if node is not null:
       Order(node.left)
        print node.value
Cross

None of the above



Question 8-Explanation: 

This will be the code for post-order traversal-

Order(node):
    if node is not null:
       Order(node.left)
       Order(node.right)
       print node.value
Question 9

Construct a binary tree by using post-order and in-order sequences given below.
In-order: N, M, P, O, Q
Post-order: N, P, Q, O, M

Cross

A binary tree by using postorder & inorder sequences - option a

Cross

A binary tree by using postorder & inorder sequences - option b

Cross

A binary tree by using postorder & inorder sequences - option c

Tick

A binary tree by using postorder & inorder sequences - option d



Question 9-Explanation: 

Here,
Post-order Traversal: N, P, Q, O, M
In-order Traversal: N, M, P, O, Q
Root node of tree is the last visiting node in Post-order traversal. Thus, Root Node = ‘M’.
The partial tree constructed is:
The partial tree with the postorder traversal is O
The second last node in post-order traversal is O. Thus, node P becomes left child of node O and node Q becomes right child of node Q. Thus, the final tree is:
Final tree with node P become left child of node O & node Q become right child of node Q

Question 10

Which of the following is not an advantage of trees?

Cross

Hierarchical structure

Cross

Faster search

Cross

Router algorithms

Tick

Undo/Redo operations in a notepad



Question 10-Explanation: 

Undo/Redo operations in a notepad is an application of stack. Hierarchical structure, Faster search, Router algorithms are advantages of trees.

There are 10 questions to complete.


Share your thoughts in the comments

Similar Reads