I have some doubts about this algorithm which checks if a binary tree is a binary search tree:
isAbr(x)
{
if(x == NULL)
return <true, -∞, +∞>;
if(x.left == NULL && x.right == NULL)
return <true, x.key, x.key>;
<abrLeft, minLeft, maxLeft> = isAbr(x.left);
<abrRight, minRight, maxRight> = isAbr(x.left);
abr = abrLeft && abrRigh && (x.key > maxLeft) && (x.key < minLeft);
min = MIN(minLeft, minRight, x.k);
max = max(maxLeft, maxRight, x.k);
return <abr, min, max>
}
in particular, it is not clear to me what happens when a node has only one child:
for example, here, the node with the value 6 returns $<true, 6, 6>$, and the NULL node to the right of the root returns $<true, -∞, + ∞>$; but with the instruction abr = abrLeft && abrRigh && (x.key > maxLeft) && (x.key < minLeft);
don't we get FALSE $(8 < -∞)$?