Page 46 - CT_AI_Class-5
P. 46

Step 4   Multiply the number by the counter.
                                                                                                                                                        The Withings Smart Scale tracks weight, body fat, muscle,
                  Step 5   Say or write the answer.                                                                                                      and bone, syncing with your phone to monitor health and

                  Step 6   Increase the counter by 1.                                                                                          ai         display progress. It recognises up to 8 family members
                                                                                                                                                                           and offers health tips.
                  Step 7   Repeat steps 4–6 until the counter reaches 10.                                                                         lens

                  Step 8   End
                                                                                                                                            DEBUGGING SIMPLE PROBLEMS
                  Comparison of The Three Types of Flow
                                                                                                                                            Sometimes, algorithms do not give the expected results. This may happen because
                  Here is a comparison of the three types of flow:
                                                                                                                                            of mistakes in the algorithm. These mistakes are called bugs. Finding and correcting

                      Type of Flow                   What It Does                       Real-Life Example                                   these mistakes is called debugging.

                        Sequence           Steps happen one by one in a  Making hot chocolate, each                                         Common Causes of Bugs
                                           fixed order with no choices or  step follows the last.
                                           repeats.                                                                                         Bugs happen for many reasons. Here are the most common ones:

                        Selection          A YES/NO question is asked             Deciding what to wear,                                      A step is missing from the algorithm.
                                           and the algorithm chooses a            the choice depends on the                                   Steps are written in the wrong order.
                                           path based on the answer.              weather.
                                                                                                                                              A decision has the wrong condition (e.g., YES and NO are swapped).
                        Repetition         A group of steps is repeated           Practising multiplication
                                           again and again until a                tables, keep repeating until                                The instructions are not clear.
                                           condition is met.                      all 10 are done.                                          Example:

                                                                                                                                            Wrong Algorithm for Drinking Milk:                            Correct Algorithm:
                                                                                                21 st
                                                                                              Century   #Critical Thinking                  1.  Drink milk.                                               1.  Pour milk into a glass.
                                                                                               Skills
                                                        concept capsule
                                                                                                                                            2.  Pour milk into glass.                                     2.  Drink the milk.
                       Write the signal that each colour of the traffic light gives:

                                                                                                                                                                                        Ask
                                                                                                                                                                                                  AGENT
                                                                                                                                                                                   OrangeAI
                                                                                                                                              Find out when the term bug was first used to mean a mistake.
                                                                                      Red
                                                                                                                                                      Study

                                             Yellow
                                                                                                                                            How to Debug: The Three-Step Method

                                                                                     Green                                                  Here is a simple three-step method for debugging any algorithm:

                                                                                                                                            1.   READ: Read  every step  carefully, as  if you  are  a  robot  following instructions
                                                                                                                                                for the first time.
                       Choose the correct type of flow of algorithm is used by traffic lights.
                                                                                                                                            2.  TRACE: Follow  the steps  on paper  and write down what would happen at
                             a)  Sequence                      b)  Selection                  c)  Repetition                                    each stage.


                                                                                                                                            3.  FIX: Once you find the mistake, correct it and test the algorithm again.




                  44         Artificial Intelligence (CT & AI)-V
   41   42   43   44   45   46   47   48   49   50   51