Data Structure Multiple Choice Questions on “Weak Heap”.
1. Choose the correct properties of weak-heap.
a) Every node has value greater than the value of child node
b) Every right child of node has greater value than parent node
c) Every left child of node has greater value than parent node
d) Every left and right child of node has same value as parent node
Answer: b
Clarification: This is the property of a weak heap.
2. Left child of parent node has value lesser than the parent node.
a) True
b) False
Answer: b
Clarification: Weak heap has no left child.
3. What is the other name of weak heap?
a) Min-heap
b) Max-heap
c) Relaxed -heap
d) Leonardo heap
Answer: c
Clarification: Relaxed heap is just another name of weak heap.
4. What is the worst case time in searching minimum value in weak -heap?
a) O(log n)
b) O(n)
c) O(n logn)
d) O(1)
Answer: d
Clarification: Weak heap is an array based form that supports the operation of finding a minimum in O(1).
5. The total comparisons in finding both smallest and largest elements are
a) 2*n +2
b) n + ((n+1)/2) -2
c) n+logn
d) n2
Answer: b
Clarification: The total comparisons in finding smallest and largest elements is n + ((n+1)/2) – 2.
6. What is the complexity of given function of insertion.
insert(int n) { if(buffer_size()< maxi_biffer_size()) buffer_aar[ind]==n; else move_to_heap(buffer,buffer+maxi_buffer_size()) }
a) O(logn)
b) amortized O(1)
c) O(n)
d) O (n*logn)
Answer: b
Clarification: Use a buffer array to store a fixed number of elements when the buffer is full the content of buffer is moved to heap.As a result the complexity
is amotized O(1).
7. Does there exist a heap with seven distinct elements so that the Inorder traversal gives the element in sorted order.
a) Yes
b) No
Answer: b
Clarification: No, The inorder traversal will not give elements in sorted order. As heap is implemented as either min-heap or max-heap, the root will be have highest or lowest value than remaining values of the nodes. So this traversal will not give a sorted list.
8. The leaf node for a heap of height h will be at which position.
a) h
b) h-1
c) h or h-1
d) h-2
Answer: c
Clarification: A complete binary tree is also a heap so by the property of binary tree the leaf nodes will be must at height h or h-1.