AlgoPlus//machine learning / decision-tree
Read the theory

Decision Tree

Carve the feature space with axis-aligned splits that purify the data.

Splits
Leaves
Your labelled points (x,y,class — class 0 or 1)
Legend
Class 1
Class 0
Split
AI Tutor Workspace
In a nutshell
A decision tree classifies by asking a chain of yes/no questions. At each node it picks the one feature-and-threshold split that best separates the classes — judged by an impurity score like Gini or entropy — then repeats on each branch until the groups are pure or it runs out of depth. To predict, you follow the answers down to a leaf and take that leaf's label.
Ready
Press play to begin the cinematic walkthrough.
Play twenty questions with the data: at each node ask the yes/no question that best splits the classes apart, then ask again on each side until the groups are pure.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Decision 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.