Binary Trees using Linked Lists | Data Structure MCQs

1.

How to travel a tree in linkedlist representation?

   A.) using post order traversing
   B.) using pre order traversing
   C.) using post order traversing
   D.) all of these

Answer: Option 'D'

Also level order traversing is possible.

2.

What is missing in this logic of finding a path in the tree for a given sum (i.e checking whether there will be a path from roots to leaf nodes with given sum) ?

checkSum(struct bin-treenode *root , int sum) :
  if(root==null)
    return sum as 0
  else :
     leftover_sum=sum-root_node-->value
     //missing

   A.) code for having recursive calls to either only left tree or right trees or to both subtrees depending on their existence
   B.) code for having recursive calls to either only left tree or right trees
   C.) code for having recursive calls to either only left tree
   D.) code for having recursive calls to either only right trees

Answer: Option 'A'

if(left subtree and right subtree) then move to both subtrees
else if only left subtree then move to left subtree carrying leftover_sum parameter
else if only right subtree then move to right subtree carrying leftover_sum parameter.

3.

What is the code below trying to print?

void print(tree *root,tree *node)
{
  if(root ==null) return 0
  if(root-->left==node || root-->right==node || print(root->left,node)||printf(root->right,node)
  {
     print(root->data)
  }
}

   A.) just printing all nodes
   B.) not a valid logic to do any task
   C.) printing ancestors of a node passed as argument
   D.) printing nodes from leaf node to a node passed as argument

Answer: Option 'C'

We are checking if left or right node is what the argument sent or else if not the case then move to left node or right node and print all nodes while searching for the argument node.

4.

Advantages of linked list representation of binary trees over arrays?

   A.) dynamic size
   B.) ease of insertion/deletion
   C.) ease in randomly accessing a node
   D.) both dynamic size and ease in insertion/deletion

Answer: Option 'D'

both dynamic size and ease in insertion/deletion

5.

Disadvantages of linked list representation of binary trees over arrays?

   A.) Randomly accessing is not possible
   B.) Extra memory for a pointer is needed with every element in the list
   C.) Difficulty in deletion
   D.) Random access is not possible and extra memory with every element

Answer: Option 'D'

Random access is not possible and extra memory with every element

6.

What may be the psuedo code for finding the size of a tree?

   A.) find_size(root_node–>left_node) + 1 + find_size(root_node–>right_node)
   B.) find_size(root_node–>left_node) + find_size(root_node–>right_node)
   C.) find_size(root_node–>right_node) – 1
   D.) find_size(root_node–>left_node + 1

Answer: Option 'A'

Draw a tree and analyze the expression. we are always taking size of left subtree and right subtree and adding root value(1) to it and finally printing size.

7.

Why we prefer threaded binary trees?

   A.) storage required by stack and queue is more
   B.) pointers in most of nodes of a binary tree are NULL
   C.) difficult to find a successor node
   D.) all of the above

Answer: Option 'D'

All the given options are properties for a threaded tree.

8.

Level order traversal of a tree is formed with the help of

   A.) breadth first search
   B.) depth first search
   C.) dijkstra’s algorithm
   D.) prims algorithm

Answer: Option 'A'

breadth first search
Level order is similar to bfs.

Binary Trees using Linked Lists | Data Structure MCQs Download Pdf