Professional Documents
Culture Documents
Binary Tree
Binary Tree
Trees are one of the most fundamental data structures. They are used to store
and organize data.
A binary tree is a tree data structure composed of nodes, each of which has at
most, two children, referred to as left and right nodes. The tree starts off with a
single node known as the root.
1. Data
2. Pointer to the left child
3. Pointer to the right child
In case of a leaf node, the pointers to the left and right child point to null.
https://www.educative.io/answers/what-is-a-binary-tree 1/6
10/18/22, 7:20 PM What is a Binary Tree?
Parent
22 10
Left Child Right Child
Common operations
Following is a list of common operations that can be performed on a binary
tree:
1. Insertion
Elements may be inserted into a binary tree in any order. The very first
insertion operation creates the root node. Each insertion that follows iteratively
searches for an empty location at each level of the tree.
Upon finding an empty left or right child, the new element is inserted. By
convention, the insertion always begins from the left child node.
2 2
20 13 7 13 7
Inserting 20
9 9 20
https://www.educative.io/answers/what-is-a-binary-tree 2/6
10/18/22, 7:20 PM What is a Binary Tree?
2. Deletion
An element may also be removed from the binary tree. Since there is no
particular order among the elements, upon deletion of a particular node, it is
replaced with the right-most element.
Let’s look at an example to get a better idea of how the deletion process works.
2 2
13 13 7 1 7
Deleting 13
9 21 1 9 21
Binary trees are one of the most efficient and frequently used data structures.
They represent structural relationships in data and are used to represent
hierarchies.
3. Tree traversal
Another frequently used tree operation is traversal. Tree traversal is the
process of visiting each node present in a tree. There are three methods of tree
traversal:
1. In-order traversal
2. Post-order traversal
3. Pre-order traversal
https://www.educative.io/answers/what-is-a-binary-tree 3/6