Types of trees

There are different types of trees, which are explained as follows:

  • Binary tree: If the degree of a tree is two, that tree is called a binary tree. For example, the tree shown in the following diagram is a binary tree as it has a degree of two:

Note that the preceding diagram shows a tree that has four levels with eight nodes.

  • Full tree: A full tree is the one in which all of the nodes are of the same degree, which will be equal to the degree of the tree. The following diagram shows the kinds of trees discussed earlier:

Note that the binary tree on the left is not a full tree, as node C has a degree of one and all other ...

Get 40 Algorithms Every Programmer Should Know now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.