Page 8 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 8

Unit 1: Introduction to Data Structure and Arrays





          In operation definition, there are three parts:                                        Notes
          1.   Function
          2.   Precondition
          3.   Postcondition

          The function clause defines the role of the operation. If we consider the addition operation in
          integers the function clause will state that two integers can be added using this function. In

          general, precondition specifies any restrictions that must be satisfied before the operation can

          be applied. This clause is optional. If we consider the division operation on integers then the
          precondition will state that the divisor should not be zero. So any call for divide operation, which
          does not satisfy this condition, will not give the desired output.
          Precondition specifies any condition that may apply as a pre-requisite for the operation defi nition.


          There are certain operations that can be carried out if certain conditions are satisfied. For example,
          in case of division operation the divisor should never be equal to zero. Only if this condition is
          satisfied the division operation is carried out. Hence, this becomes a precondition. In that case &

          (ampersand) should be mentioned in the operation defi nition.

          Postcondition specifies what the operation does. One can say that it specifies the state after the

          operation is performed. In the addition operation, the post condition will give the addition of the
          two integers.
                                     Figure 1.1: Components of ADT
                                            ADT



                    Value Definition                       Operation Definition




            Definition Clause  Condition Clause    Function   Precondition  Postcondition

          As an example, let us consider the representation of integer data type as an ADT. We will consider
          only two operations addition and division.

          Value Defi nition

          1.   Defi nition  clause: The values must be in between the minimum and maximum values

               specified for the particular computer.
          2.   Condition clause: Values should not include decimal point.

          Operations

          1.   add (a, b)
               Function: add the two integers a and b.

               Precondition: no precondition.
               Postcondition: output = a + b









                                           LOVELY PROFESSIONAL UNIVERSITY                                     3
   3   4   5   6   7   8   9   10   11   12   13