Binary Search Trees & the Release Catalog
In short: a binary search tree is a binary tree with one rule, holding at every node: every key in the left subtree is smaller, and every key in the right subtree is bigger (Tunebox sends ties right). That single rule turns search, insert and range queries into one path from the root — O(h), where h is the tree's height. The catch: h depends entirely on the order keys arrive in. The same keys can build a tree of height 3 or height 7, and only self-balancing trees (AVL, red-black) guarantee the short one.

Keep the release catalog ordered as it grows
New releases land every day. Re-sorting a list after every insert costs O(n log n) each time; a BST takes a new release by walking a single path. Each new year walks down from the root, going left when it is earlier and right otherwise, so the rule holds for every ancestor, not just the parent:
Each new year walks down from the root, going left when it is earlier and right otherwise, so the rule holds for every ancestor and not just the parent.
1987 is earlier than 1999, so it lands in the left subtree. Binary tree, 2 nodes, height 2. At node 1987.
The rule covers whole subtrees, not just a node's two children — and that's exactly where a shallow check goes wrong:
class Node:
def __init__(self, key, left=None, right=None):
self.key, self.left, self.right = key, left, right
def looks_ok(node):
if node is None:
return True
if node.left and node.left.key >= node.key:
return False
if node.right and node.right.key < node.key:
return False
return looks_ok(node.left) and looks_ok(node.right)
root = Node(1999, Node(1987, None, Node(2003)), Node(2012))
print(looks_ok(root))Insertion follows the path a search would: step left or right until you fall
off onto None, and that empty slot is where the new key belongs.
Returning root from every call is what lets one line —
root.left = insert(...) — attach the new node, and it handles an empty tree
for free. Step through four more inserts and watch the shape form:
Your BST insert, one comparison per level — the new key always ends up as a leaf.