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 21 of 32

Explore more Topics under Data Structures and Algorithms

Q201.
What is the speciality about the inorder traversal of a binary search tree?
Discuss
Answer: (b).It traverses in an increasing order
Q202.
What does the following piece of code do?
public void func(Tree root)
{
	func(root.left());
	func(root.right());
	System.out.println(root.data());
}
Discuss
Answer: (c).Postorder traversal
Q203.
What does the following piece of code do?
public void func(Tree root)
{
	System.out.println(root.data());
	func(root.left());
	func(root.right());
}
Discuss
Answer: (a).Preorder traversal
Q204.
How will you find the minimum element in a binary search tree?
a)

public void min(Tree root)
{
 while(root.left() != null)
 {
  root = root.left();
 }
 System.out.println(root.data());
}

b)

public void min(Tree root)
{
 while(root != null)
 {
  root = root.left();
 }
 System.out.println(root.data());
}

c)

public void min(Tree root)
{
 while(root.right() != null)
 {
  root = root.right();
 }
 System.out.println(root.data());
}

d)

public void min(Tree root)
{
 while(root != null)
 {
  root = root.right();
 }
 System.out.println(root.data());
}

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q205.
How will you find the maximum element in a binary search tree?
a)

public void max(Tree root)
{
 while(root.left() != null)
 {
  root = root.left();
 }
 System.out.println(root.data());
}

b)

public void max(Tree root)
{
 while(root != null)
 {
  root = root.left();
 }
 System.out.println(root.data());
}

c)

public void max(Tree root)
{
 while(root.right() != null)
 {
  root = root.right();
 }
 System.out.println(root.data());
}

d)

public void max(Tree root)
{
 while(root != null)
 {
  root = root.right();
 }
 System.out.println(root.data());
}

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (c).c
Q206.
What are the worst case and average case complexities of a binary search tree?
Discuss
Answer: (d).O(n), O(logn)
Q207.
Given that 2 elements are present in the tree, write a function to find the LCA(Least Common Ancestor) of the 2 elements.
a)

public void lca(Tree root,int n1, int n2)
{
 while (root != NULL)
        {
            if (root.data() > n1 && root.data() > n2)
            root = root.right();
            else if (root.data() < n1 && root.data() < n2)
            root = root.left();
     else break;
        }
        System.out.println(root.data());
}

b)

public void lca(Tree root,int n1, int n2)
{
    while (root != NULL)
    {
        if (root.data() > n1 && root.data() < n2)
        root = root.left();
        else if (root.data() < n1 && root.data() > n2)
        root = root.right();
 else break;
    }
    System.out.println(root.data());
}

c)

public void lca(Tree root,int n1, int n2)
{
    while (root != NULL)
    {
        if (root.data() > n1 && root.data() > n2)
        root = root.left();
        else if (root.data() < n1 && root.data() < n2)
        root = root.right();
 else break;
    }
    System.out.println(root.data());
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (c).c
Discuss
Answer: (a).The tree should not be modified and you should know how often the keys are accessed, it improves the lookup cost
Discuss
Answer: (a).a tree which is balanced and is a height balanced tree
Q210.
Why we need to a binary tree which is height balanced?
Discuss
Answer: (a).to avoid formation of skew trees

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!