Binary Trees (Data Structure)

Binary Trees (Data Structure)

Hi there 👋. If you're reading this, you're in the right place. Thank you for stopping by!

What is binary tree:

Binary tree is the one of the nonlinear data structures. to understand the concept of binary tree we have to understand the following terms:

1-Root: this is the first node is the tree.

2-Parent: this is the father node for any child nodes look at the picture above.

3-Child: this is referring to any node that derived from other parent node.

4-leaf: any child node that hasn't any node derived from it.

5-siblings: if we have a parent node that derived into 2 node one on the left and the other on the right, so both of the right and left children are called siblings as a group.

6-Ancestor: to understand this term look at the below diagram👇.

if we want to reach the node "M" so we have to talk a pathway starting with the root "P" the node "R", node "C" and finally we reach the node "M", so the nodes with yellow background ("P", "R", "C") are called ancestors to the node "M".

7-Subtree: to understand this term look and the below diagram.

all the branches nested in the yellow bordered boxes are called subtree.

8-Depth of a node: to understand that term you have to imagine that each branch below the root is called level and the number of levels you have to pass through to reach the target node is called the depth.

for example: to get the depth of the node "H" we have to start with root node located in level 0, then go to node "R" located in level 1, then the node "C" located in level 2, then node "M" located in level 3, and finally reach the node "H" located in level 4. So, the number of levels to reach node "H" equal the depth equal 4.

9-Height of a node: this is equal to how many levels below the node, for example the height if each leaf node equal to 0, another example: the height of node "R" equal 3.

10-edges: this is equal to total number if nodes -1.

Main Operations for the binary tree:

1- Insert

2- Delete

3- Search

4- Traversal