Binary Tree Visualizer

Paste a level-order array, render the binary tree shape, and compare traversal orders without changing the structure into a binary search tree.

Nodes
6
Height
3
Leaves
3
Nulls
1

Level-order input

Use null for missing children. Values are read breadth first from left to right.

Traversal

Example inputs

Binary tree diagram

Sample tree loaded from LeetCode-style level-order input.

Traversal
Binary tree diagramCurrent binary tree built from level-order input [1, 2, 3, null, 4, 5, 6].241536

Level-order result

Run a traversal to see visit order. Unlike a BST, in-order traversal does not automatically sort a general binary tree.

Current level-order array

[1, 2, 3, null, 4, 5, 6]

This page preserves the shape you provide. Use the BST visualizer when you want values placed by search-tree ordering rules.

What is a Binary Tree Visualizer?

A binary tree visualizer is an interactive tool that turns level-order array input into a tree diagram. It is useful when you want to understand a tree’s shape, compare traversal orders, or check coding interview examples that use null placeholders.

This visualizer supports LeetCode-style input such as [1, 2, 3, null, 4]. The values are read from left to right, level by level, and null marks a missing child.

For the full set of related learning tools, start with the Data Structure Visualizers hub.

How to use the binary tree visualizer

  • Paste a level-order array into the input box.
  • Use null for missing left or right children.
  • Click Build to render the binary tree.
  • Run in-order, pre-order, post-order, or level-order traversal.
  • Copy the traversal output if you want to compare it with your code.

For example, [1, null, 2, 3] means the root is 1, the root has no left child, the root’s right child is 2, and 2 has a left child 3.

Binary tree vs binary search tree

A binary tree is any tree where each node has at most two children. The left and right child positions matter, but there is no automatic ordering rule.

A binary search tree is a special kind of binary tree. In a BST, smaller values go to the left and larger values go to the right. If you want that ordering behavior, use the Binary Search Tree Visualizer.

If you want a tree that automatically keeps itself balanced, compare this with the AVL Tree Visualizer. If you want priority-queue behavior instead of tree search, use the Heap Visualizer.

Common binary tree traversal orders

In-order traversal visits the left child, then the current node, then the right child.

Pre-order traversal visits the current node before visiting its children.

Post-order traversal visits both children before visiting the current node.

Level-order traversal visits the tree breadth first, from top to bottom and left to right.

Frequently Asked Questions

What input format does this binary tree visualizer use?
The tool uses level-order array input, the same style commonly used in LeetCode binary tree problems.
Can I use null values in the array?
Yes. Use null to mark a missing child, such as [1, null, 2, 3].
Does in-order traversal sort the values?
No. In-order traversal only returns sorted values for a binary search tree. For a general binary tree, it follows the left-node-right visit order without sorting.
Can duplicate values be shown in the tree?
Yes. A general binary tree can contain duplicate values because the shape is controlled by the input array rather than search-tree ordering rules.

Related tools