// binary tree algorithm

preorder traversal — visualized

1 2 3 4 5 6 7
Currently visiting
Already printed
Waiting (in recursion stack)
Step 0 / 13 — Press Next to start
Output so far:
1
2
4
5
3
6
7
void preorder(Node* root) { if (root != NULL) { printf("%d ", root->data); // ① VISIT ROOT first preorder(root->left); // ② go LEFT preorder(root->right); // ③ go RIGHT } // NULL → base case, return immediately }
Preorder = Root → Left → Right mnemonic "Visit before you descend"