Write in pseudocode an algorithm that receives as input the
Write in pseudocode an algorithm that receives as input the root of a tree and it returns true if the tree is a proper binary tree (i.e. each internal node has 2 children) and false otherwise. Assume that r.children is the number of children of a node r. For example, for the tree below with root A the algorithm must return the value true, and for the tree with root B it must return the value false.
Solution
isProperTree:
if root = null //if the root is null it is a proper binary tree
return true
if root->left = null and root->right = null) //if leftchild and tight child are null it is proper
return true;
if root->left and root->right //if both are not null repeat from left and right
return ( goto: isProperTree(root->left) and goto:isProperTree(root->right))
return false //if none of the above works it is not proper.
end isPeoperTree.
