can anyone help me understand this code part ?
this is about binary minimum heap , ie root has the lowest key..
the part of the code im trying to understand checks whether the subtree ( of a certain minHeap pq[1..N] ), rooted at k is also a min heap or not
private boolean isMinHeap(int k) {
if (k > N)
return true;
int left = 2 * k, right = 2 * k + 1;
if (left <= N && greater(k, left))
return false;
if (right <= N && greater(k, right))
return false;
return isMinHeap(left) && isMinHeap(right);
}
in the 2nd line , i dont understand the if statement... as the array which is used to implement the minheap is [1..N] , shouldnt k>N return false? as a value > N means its out of the array?
this is the full version from where i got the above part.