A full trinary tree has no missing nodes, i.e., all interior nodes have three ch
ID: 3685718 • Letter: A
Question
A full trinary tree has no missing nodes, i.e., all interior nodes have three children and all leaf nodes are at the same level as shown in these examples: public static boolean isFullTriTree(TrinaryTreenode n) {//TODO: COMPLETE THIS METHOD} The method is passed a reference to a TrinaryTreenode that is the squareroot of the tree. The TrinaryTreenode class is implemented as partially shown below: class TrinaryTreenode {//*** fields *** private T data; private TrinaryTreenode leftChild; private TrinaryTreenode midChild; private TrinaryTreenode rightChild;//***methods *** public T getData() { return data;} publicTrinaryTreenode getLeft() { return leftChild;} publicTrinaryTreenode getMidQ { return midChild;} publicTrinaryTreenode getRight() { return rightChild;}Explanation / Answer
Answer for Question:
This below method will check the weither given tree is full binary tree or not.
See the below method with comments..
/* This function tests if a binary tree is a full binary tree. */
bool isFullTree (struct Node* root)
{
// If empty tree
if (root == NULL)
return true;
// If leaf node
if (root->left == NULL && root->right == NULL)
return true;
// If both left and right are not NULL, and left & right subtrees
// are full
if ((root->left) && (root->right))
return (isFullTree(root->left) && isFullTree(root->right));
// We reach here when none of the above if conditions work
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.