Degenerate Tree Visualizer
A tree in which each parent has only one child, resembling a linked list. Insert, delete, edit and search with step-by-step animation.
How to use the Degenerate Tree Visualizer on KickSolve
Three quick steps, no account needed.
Why choose KickSolve
Built for learning, speed and privacy.
What you can do with the Degenerate Tree Visualizer
Everything this tool offers.
About the Degenerate Tree Visualizer on KickSolve
What it does and how to get the best results.
What is a degenerate tree?
A degenerate tree, also called a pathological tree, is a tree in which every parent has only one child. It has the shape of a linked list: each node has one child, which has one child, and so on.
Key properties
- Every parent node has exactly one child
- Only one leaf, at the bottom of the chain
- A tree with n nodes has height n
- The child can be on the left or the right at each step
Operations and time complexity
Search, insert at the end, delete and traversal all take O(n), because every operation has to walk the chain. A balanced tree does the same work in O(log n).
Why it matters
- The worst case for binary search trees
- Shows why self-balancing trees exist
- Behaves like a linked list
- Can cause deep recursion and stack overflow
Comparing tree shapes? Try the Skewed Tree, Binary Search Tree or Balanced Binary Tree visualizer.
Worked example: building a small degenerate tree
The same steps the visualizer animates for any input.
Insert 1: it becomes the root. Insert 2 on the Right: right child of 1. Insert 3 on the Left: left child of 2. Insert 4 on the Right: right child of 3. Every parent has exactly one child, but the sides are mixed. Preorder: 1 2 3 4 Inorder: 1 3 4 2 Postorder: 4 3 2 1 Level order: 1 2 3 4
The tree has 4 nodes and height 4, with one leaf. Because the sides are mixed it is degenerate but not skewed.
Degenerate Tree traversals compared
When each node is visited relative to its children.
| Traversal | Order | Typical use |
|---|---|---|
| Preorder | Root, left, right | Copying a tree, prefix expressions |
| Inorder | Left, root, right | Sorted output from a binary search tree |
| Postorder | Left, right, root | Deleting a tree, postfix expressions |
| Level order | Level by level, left to right | Shortest path, printing by depth |
Degenerate tree shapes
How the chain can lean.
| Shape | Rule | Child sides along the chain |
|---|---|---|
| Degenerate | Every parent has exactly one child | Any mix of left and right |
| Left skewed | Degenerate, and every child is a left child | Left, left, left |
| Right skewed | Degenerate, and every child is a right child | Right, right, right |
| Zig-zag | Degenerate, and the side alternates | Left, right, left |
Degenerate vs balanced height
Height grows with n instead of with log n.
| Nodes | Degenerate height | Balanced height |
|---|---|---|
| 1 | 1 | 1 |
| 3 | 3 | 2 |
| 7 | 7 | 3 |
| 15 | 15 | 4 |
| 31 | 31 | 5 |
| 63 | 63 | 6 |
| 127 | 127 | 7 |
| 255 | 255 | 8 |
| 511 | 511 | 9 |
| 1023 | 1023 | 10 |
Degenerate Tree FAQ
Quick answers.
What is a degenerate tree?
A tree in which every parent has only one child, so it looks like a linked list. It is also called a pathological tree.
What is the height of a degenerate tree with n nodes?
The height is n levels, because every node sits one level below the previous one. A balanced tree with the same nodes needs only about log2(n + 1) levels.
What is the difference between a degenerate and a skewed tree?
A skewed tree is a degenerate tree whose nodes all lean the same way, all left or all right. Every skewed tree is degenerate, but a degenerate tree that switches sides is not skewed.
Why is a degenerate tree bad for performance?
Search, insert and delete have to walk the whole chain, so they take O(n) time like a linked list instead of O(log n) in a balanced tree.
How does a tree become degenerate?
A common cause is inserting already sorted values into a binary search tree. Each new value is larger than the last, so it always goes to the same side.
How can a degenerate tree be fixed?
Use a self-balancing tree such as an AVL or red-black tree, which rotates nodes to keep the height small.
How do I build a degenerate tree in the visualizer?
The first value becomes the root. After that, choose Left or Right in Insert on side and press Insert. The new node is added below the last node of the chain, so every parent keeps a single child.
How do I delete a node in the visualizer?
Type the node or click it, then press Delete. Its child takes its place, so the chain stays unbroken.
How many leaves does a degenerate tree have?
Exactly one leaf, at the bottom of the chain. The other n - 1 nodes are internal nodes with one child each.
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.