adplus-dvertising

Welcome to the Trees MCQs Page

Dive deep into the fascinating world of Trees with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Trees, a crucial aspect of Data Structures and Algorithms. In this section, you will encounter a diverse range of MCQs that cover various aspects of Trees, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Data Structures and Algorithms.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Trees. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Data Structures and Algorithms.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Trees. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Trees MCQs | Page 18 of 32

Explore more Topics under Data Structures and Algorithms

Q171.
Level order traversal of a tree is formed with the help of
Discuss
Answer: (a).breadth first search
Discuss
Answer: (d).all of the mentioned
Q173.
The following lines talks about deleting a node in a binary tree.(the tree property must not be violated after deletion)
i) from root search for the node to be deleted

ii)

iii) delete the node at

what must be statement ii) and fill up statement iii)
Discuss
Answer: (d).ii)-find deepest node,replace with node to be deleted. iii)- delete the deepest node
Discuss
Answer: (a).find_size(root_node–>left_node) + 1 + find_size(root_node–>right_node)
Q175.
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
Discuss
Answer: (a).code for having recursive calls to either only left tree or right trees or to both subtrees depending on their existence
Q176.
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)
  }
}
Discuss
Answer: (c).printing ancestors of a node passed as argument
Q177.
Select the code snippet which performs pre-order traversal.
a)

public void preorder(Tree root)
{
 System.out.println(root.data);
 preorder(root.left);
 preorder(root.right);
}

b)

public void preorder(Tree root)
{
 preorder(root.left);
 System.out.println(root.data);
 preorder(root.right);
}

c)

public void preorder(Tree root)
{
 System.out.println(root.data);
 preorder(root.right);
 preorder(root.left);
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q178.
Select the code snippet which performs post-order traversal.
a)

public void postorder(Tree root)
{
 System.out.println(root.data);
 postorder(root.left);
 postorder(root.right);
}

b)

public void postorder(Tree root)
{
 postorder(root.left);
 postorder(root.right);
 System.out.println(root.data);
}

c)

public void postorder(Tree root)
{
 System.out.println(root.data);
 postorder(root.right);
 postorder(root.left);
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q179.
Select the code snippet that performs pre-order traversal iteratively.
a)

public void preOrder(Tree root) 
{   
        if (root == null) return;
 Stack<Tree> stk = new Stack<Tree>();
        st.add(root);        
 while (!stk.empty()) 
        {
            Tree node = stk.pop();           
            System.out.print(node.data + " ");
   if (node.left != null) stk.push(node.left);
            if (node.right != null) stk.push(node.right);
        }
}

b)

public void preOrder(Tree root) 
{   
        if (root == null) return;
  Stack<Tree> stk = new Stack<Tree>();      
 while (!stk.empty()) 
        {
            Tree node = stk.pop();           
            System.out.print(node.data + " ");
            if (node.right != null) stk.push(node.right);
            if (node.left != null) stk.push(node.left);
        }
}

c)

public void preOrder(Tree root) 
{   
        if (root == null) return;
 Stack<Tree> stk = new Stack<Tree>();
        st.add(root);        
 while (!stk.empty()) 
        {
            Tree node = stk.pop();           
            System.out.print(node.data + " ");
            if (node.right != null) stk.push(node.right);
            if (node.left != null) stk.push(node.left);
        }
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (c).c
Q180.
What is the time complexity of pre-order traversal in the iterative fashion?
Discuss
Answer: (b).O(n)

Suggested Topics

Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!