A complete binary tree is defined as a binary tree in which every level, except possibly the deepest, is completely filled. At deepest level, all nodes must be as far left a
You can tell if a given binary tree is a left-complete binary tree - better known as a binary heap by ensuring that every node with a right child also has a left child. See below
bool IsLeftComplete(tree)
{
if (!tree.Right.IsEmpty && tree.Left.IsEmpty)
//tree has a right child but no left child, therefore is not a heap
return false;
if (tree.Right.IsEmpty && tree.Left.IsEmpty)
//no sub-trees, thus is leaf node. All leaves are complete
return true;
//this level is left complete, check levels below
return IsLeftComplete(tree.Left) && IsLeftComplete(tree.Right);
}