Page 41 - Trackpad_ipro 4.1_Class8
P. 41

CHARACTERISTICS OF A GOOD ALGORITHM

                 The main characteristics of a good algorithm are:

                    Precision: Each step is precisely defined.
                    Uniqueness: The result of each step can be uniquely identified and only depends on the
                    result of the preceding step.

                    Finiteness: It stops after a finite number of instructions are executed.
                    Well-Defined Input: The input to an algorithm must be clearly specified and precisely defined.

                    Well-Defined Output: The output produced by the algorithm must also be clearly specified
                    and precisely defined.

                    Effectiveness: The algorithm should be efficient in terms of time and space.
                     USES OF AN ALGORITHM


                 Algorithm is commonly used for:
                    Performing data processing
                    Performing logical and mathematical operations

                    Manipulating data
                    Searching for a particular data

                     WRITING AN ALGORITHM

                 The  construction  of  an  algorithm  involves  creative  thinking  and  finding  the  best  possible
                 combination of steps to get the desired result. For example,

                 A.  Algorithm to find product, sum, and difference of two numbers A and B.
                    Step 1  Start.

                    Step 2  Read two numbers and store them in A and B.
                    Step 3  Multiply the two numbers A and B and store the result in Product.
                    Step 4  Print the product.

                    Step 5  Add the two numbers A and B and store the result in Sum.
                    Step 6  Print the sum.
                    Step 7  Subtract number B from number A store the result in Difference.
                    Step 8  Print the Difference.

                    Step 9  Stop.

                 B.  Algorithm to compare two numbers A and B.
                    Step 1  Start.
                    Step 2  Read two numbers and store them in A and B.

                    Step 3  Compare the numbers A and B.
                    Step 4  If A is less than B, print "A is smaller" and go to Step 7.
                    Step 5  If B is less than A, print "B is smaller" and go to Step 7.



                                                                                     Algorithms and Flowcharts   39
   36   37   38   39   40   41   42   43   44   45   46