No tree yet — build one from the controls.
AlgoPlus//structures / tree
Read the theory

Binary Search Tree

Smaller values go left, larger go right — build it, traverse it, search it.

Stability
In-Place
Space Complexity
Avg Time
Legend
Comparing
Visited / found
Node
AI Tutor Workspace
In a nutshell
A binary search tree keeps numbers sorted by shape: every node sits above two branches, with all smaller values in its left branch and all larger ones in its right. To find or insert a value you start at the top and step left or right by comparison, so you only ever walk one path down — about as many steps as the tree is tall. Reading it left-branch, node, right-branch (an in-order traversal) returns the values in sorted order.
Ready
Press play to begin the cinematic walkthrough.
Smaller values branch left, larger branch right. Searching walks one path down by comparison, and an in-order traversal reads the keys back out in sorted order.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Binary Search Tree.
Code Simulator
1
def bst(root, val):
2
    # insert / search / traverse
3
    if root is None:
4
        return Node(val)  # Inserted/Found
5
    if val < root.val:
6
        root.left = bst(root.left, val)
7
    else:
8
        root.right = bst(root.right, val)
9
    # traversal order
10
    visit(root.val)  # Visit
Why Python? · Readable first, fast second

Dynamically typed and interpreted — every comparison and swap is dispatched by the interpreter at run time, so tight loops run roughly 10–100× slower than compiled C/C++. Unbeatable for learning the idea with the least code; not what you reach for when the inner loop is the bottleneck.