Data Structures Multiple Choice Questions and Answers on Heap
![](http://img2.blogblog.com/img/icon18_edit_allbkg.gif)
https://www.computersprofessor.com/2017/10/data-structures-multiple-choice_24.html
1. In a max-heap, element with the greatest key is always in the which node?
a) Leaf node
b) First node of left sub tree
c) root node
d) First node of right sub tree
Answer: c
Explanation: This is one of the property of max-heap that root node must have key greater than its children.
2. Heap exhibits the property of a binary tree?
a) True
b) False
Answer: a
Explanation: Yes, Because the leaf nodes are present at height h or h-1 ,which is a property of complete binary tree.
3. What is the complexity of adding an element to the heap.
a) O(log n)
b) O(h)
c) a and b
d) None of the mentioned
Answer: c
Explanation: The total possible operation in re locating the new location to a new element will be equal to height of the heap.
4. The worst case complexity of deleting any arbitrary node value element from heap is
a) O(logn)
b) O(n)
c) O(nlogn)
d) O(n2)
Answer: a
Explanation: The total possible operation in deleting the existing node and re locating new position to all its connected nodes will be equal to height of the heap.
5. Heap can be used as…
a) Priority queue
b) Stack
c) A decreasing order array
d) None of the mentioned
Answer: a
Explanation: The property of heap that the value of root must be either greater or less than both of its children makes it work like a priority queue.
6.![data-structure-questions-answers-heap-q6](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tpUp5NUCIuFRSwImkRTktjjQaA7psQ8-B1gsUChZXAj5vBoTyb1411oOqn06aeTHybemxUlj0GpAtqvMyhiXjBlRRoE8FsQTIGB9AMMHjGd1YKgN67W8IQ1XlNjuMoqOuIuqsSDx9bxw726kN_McjSkYbwcJ7c54zSEr3H-HH0pf2JTQ=s0-d)
If we implement heap as min-heap , deleting root node (value 1)from the heap. What would be the value of root node after second iteration if leaf node (value 100) is chosen to replace the root at start.
If we implement heap as min-heap , deleting root node (value 1)from the heap. What would be the value of root node after second iteration if leaf node (value 100) is chosen to replace the root at start.
a) 2
b) 100
c) 17
d) 3
Answer: a
Explanation: As the root is deleted and node with value 100 is used as replaced one.There is a violation of property that root node must have value less than its children.So there will be shuffling of node with value 100 with node of value 2.And thus 2 becomes root. And it will remain to be at root after all the possible operations .So the value at root will be 2.
7.![data-structure-questions-answers-heap-q7](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_s5bYbdJVvqZpBQKm7xjAGw7S426OBLvD9J6-ElGmFx_4rNhn-opDwOnZqktt3ihQqk0ipwhcmG7JZWO7WLzDeSceZnsvCHAjaXVZKl39TU9pW6NA1e1stBc718tcM74zZ1LGRf93xAsVpW0bMdqqm7DD0_h4HYtRQfXgTHL4CdEcgbWw=s0-d)
If we implement heap as maximum heap , adding a new node of value 15 to the left most node of right subtree . What value will be at leaf nodes of the right subtree of the heap.
If we implement heap as maximum heap , adding a new node of value 15 to the left most node of right subtree . What value will be at leaf nodes of the right subtree of the heap.
a) 15 and 1
b) 25 and 1
c) 3 and 1
d) 2 and 3
Answer: a
Explanation: As 15 is less than 25 so there would be no violation and the node will remain at that position.So leaf nodes with value 15 and 1 will be at the position in right sub tree.
8. An array consist of n elements.We want to create a heap using the elements.The time complexity of building a heap will be in order of
a) O(n*n*logn)
b) O(n*logn)
c) O(n*n)
d) O(n *logn *logn)
Answer: b
Explanation: The total time taken will be N times the complexity of adding a single element to the heap .And adding a single element takes logN time,so That is equal to N*logN.