Binary tree and BST tool
Draw a binary tree and get what ISC Computer Science asks about it: the preorder, inorder and postorder traversals, the height and levels, leaves, internal nodes, and each node's parent, children and sibling. Build it by inserting values into a binary search tree, give it level by level, or rebuild it from two traversals.
The tree
Traversals
- Preorder (root, left, right)
- 50 30 20 40 70 60 80
- Inorder (left, root, right)
- 20 30 40 50 60 70 80
- Postorder (left, right, root)
- 20 40 30 60 80 70 50
- Level order
- 50 30 70 20 40 60 80
About the tree
- Root
- 50
- Number of nodes (size)
- 7
- Height = depth (edges from the root to the deepest leaf)
- 2
- Levels (the root is at level 0)
- 3
- Leaves (external nodes)
- 20, 40, 60, 80
- Internal nodes (not the root)
- 30, 70
- Full binary tree (every node has 0 or 2 children)
- Yes
- Complete binary tree
- Yes
- Binary search tree (inorder is in order)
- Yes
Inserting, one value at a time
Each value starts at the root and goes left if smaller, right if larger, until there is a free place.
- 50: the first value is the root
- 30: 30 < 50: go left → left of 50
- 70: 70 > 50: go right → right of 50
- 20: 20 < 50: go left; 20 < 30: go left → left of 30
- 40: 40 < 50: go left; 40 > 30: go right → right of 30
- 60: 60 > 50: go right; 60 < 70: go left → left of 70
- 80: 80 > 50: go right; 80 > 70: go right → right of 70
Every node
| Node | Level | Parent | Left child | Right child | Sibling | Degree | Kind |
|---|---|---|---|---|---|---|---|
| 50 | 0 | - | 30 | 70 | - | 2 | root |
| 30 | 1 | 50 | 20 | 40 | 70 | 2 | internal |
| 70 | 1 | 50 | 60 | 80 | 30 | 2 | internal |
| 20 | 2 | 30 | - | - | 40 | 0 | leaf |
| 40 | 2 | 30 | - | - | 20 | 0 | leaf |
| 60 | 2 | 70 | - | - | 80 | 0 | leaf |
| 80 | 2 | 70 | - | - | 60 | 0 | leaf |
Practise on real ISC questions
- Answer the following questions from the diagram of a Binary Tree given below: Name the root of the left sub… 2025 Specimen
- Answer the following questions from the diagram of a Binary Tree given below: Write the post-order traversal… 2026 Improvement
- State the difference between internal nodes and external nodes of a binary tree structure. 2019
- Write the pre-order traversal of the above tree. 2026
- Write the postorder traversal of the above tree structure. 2017
- State the difference between a Binary Tree structure and a single Linked List. 2020
- Answer the following questions from the diagram of a Binary Tree given below: Write the pre-order traversal… 2023
- Write the inorder traversal of the above tree structure. 2018
- Write the post order traversal of the tree. 2020 Specimen
- Write the post-order traversal of the left subtree of the above structure. 2020
More Computer Science tools
- Boolean algebra solver Simplify any expression: the laws step by step, truth table, K-map and the logic circuit.
- Infix to postfix converter Infix to postfix or prefix with the stack table, and postfix evaluation step by step.