Binary Tree






A binary tree is made of nodes, where each node contains a "left" pointer, a "right" pointer, and a data element. The "root" pointer points to the topmost node in the tree. The left and right pointers recursively point to smaller "subtrees" on either side. A null pointer represents a binary tree with no elements -- the empty tree. The formal recursive definition is: a binary tree is either empty (represented by a null pointer), or is made of a single node, where the left and right pointers (recursive definition ahead) each point to a binary tree.


What is a Binary Tree
   
   A "binary search tree" (BST) or "ordered binary tree" is a type of binary tree where the nodes are arranged in order: for each node, all elements in its left subtree are less-or-equal to the node (<=), and all the elements in its right subtree are greater than the node (>). 

Types of binary tree

  • full binary tree which is also called as proper binary tree or 2-tree is a tree in which all the node other than the leaves has exact two children.
  • Full Binary Tree
  • complete binary tree is a binary tree in which at every level, except possibly the last, has to be filled and all nodes are as far left as possible.
  • Complete Binary Tree
  • A binary tree can be converted into an extended binary tree by adding new nodes to its leaf nodes and to the nodes that have only one child. These new nodes are added in such a way that all the nodes in the resultant tree have either zero or two children. It is also called 2 - tree
  • The threaded Binary tree is the tree which is represented using pointers the empty subtrees are set to NULL, i.e. 'left' pointer of the node whose left child is empty subtree is normally set to NULL. These large numbers of pointer sets are used in different ways.

Advantages of binary tree :
  • It enables linear traversal of elements in the tree
  • Linear traversal eliminates the use of stacks which in turn consume a lot of memory space and computer time
  • It enables to find the parent of a given element without explicit use of parent pointers
  • Since nodes contain pointers to in-order predecessor and successor, the threaded tree enables forward and backward traversal of the nodes as given by in-order fashion

Comments

Popular posts from this blog

AVL Tree & B Tree

Data Structure Summary