KickSolve • Free • Private

General Tree Visualizer

A tree in which a node can have any number of children. Insert, delete, edit and search with step-by-step animation.

Any number of childrenPreorder, postorder, level orderLive node, height and leaf counts

How to use the General Tree Visualizer on KickSolve

Three quick steps, no account needed.

Type a value and a parentEnter a number or short word in the Value box. Type the parent in the Target box or click it in the tree. Leave the target empty to add under the root. The first value becomes the root.
Press Insert, Delete, Edit or SearchWatch the animation walk through the tree. Orange is a new node, red is being deleted and green is found. Delete subtree removes a node with everything below it.
Run a traversalUse the traversal buttons to see preorder, postorder and level order output, and check the node, height and leaf counts on the right.

Why choose KickSolve

Built for learning, speed and privacy.

Private by designEverything runs in your browser. Nothing you type is ever sent anywhere.
Animated, step by stepWatch every visit and placement as it happens, at a speed you choose.
Any number of childrenAdd as many children as you like under any node and watch the layout re-center itself.
Undo and experimentStep back through your last 40 changes, or generate a random tree to explore.

What you can do with the General Tree Visualizer

Everything this tool offers.

InsertAdd a child under the parent you type or click. Leave the parent empty to add under the root.
DeleteRemove a node. Its children move up into its place under the parent.
Delete subtreeRemove a node together with everything below it.
EditChange a node's value in place without moving it.
SearchScan the tree and highlight the first node that matches.
PreorderNode first, then each child from left to right.
PostorderEach child from left to right, then the node.
Level orderBreadth first, one level at a time.
Live countsNodes, height and leaves update after every change.
Copy and downloadCopy the tree as an image or save it as a PNG for notes and slides.
Click to selectClick any node to fill in the target box for insert, delete or edit.
Random and UndoGenerate a random tree, or step back through your changes.

About the General Tree Visualizer on KickSolve

What it does and how to get the best results.

What is a general tree?

A general tree is a hierarchical data structure with one root where every node can have any number of children, from zero to many. There is no limit on the number of children and no left or right naming.

Key properties

  • One root node with no parent
  • Each node has zero or more children
  • No restriction on the number of children
  • Nodes with no children are called leaves

Operations and time complexity

Traversal and search take O(n). Inserting a child is O(1) once the parent is found, and deleting a node is O(n) because the node must be located first.

Real-world uses

  • File and folder systems
  • Organization charts
  • HTML and XML DOM trees
  • Category and menu hierarchies

Comparing tree shapes? Try the Binary Tree, Full Binary Tree, Complete Binary Tree, Perfect Binary Tree or Balanced Binary Tree visualizer.

Worked example: building a small general tree

The same steps the visualizer animates for any input.

Insert 1: it becomes the root.
Insert 2 under 1, then 3 under 1, then 4 under 1: the root now has three children.
Insert 5 under 2: node 2 gets one child.

Preorder:    1 2 5 3 4
Postorder:   5 2 3 4 1
Level order: 1 2 3 4 5

Delete 2: its child 5 moves up, so the root's children become 5, 3, 4.

Node 1 has three children while node 2 has one. That is only possible in a general tree.

General tree traversals compared

When each node is visited relative to its children.

TraversalOrderTypical use
PreorderNode, then each child left to rightCopying a tree, printing a folder outline
PostorderEach child left to right, then the nodeDeleting a tree, adding up folder sizes
Level orderLevel by level, left to rightShortest path, printing by depth

General tree vs binary tree

How the two structures differ.

FeatureGeneral treeBinary tree
Children per nodeAny numberAt most 2
Child namesJust children, in orderLeft and right
Inorder traversalNot definedLeft, root, right
Typical useFolders, org charts, DOMSearch trees, heaps, expression trees

Nodes per general tree height

The fewest nodes, and the most when every node has k children.

HeightMinimum nodesMax (2 children)Max (3 children)Max (4 children)
11111
22345
3371321
44154085
5531121341
66633641365
7712710935461
88255328021845

General Tree FAQ

Quick answers.

How many children can a node in a general tree have?

Any number. A node can have zero, one or many children.

What is the difference between a general tree and a binary tree?

A binary tree limits each node to two children, a left and a right. A general tree has no such limit and its children are not named left or right.

What happens to the children when a node is deleted?

Delete moves them up into the deleted node's place under its parent. If you delete the root, its first child becomes the new root and the other children move under it. Delete subtree removes the node and everything below it.

What is a general tree?

A hierarchical structure with one root where every node can have any number of children. Unlike an n-ary tree, it has no maximum number of children per node.

Why is there no inorder traversal?

Inorder means left, root, right, which only makes sense when a node has at most two children. For a general tree the visualizer offers preorder, postorder and level order.

How do I add a child to a node?

Type the new value and the parent in the Target box, or click the parent in the tree, then press Insert. Leave the target empty to add under the root. The very first value becomes the root.

What are real-world examples of general trees?

File and folder systems, organization charts, HTML and XML document trees, and category or menu hierarchies.

What is the time complexity of general tree operations?

Traversal and search take O(n). Adding a child is O(1) once the parent is found, and finding the parent is O(n) in a plain general tree.

Can I undo a change?

Yes. Press Undo to step back through your last 40 changes. Clear and Random can also be undone.

Is the visualizer free and private?

Yes. It is free with no signup, and everything runs in your browser. Nothing you type is sent to a server.

More free tools from KickSolve

Other tree visualizers.