8.2k views
2 votes
Add the following method to the LinkedBinaryTree class:

def leaves_list(self)
When called on a tree, it will create and return a list, containing the values stored at the leaves of the tree, ordered from left to right. For example, if called on the tree from question 1, it should return: [5, 1, 8, 4]
Implementation requirement: 1. Your method should run in linear time.

User Mpaolini
by
4.9k points

1 Answer

6 votes

Answer:

Output

5

9

1

2

3

8

7

4

Step-by-step explanation:

See attached image

Add the following method to the LinkedBinaryTree class: def leaves_list(self) When-example-1
Add the following method to the LinkedBinaryTree class: def leaves_list(self) When-example-2
Add the following method to the LinkedBinaryTree class: def leaves_list(self) When-example-3
Add the following method to the LinkedBinaryTree class: def leaves_list(self) When-example-4
User Mayank Garg
by
5.4k points