PythiloLesson 15 of 32 · progress kept in this browser

Insert into a binary search tree

In a binary search tree every value in a node's left subtree is smaller and every value in its right subtree is larger. Inserting walks down as a search would and attaches a new node where the search falls off the tree.

# 8 has 3 on the left and 10 on the right
# inserting 6: 6 < 8 go left, 6 > 3 go right
Your task

TreeNode(value) is provided. Write insert(root, value) returning the root after inserting value; insert into None to start a tree. Ignore a value that is already present.