Short answer: the code is incorrect.
You cannot simply return true
from the moment one of the checks succeeds. A minheap is a structure where for every node this check must hold.
Furthermore it is more safe to check whether the parent of a node is indees less than (or equal) to the node itself. Since the last layer of the heap can be incomplete.
public boolean check(int [] arr){
if(arr == null){ // check whether the arr is null itself, not the element
return false; // here we assume null is not a heap (open for discussion)
}
for(int i=1 ; i < arr.length ;i++){
if(x[i] < x[(i-1)/2]){ // the node is less than its parent
return false; // we know there is an error, so return false
}
}
return true; // all checks succeeded, return true
}