Page 24 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 24

Unit 1: Introduction to Data Structure and Arrays




                                                                                                Notes
                                       LB                   UB
                                         2                    2
                                   LB
                                     1
                               i th  Row  A(i, LB )  .......
                                           2        A(l, j)



                                  UB
                                     1

          If we want to calculate the number of elements till Ist Row then.
                No. of elements = (UB  – LB  + 1) * (1 – 1 + 1)
                                  2   2
          or    No. of elements = UB  – LB  + 1                                   …(6)
                                 2    2
          No. of elements in (j – 1) Rows = (j – 1) (UB  – LB  + 1). If s be the size of data types of Array
                                              2
                                                   2
          elements then memory space required for storing i-1 Rows will be.
                Space Required = (UB  – LB  + 1) (i – 1)*s                        …(7)
                                  2   2
          If x be the address of A[LB , LB ] then Address of A(i, LB ) will be:
                               1   2                   2
                         Add = x + (UB  – LB  + 1) (i-1)*s                        …(8)
                                     2   2
          Address of A[i, j] will be
               Address of A[i, j] = x + [(UB  – LB  + 1) (i – 1) + (j – 1)]*s     …(9)
                                     2    2
          This is Address Scheme for Row Major form. For Column Major form
               Address of A[i, j] = x + [(UB  – LB  + 1) (j – 1) + (i – 1)]*s    …(10)
                                     1    1
                                        1      2       3     4
                                     1

                                     2
                                A =
                                     3

                                     4


          Consider a two-dimensional matrix of  figure. Suppose address of A11 is 2000 and this two

          dimensional array contains elements of 4-bytes each we want to calculate the address of A23,
          then by the formula (9) we have
                            _ = 2000,
                          UB  = 4, LB  = 1
                             2     2
                             i = 2, j = 3,
          and               s = 4
          then

                 add. of A23 = 2000 + [(4 – 1 + 1) (2 – 1) + (3 – 1)]*4 = 2024





                                           LOVELY PROFESSIONAL UNIVERSITY                                    19
   19   20   21   22   23   24   25   26   27   28   29