Page 203 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 203

Fundamentals of Data Structures




                    Notes            }
                                    else
                                     {
                                      if(curr->right != NULL)
                                        create_tree(curr->right, new);
                                      else
                                        curr->right = new;
                                     }
                                   }

                                   12.2.2 Binary Tree Representation

                                   There are two ways by which we can represent a binary tree.

                                       Array representation of a binary tree
                                       Linked representation of a binary tree
                                   These are explained below:

                                   Array representation of binary trees

                                   When a binary tree is represented by arrays three separate arrays are required. One array stores
                                   the data fields of the trees. The other two arrays represents the left child and right child of the
                                   nodes.
                                   Consider the binary tree given below:

                                                               Figure 12.3: Binary Tree

                                                                                 1

                                                         2                       3               4

                                              5          6          7       8    9    10   11   12    13


                                          14  15 16  17  18 19  20  21
                                   Source:  http://www.ustudy.in/node/7015

                                   Now the Array representation of this binary tree is given below:
                                            Figure 12.4: Array Representation of the Binary Tree given in Figure 12.3












                                       1      2        3       4       5       6        7       8       9      10111213     14    15     16    17    18    19    20     21


                                   Source:  http://www.ustudy.in/node/7015




          196                               LOVELY PROFESSIONAL UNIVERSITY
   198   199   200   201   202   203   204   205   206   207   208