BEGINNER · 10 MIN · FREE LESSON
Binary tree & traversals
Explore binary tree & traversals through a visual, step-by-step model.
Loading interactive lesson…
BEGINNER · 10 MIN · FREE LESSON
Explore binary tree & traversals through a visual, step-by-step model.
Loading interactive lesson…
Enter {"values":[4,2,6,1,3,5,7],"order":"in"}. Values describe a complete binary tree in level order; order is pre/in/post/level.
Visit the next node in the selected traversal order.
[]
Every node is visited once. DFS changes when the root is emitted; level order uses a FIFO frontier.
Measured reads + comparisons, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
Tour the same building by entering rooms before, between or after visiting their wings.
Choose when to visit the root. Inspect the changing tree, variables and operation counters before stepping backward to compare states.
Predict the branch, repair, visited node or range block. Try the single-element case, then use a larger seeded input.
O(n) time; O(h) DFS stack or O(w) level frontier. Traversal order changes the output without changing the tree. The input is a complete binary tree, not an implicit BST; inorder is sorted only if the tree already satisfies BST ordering.
The four language references show the underlying operations. The teaching scene uses bounded, validated inputs; standalone callers must respect the stated structure and index assumptions.
Use preorder for structural serialization, postorder for bottom-up computation and BFS for layers.
Do not infer BST ordering merely because the tree is binary.
Explain the invariant and one boundary case before checking your answers.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.