Data Structure Questions and Answers – Weak Heap

«
»

This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

Answer: b
Explanation: This is the property of a weak heap.
advertisement

2. Left child of parent node has value lesser than the parent node.
a) True
b) False
View Answer

Answer: b
Explanation: 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
View Answer

Answer: c
Explanation: Relaxed heap is just another name of weak heap.
advertisement
advertisement

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)
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: The total comparisons in finding smallest and largest elements is n + ((n+1)/2) – 2.
advertisement

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)
View Answer

Answer: b
Explanation: 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).
advertisement

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
View Answer

Answer: b
Explanation: 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.
advertisement

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
View Answer

Answer: c
Explanation: 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.

Sanfoundry Global Education & Learning Series – Data Structure.

To practice all areas of Data Structure, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter