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)
- MANGO BANANA APPLE PEAR ORANGE
- Inorder (left, root, right)
- APPLE BANANA MANGO ORANGE PEAR
- Postorder (left, right, root)
- APPLE BANANA ORANGE PEAR MANGO
- Level order
- MANGO BANANA PEAR APPLE ORANGE
About the tree
- Root
- MANGO
- Number of nodes (size)
- 5
- Height = depth (edges from the root to the deepest leaf)
- 2
- Levels (the root is at level 0)
- 3
- Leaves (external nodes)
- APPLE, ORANGE
- Internal nodes (not the root)
- BANANA, PEAR
- Full binary tree (every node has 0 or 2 children)
- No
- Complete binary tree
- No
- 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.
- MANGO: the first value is the root
- BANANA: BANANA < MANGO: go left → left of MANGO
- PEAR: PEAR > MANGO: go right → right of MANGO
- APPLE: APPLE < MANGO: go left; APPLE < BANANA: go left → left of BANANA
- ORANGE: ORANGE > MANGO: go right; ORANGE < PEAR: go left → left of PEAR
Every node
| Node | Level | Parent | Left child | Right child | Sibling | Degree | Kind |
|---|---|---|---|---|---|---|---|
| MANGO | 0 | - | BANANA | PEAR | - | 2 | root |
| BANANA | 1 | MANGO | APPLE | - | PEAR | 1 | internal |
| PEAR | 1 | MANGO | ORANGE | - | BANANA | 1 | internal |
| APPLE | 2 | BANANA | - | - | - | 0 | leaf |
| ORANGE | 2 | PEAR | - | - | - | 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.