Everything about Binary tree in Data Structure

0
1328
binary tree

A binary tree is either blank or it is a root node together with two subtrees, the left-side subtree, and the right-side subtree, every subtree is a binary tree. The binary tree is incomplete if each level, except the last, includes as many nodes as possible. Therefore a binary tree is complete if each level holds as many nodes as possible. Binary trees have the following three unique characteristics:

binary tree
  • Each node has at most two subtrees.
  • Each subtree is known as either the left-subtree or the right-subtree of the parent.
  • A binary tree may be empty.

The example of the above confers a binary tree diagram that is a full binary tree. The following example gives a complete binary tree.

Why binary trees?

These binary trees are used to store data in hierarchical order. and quickly used for insertion and deletion operation as compared to the array and linked list. One important thing, it is based on the nonlinear data structure.

We can insert any data at any required place because the size is dynamic. Now come to the performance, it’s faster when used in the linked list and slower when used arrays.

Types of binary tree

We can divide the binary tree as follows.

  1. Complete binary tree: All the levels are fully filled except possibly the end level and the nodes in the end level areas left as possible.
  2. Perfect binary tree: It’s the same as a full binary tree, it has all the nodes 2 child node other than the leaf nodes.
  3. Full binary tree: Every, node of a binary tree node should have either 0 and 2 child nodes.

Application of binary tree

It is a node-based binary tree data structure which has the following properties:

  • The left subtree of a node includes only nodes with keys less than the node’s key.
  • The right subtree of a node includes only nodes with keys greater than the node’s key.
  • The left and right subtree individual must also be a binary search tree.
  • its must be no duplicate nodes.
  • Binary Search Tree – Used in various search applications where data is continually leaving/joining, such as the map furthermore set objects in many languages’ libraries.
  • Binary Space Partition – Used in nearly every 3D video game to discover what objects want to be rendered.
  • Binary Tries – Used in almost every high-bandwidth router for collecting router-tables.
  • Hash Trees – used in p2p program code and trained image-signatures in which a hash needs to be confirmed, but the whole file is not available.
  • Heaps – Used in performing active priority-queues, which in turn are used …

Conclusion

A binary tree can be used for binary search and it has a variety of trees like binary search tree, binary space partition and has a tree, etc

We can use a nonlinear data structure for fast traversal and implement up-dating very fast compared to a linear data structure.