Binary Tree

Definition:


binary tree   T is a finite set of nodes  with the following properties:
  1. Either the set is empty, tex2html_wrap_inline62586; or
  2. The set consists of a root, r, and exactly two distinct binary trees tex2html_wrap_inline62742 and tex2html_wrap_inline62744tex2html_wrap_inline62746.
  • The tree tex2html_wrap_inline62742 is called the left subtree  of T, and the tree tex2html_wrap_inline62744 is called the right subtree  of T.
  • They are considered as Ordered subtrees.

  • Level i has  2i  nodes.
In a tree of height h,
  • Leaves are level at h.
  • No of leave are  2h.
  • No of internal nodes 2h    -1.
  • No of internal nodes = no of leaves -1
  • Total no of nodes = 2h+1  -1 =n

In a tree on n nodes 
  • No of leaves is (n+1)/2
  • height =   Log2(n+1)/2

Tree Traversal

  1. PostOrder Traversal
  2. PreOrder  Traversal
  3. InOrder  Traversal

PostOrder Traversal :  In post order tree walks process each node after processing its children.

PreOrder traversal : In preorder tree walk processes each  node before processing its children.

Inorder Traversal :  Besides preorder and postorder , a third possibilities arises when node is visited between visit to  left and right sub tree.



PostOrder : C,B,F ,G E,I,H,D,A

PreOrder : A,B,C,D,E,F,G,H,I

InOrder :B,C,A,F,E,G,D,I,H


Comments

Popular posts from this blog

JDBC Hive Connection fails : Unable to read HiveServer2 uri from ZooKeeper

Access Kubernetes ConfigMap in Spring Boot Application

Developing Custom Processor in Apache Nifi