Sail E0 Webinar

MCQs

Total Questions : 12 | Page 1 of 2 pages
Question 1. Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations?
  1.    just build the tree with the given input
  2.    find the median of the set of elements given, make it as root and construct the tree
  3.    use trial and error
  4.    use dynamic programming to build the tree
 Discuss Question
Answer: Option B. -> find the median of the set of elements given, make it as root and construct the tree


Sort the given input, find the median element among them, make it as root and construct left and right subtrees with elements lesser and greater than the median element recursively. this ensures the subtrees differ only by height 1.


Question 2. How will you find the minimum element in a binary search tree?
  1.    public void min(Tree root){
  2.    public void min(Tree root){
  3.    public void min(Tree root){
  4.    public void min(Tree root){
 Discuss Question
Answer: Option A. -> public void min(Tree root){


Since all the elements lesser than a given node will be towards the left, iterating to the leftmost leaf of the root will give the minimum element in a binary search tree.


Question 3. Which of the following is not an advantage of trees?
  1.    Hierarchical structure
  2.    Faster search
  3.    Router algorithms
  4.    Undo/Redo operations in a notepad
 Discuss Question
Answer: Option D. -> Undo/Redo operations in a notepad


This is an application of stack.


Question 4. 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)
  1.    ii)-find random node,replace with node to be deleted. iii)- delete the node
  2.    ii)-find node to be deleted. iii)- delete the node at found location
  3.    ii)-find deepest node,replace with node to be deleted. iii)- delete a node
  4.    ii)-find deepest node,replace with node to be deleted. iii)- delete the deepest node
 Discuss Question
Answer: Option D. -> ii)-find deepest node,replace with node to be deleted. iii)- delete the deepest node


We just replace a to be deleted node with last leaf node of a tree. this must not be done in case of BST or heaps.


Question 5. If the tree is not a complete binary tree then what changes can be made for easy access of children of a node in the array ?
  1.    every node stores data saying which of its children exist in the array
  2.    no need of any changes continue with 2w and 2w+1, if node is at i
  3.    keep a seperate table telling children of a node
  4.    use another array parallel to the array with tree
 Discuss Question
Answer: Option A. -> every node stores data saying which of its children exist in the array


Array cannot represent arbitrary shaped trees it can only be used in case of complete trees hence option a must be done which is one of several ways to use array in such situations.


Question 6. After applying the below operations on a input sequence, what happens?
i. construct a cartesian tree for input sequence
ii. put the root element of above tree in a priority queue
iii. if( priority queue is not empty) then
.search and delete minimum value in priority queue
.add that to output
.add cartesian tree children of above node to priority queue
  1.    constructs a cartesian tree
  2.    sorts the input sequence
  3.    does nothing
  4.    produces some random output
 Discuss Question
Answer: Option B. -> sorts the input sequence


The above given steps are for sorting a cartesian tree. cartesian sort is benificial in case of partially sorted set of elements. a cartesian
sort can be considered as a selection or heap sort maintaining a priority queue.


Question 7. When it would be optimal to prefer Red-black trees over AVL trees?
  1.    when there are more insertions or deletions
  2.    when more search is needed
  3.    when tree must be balanced
  4.    when log(nodes) time complexity is needed
 Discuss Question
Answer: Option A. -> when there are more insertions or deletions


Though both trees are balanced, when there are more insertions and deletions to make the tree balanced, AVL trees should have more rotations, it would be better to use red-black. but if more search is required AVL trees should be used.


Question 8. Which of the following options is an application of splay trees ?
  1.    cache Implementation
  2.    networks
  3.    send values
  4.    receive values
 Discuss Question
Answer: Option A. -> cache Implementation


Splay trees can be used for faster access to recently accessed items and hence used for cache implementations.


Question 9. Select the code snippet that performs post-order traversal iteratively.
  1.    public void postorder(Tree root){        if (root == null)        return;
  2.    public void postorder(Tree root){        if (root == null)        return;
  3.    public void postorder(Tree root){        if (root == null)            return;
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> public void postorder(Tree root){        if (root == null)        return;


The left and right children are added first to the stack, followed by the node, which is then popped. Post-order follows LRN policy.


Question 10. What is the time complexity of level order traversal?
  1.    O(1)
  2.    O(n)
  3.    O(logn)
  4.    O(nlogn)
 Discuss Question
Answer: Option B. -> O(n)


Since you have to go through all the nodes, the complexity becomes O(n).


Latest Videos

Latest Test Papers