Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote