Menu

Trees Questions

MCQ
81.
Level order traversal of a tree is formed with the help of
forum Discussion
MCQ
82.
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
forum Discussion
MCQ
83.
Select the code snippet that performs pre-order traversal iteratively.

a)

public void preOrder(Tree root) 
{   
        if (root == null) return;
 Stack stk = new Stack();
        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 stk = new Stack();      
 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 stk = new Stack();
        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
forum Discussion
MCQ
84.
What is the time complexity of pre-order traversal in the iterative fashion?
forum Discussion
MCQ
85.
What is the space complexity of the post-order traversal in the recursive fashion? (d is the tree depth and n is the number of nodes)
forum Discussion
MCQ
86.
To obtain a prefix expression, which of the tree traversals is used?
forum Discussion
MCQ
87.
Select the code snippet which performs in-order traversal.

a)

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

b)

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

c)

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

d) None of the mentioned
forum Discussion
MCQ
88.
Select the code snippet which performs level-order traversal.
forum Discussion
MCQ
89.
What is the space complexity of the in-order traversal in the recursive fashion? (d is the tree depth and n is the number of nodes)
forum Discussion
MCQ
90.
What is the time complexity of level order traversal?
forum Discussion