DEV Community

loading...
Cover image for Binary tree in data structure

Binary tree in data structure

Aya Bouchiha
Full stack web developer
Updated on ・2 min read

Hi, this the part 2 of the tree in the data structure, we're going to talk about binary tree and its famous types.

Definition of binary tree

Binary tree: is one of the most famous tree data structure which each node should have at most 2 children (left child and right child), in this type of trees, all nodes contains three items which are data, pointer to left child, pointer to right child.

Types of binary tree

Full Binary tree

  • In this type of trees, all nodes except the leaves have two children

full binary tree in data structure Aya Bouchiha

Perfect Binary tree

  • All internal nodes have exactly two children and all the leaves are at the same level.

perfect binary tree in data structure Aya Bouchiha

Degenerate binary tree

  • In This kind of tree, all nodes have only one child.

degenerate binary tree in data structure

Complete Binary tree

  • Like a full binary tree, All levels are filled, but All the leaves should lean towards the left

complete binary tree in data structure Aya Bouchiha

Balanced Binary tree

  • the absolute value of the height difference between the left and the right subtree is smaller than or equal 1. | height(left_sub_tree) - height(right_sub_tree) | <= 1

Balanced binary tree in data structure Aya Bouchiha

Skewed Binary tree

  • All nodes have only one child except the last one (leaf) which hasn't a child. It divided into two types: left skewed binary tree and right skewed binary tree

Skewed binary tree in data structure Aya Bouchiha

References and useful Resources

Discussion (0)