What are the necessary condition for a Tree to be a heap?
(A)
the tree must be complete.
(B)
Every Root value is greater or smaller than the children’s value.
(C)
Both A and B
(D)
None
Answer: (C)
Explanation:
A Heap is a special Tree-based data structure in which the tree is a complete binary tree.
Types of Heap Data Structure
Generally, Heaps can be of two types:
- Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of its children. The same property must be recursively true for all sub-trees in that Binary Tree.
- Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of its children. The same property must be recursively true for all sub-trees in that Binary Tree.
Hence Option(C) is the correct answer.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!