Question: class tree: def __init__(self, key): self.key = key self.left = None self.right = None def find_longest_word(self): res = root.data t2 = tree('apple') t2.left = tree('banana')
class tree: def __init__(self, key): self.key = key self.left = None self.right = None def find_longest_word(self): res = root.data t2 = tree('apple') t2.left = tree('banana') t2.left.right = tree('orange') t2.right = tree('strawberry') t2.right.left = tree('grape') t2.right.left.right = tree('peach') print(find_longest_word)
Hello, need help with this python code. Im trying to have a binary tree that can determine which nodes have the longest words. I got stuck on the function part. please help and thank you. It should return strawberry!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
