KEMBAR78
Representation of binary tree in memory | PPTX
Representation of Binary tree
in memory
Let T be a binary.
There are two ways for representing binary
tree in memory.

Sequential Representation
Linked Representation
Sequential Representation
   Suppose T is a complete binary tree. Then
    only single linear array TREE is used as
    follows.
   The root R is stored in TREE[0].

   If a node n occupies TREE[K],

   then its left child in TREE[2*K]

   & right child TREE [2*K+1].

   If TREE[1]=NULL then it is empty
    tree.
Linked Representation
   The linked representation uses three parallel
    arrays,INFO,LEFT & RIGHT & a pointer variable
    ROOT.Each node N of Y will correspond to a location K
    such that:

   1) INFO[K] contains the data at node N.

   2) LEFT[K] contains the location of left child of node N.

   3) RIGHT[K] contains the location of right child of node
    N.

   ROOT will contain location of root R of T.
A sample representation is shown
in fig.

Representation of binary tree in memory

  • 1.
    Representation of Binarytree in memory Let T be a binary. There are two ways for representing binary tree in memory. Sequential Representation Linked Representation
  • 2.
    Sequential Representation  Suppose T is a complete binary tree. Then only single linear array TREE is used as follows.
  • 3.
    The root R is stored in TREE[0].  If a node n occupies TREE[K],  then its left child in TREE[2*K]  & right child TREE [2*K+1].  If TREE[1]=NULL then it is empty tree.
  • 7.
    Linked Representation  The linked representation uses three parallel arrays,INFO,LEFT & RIGHT & a pointer variable ROOT.Each node N of Y will correspond to a location K such that:  1) INFO[K] contains the data at node N.  2) LEFT[K] contains the location of left child of node N.  3) RIGHT[K] contains the location of right child of node N.  ROOT will contain location of root R of T.
  • 8.
    A sample representationis shown in fig.