Heap element with greatest key is always located in root - Data Structure

Q.  In a heap the element with the greatest key is always located in which node?
- Published on 25 Aug 15

a. leaf
b. root
c. first node of left sub tree
d. first node of right sub tree

ANSWER: root
 

    Discussion

  • Nirja Shah   -Posted on 21 Nov 15
    Heap is a complete binary tree such that root node is always greater than or equal to the key value in both its children. There are two types of heap, if the parent nodes are greater than their children, then it is called as Max-Heap , and if the parent nodes are smaller than their child nodes, heap is called Min-Heap . A heap can be considered as a priority queue; the most important node will always be at the top. Heap is also used in sorting.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)