Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS COMPLETE CODE Problem : Complete the function isBalanced() to take in a root node of a binary tree and return

PYTHON 3 PLEASE FOLLOW INSTRUCTIONS

COMPLETE CODE

Problem : Complete the function isBalanced() to take in a root node of a binary tree and return True if the tree is balanced, False otherwise.

Code:

class Node: def __init__(self, value): self.value = value self.left = None self.right = None def isBalanced(root): # TODO

root = Node(7) root.left = Node(4) root.left.left = Node(1) root.left.right = Node(5) """ 7 / 4 (NOT BALANCED) / \ 1 5 """ print(isBalanced(root)) # has to print False

root.right = Node(10) root.right.right = Node(13) """ 7 / \ 4 10 (BALANCED) / \ \ 1 5 13 """ print(isBalanced(root)) # must print True

root.left.left.left = Node(0) root.left.right = None """ 7 / \ 4 10 (NOT BALANCED) / \ 1 13 / 0 """ print(isBalanced(root)) # must print False

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions