Page 105 - Computer Science V2.0 Class 11
P. 105

A teacher may be responsible for the execution of the above steps sequentially. The preceding program's steps are
                 without any ambiguity and can be easily executed by a teacher coordinating the program.

                 4.2.1 Characteristics of an Algorithm
                 ●  Inputs: Typically an algorithm requires some user input. For example, to compute the area of a rectangle, its length
                   and breadth would serve as inputs.
                 ●  Process: An algorithm often requires several steps to be executed.

                 ●  Effectiveness: Each step of an algorithm must be executable by the computer hardware or software that has been
                   developed already. For example, multiplying two numbers is an effective step for a computer, but finding the area
                   of a rectangle is not. So, we need to develop an algorithm for finding the area of a rectangle.



                       Once the algorithm to find the area of a rectangle is developed, it can be used as an effective step in another algorithm
                       that computes the area and perimeter of one of several geometric figures.


                 ● Output: the algorithm produces some output, for example, the area of a rectangle.
                 ● Finiteness: An algorithm must terminate after a certain number of steps.

                 4.2.2 Computing Simple Interest

                 The problem of computing simple interest may be described as follows:
                 Given the principal amount (say, principal), the number of years (say, time), and the rate of interest (say, rate),
                 compute the simple interest (say, interest).
                 Before developing the algorithm, let us first identify the input, process, and output:

                 ● Input: principal, rate, and time
                 ● Process: multiply principal, rate, and time and divide the result by 100
                 ● Output: simple interest
                 Now that we have identified the inputs, process, and output, it is straightforward to display the simple interest for a
                 given amount and rate of interest for a certain duration of time:

                    Input: principal, rate, and time
                    interest = (principal * rate * time)/100
                    Output: interest
                 The above algorithm may be executed by a human, or we may develop a program in a computer programming language
                 such as Python that is executed by a computer. For example, if you want your friend to execute the above algorithm for
                 you, as a first step, they will ask you for the values of principal, rate, and time. Next, they would compute
                 simple interest according to the formula:

                    (principal * rate * time)/100
                 Finally, your friend will report the result to you. As the above description of the algorithm to compute simple interest
                 does not relate to any programming language, it is called a pseudocode.
                 When the above algorithm is to be executed by a computer, we need to store the values of principal, rate, and
                 interest in the computer's memory. We associate the values stored in the computer memory with the names that
                 enable us to refer to them conveniently. The number of bytes required to store a value depends on the type of value.
                 For example, while an integer may be stored using two bytes, four bytes may be required to store a fraction such as
                 23.47.






                                                                                                     Problem Solving  91
   100   101   102   103   104   105   106   107   108   109   110