Binary Tree Simulator
Build a binary tree, run pre-order, in-order, post-order and level-order traversals step by step, and see its height and leaf nodes.
Build the tree
Insert fills the tree level by level, left to right. Or click a node to select it and add a child exactly where you want.
Tree
Drag to move · scroll to zoom
Traversal
Pseudocode
The current line is highlighted.
Full order: D → B → E → A → F → C → G
About This Simulation
This binary tree simulator lets you build a tree level by level or by adding left and right children wherever you like. It animates pre-order, in-order, post-order and level-order traversals and shows the height, leaves and number of nodes.
Features
- Insert in level order or add a child to a selected node
- Delete a node together with its subtree
- Pre-order, in-order, post-order and level-order traversals step by step
- Visit order shown as a growing output sequence
- Height, node count, leaf nodes and internal nodes
Topics covered
- Binary Tree
- Root, Parent, Child and Leaf
- Tree Traversal
- Tree Height and Depth
- Recursion
Explanation
A binary tree is a hierarchical data structure where each node has at most two children, called the left child and the right child. The top node is the root, nodes without children are leaves, and the height of the tree is the number of edges on the longest path from the root to a leaf.
How it works
- Pre-order: visit the node, then traverse the left subtree, then the right subtree (root, left, right).
- In-order: traverse the left subtree, visit the node, then traverse the right subtree (left, root, right).
- Post-order: traverse the left subtree, then the right subtree, then visit the node (left, right, root).
- Level-order: visit nodes level by level from left to right, using a queue.
- The depth of a node is the number of edges from the root to it; the height of the tree is the greatest depth.
Why it matters
Binary trees are on the Cambridge 9618 syllabus and in university data structures courses. They underpin binary search trees, heaps, expression trees and syntax trees in compilers, and traversals are a classic use of recursion.
Frequently Asked Questions
What is the difference between pre-order, in-order and post-order?
They differ in when the node itself is visited: before its subtrees (pre-order), between them (in-order) or after them (post-order).
What is a leaf node?
A node with no children. Every other node is an internal node.
What is the height of a binary tree?
The number of edges on the longest path from the root down to a leaf. A tree with only a root has height 0.
Which traversal is used to evaluate an expression tree?
Post-order: both operands are evaluated before the operator. In-order gives the normal (infix) expression and pre-order gives prefix notation.
Related Simulations
Data Structures
Binary Search Tree Simulator
Insert, search and delete in a binary search tree step by step, including all three deletion cases and the in-order successor.
Data Structures
Heap Simulator
See min-heap and max-heap insertion, extraction and heapify as both a tree and an array, one swap at a time.
Data Structures
B+ Tree
Insert, delete, search in a B+ tree visualiser
Data Structures
Stack (ADT) Simulator
Visualise push, pop, overflow, and underflow operations

