17. Does array represent Heap
The problem can be found at the following link: Question Link
My Approach
We iterate through each non-leaf node of the binary tree represented by the array.
For each node, we check if it violates the heap property. If it does, we return false.
If we reach the end of the loop without finding any violations, we return true.
Time and Auxiliary Space Complexity
Time Complexity : O(n), where n is the number of elements in the array. We iterate through each non-leaf node once.
Auxiliary Space Complexity : O(1), no extra space is used.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the getlost01/gfg-potd repository.
Last updated