Sunday 28 July 2013

Binary Tree representation using Array:

a Binary Tree T can be represented by Array in 2 different way;
  1. Sequential representation (via singular linear array)
  2. Linked representation


Sequential representation:
if T is a complete Binary tree, then its-
  • root R will be stored in array element T[0]
  • if K number of node occupies, will be stored in array element T[K]
  • left child will be stored in array element T[ 2*K ]
  • right child will be stored in array element T [ 2*K+1 ]
** if T[ 1 ] = NULL, then it is an empty Tree.


diagrammatic explanation:










Linked representation:
if K is the correspond  location pointer :
  • need 3 parallel array INFO, LEFT and RIGHT
  • data at node will be stored in array element INFO[K]
  • location of left child of node N will be stored in array element LEFT[ K ]
  • location of right child of node N will be stored in array element RIGHT [ K ]
  • root R of T will be stored in ROOT
diagrammatic explanation:





No comments:

Post a Comment