Check if a given Binary Tree is Heap - GeeksforGeeks
Check if a given Binary Tree is Heap Given a binary tree we need to check it has heap property or not, Binary tree need to fulfill following two conditions for being a heap – It should be a complete tree (i.e. all levels except last should be full). Every node's value should be greater than or equal to its child node (considering max-heap). For example this tree contains heap property – While this doesn't – We strongly recommend you to minimize your browser and try this yourself first. We check each of the above condition separately, for checking completeness isComplete and for checking heap isHeapUtil function are written. Detail about isComplete function can be found here . isHeapUtil function is written considering following things – Every Node can have 2 children, 0 child (last level nodes) or 1 child (there can be at most one such node).Read full article from Check if a given Binary Tree is Heap - GeeksforGeeks
No comments:
Post a Comment