Problem Complete the function isFull() to take in a root node of a tree and retu
ID: 3711300 • Letter: P
Question
Problem
Complete the function isFull() to take in a root node of a tree and return True if the tree is full, False otherwise.
A binary tree is considered full if all nodes have either 2 or 0 children (i.e. no node has only one child). In other words, a binary tree is full if all non-leaf nodes have exactly 2 children.
CODE:
def isFull(root):?
1 def isFullCroot): Problem Complete the function isFull() to take in a root node of a tree and return True if the tree is full, False otherwise. A binary tree is considered full if all nodes have either 2 or 0 children (i.e. no node has only one child). In other words, a binary tree is full if all non-leaf nodes have exactly 2 children.Explanation / Answer
def isFull(root): if root is None: return True else: count = 0 if root.left is not None: count += 1 if root.right is not None: count += 1 if count == 1: return False else: return isFull(root.left) and isFull(root.right)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.