Page 220 - Ai_V1.0_Class9
P. 220

An algorithm uses simple English-like statements to represent the steps of a program. There may be more than
              one way to solve any problem, so there may be more than one algorithm for a given problem. It must terminate
              after a finite number of steps. Once we have an algorithm, we can translate it into a computer program in any
              programming language.




                            Brainy Fact

                   The word 'algorithm' come from the name of a Persian mathematician called Al-Khwārizmī.





              Writing an Algorithm

              Let us do an activity of writing an algorithm for making cucumber and tomato sandwich:
               Step 1   Take a few slices of tomato and a cucumber.

               Step 2   Take two slices of multigrain bread.
               Step 3   Put tomato sauce on one slice of bread.

               Step 4   Put cheese spread on the other slice of bread.
               Step 5   Place a few slices of tomato and cucumber between the two slices of bread.
               Step 6   Cut the sandwich into two halves and serve it.


              Advantages of an Algorithm
              The advantages of an algorithm are as follows:
                 • It is a step-by-step representation of a solution to a given problem.
                 • It uses simple English-like statements, so it is easy to understand and write.
                 • The  problem is broken down  into smaller pieces, hence,  it is easy to convert it into a  program  using any
                 programming language.

              Disadvantages of an Algorithm
              The disadvantages of an algorithm are as follows:
                 • There is no standard rule for writing an algorithm, it varies drastically.
                 • The process of creating an algorithm can be time-consuming.

                 • It is difficult to represent branching and looping in an algorithm.
              Let us look at some other examples of algorithms.
              1.  Input the temperature in Fahrenheit and convert it into Celsius and display it.
                 Step 1   Start
                 Step 2   Input Temp(in Fahrenheit)

                 Step 3   C=(5/9)*(Temp-32)
                 Step 4   Display C
                 Step 5   Stop

              2.  Input the radius of a circle and calculate its area.
                 Step 1   Start
                 Step 2   Input radius

                    218     Artificial Intelligence Play (Ver 1.0)-IX
   215   216   217   218   219   220   221   222   223   224   225