The following python code describes an algorithm for inserting values into a binary search tree.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

classNode:def__init__(self,val):self.left_child=Noneself.right_child=Noneself.data=valdefbinary_insert(tree,val):# insert val at root if tree is emptyiftreeisNone:tree=Node(val)else:# if val is less than current node, # insert val into left subtreeif(tree.data>val):tree.left_child=binary_insert(tree.left_child,val)# else, insert val into right subtreeelse:tree.right_child=binary_insert(tree.right_child,val)returntree

Using this algorithm, you create a new binary search tree B, and insert the following elements into it in this order:

1

4,2,1,5,6,3,7,9,8,12,10,11,13,15,14

After these operations, what is the sum of the data in the leaf nodes of B?

Details and assumptions

A leaf node is a node that has no children (no left_child or right_child).

Excel in math and science

Master concepts by solving fun, challenging problems.

It's hard to learn from lectures and videos

Learn more effectively through short, interactive explorations.

Used and loved by over 8 million people

Learn from a vibrant community of students and enthusiasts,
including olympiad champions, researchers, and professionals.

Your answer seems reasonable.
Find out if you're right!