Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 48 - CT_AI_Class-5
P. 48

    A Buggy Algorithm Spot the Problem                                                                                        ALGORITHM IN REAL-LIFE

                                                                                                                                                As you now understand what algorithms are, you might be surprised to know how
                                                 Step                    Action
                                                                                                                                                many algorithms you encounter every single day.
                                                   1      Put bread in the toaster
                                                   2      Take the toast out of the toaster                                                     Here are a few examples of algorithm in real-life:

                                                   3      Turn the toaster on                                                                   Example 1: ATM Machine

                                                   4      Spread butter on the toast                                                            When you use an Automatic Teller Machine (ATM) to withdraw money, the ATM
                                                   5      Eat the toast                                                                         follows a specific algorithm to verify your identity and check that you have enough
                                                                                                                                                money in your account. Here is the simplified algorithm an ATM follows:
                      Solution: Step 2 and Step 3 are in the wrong order. You should turn the toaster ON                                         Step 1   User inserts debit card.
                      before you take the bread out. The corrected order should be: 1 → 3 → 2 → 4 → 5.
                                                                                                                                                 Step 2   ATM asks for PIN (secret number).
                      Testing Your Algorithm
                                                                                                                                                 Step 3   Is PIN correct?
                      After fixing a bug, one should always test  his algorithm  again.  Testing means                                                    If NO: Show error and eject card.
                      checking that the algorithm works correctly with different situations and giving the
                      expected result.                                                                                                                    If YES: Continue.

                                                                                                                                                 Step 4   User selects amount to withdraw.
                                                                                                      21 st
                                                                                                     Century   #Critical Thinking                Step 5   Is enough money in account?
                                                         FINDING THE BUG AND FIXING                   Skills

                                                                  THE ALGORITHM                                                                           If NO: Show error.

                         A robot chef tried to make a sandwich for Kavya, but something went wrong. The sandwich                                          If YES: Dispense cash.
                        was not made properly because the steps were not in the correct order. Can you find the bug?                             Step 6   Print receipt and eject card.

                        Here is the algorithm given to the robot:
                          1.  Get two slices of bread from the bag              2.  Eat the sandwich
                                                                                                                                                                                  Example 2: Search Engine
                          3.  Open the refrigerator                             4.  Take out the cheese and tomato

                          5.  Close the refrigerator                           6.  Put one slice of bread on the plate                                                            When  you  search  something  on  a  search engine
                                                                                                                                                                                  like Google, it uses a smart set of steps to find useful
                          7.  Put the cheese on the bread                      8.  Put the sliced tomato on the cheese
                                                                                                                                                                                  information  for you.  It  looks  at  your  search words,
                          9.  Place the second slice of bread on top          10.  Cut the tomato in slices
                                                                                                                                                                                  related popular pages and past searches. It gives you
                        The bug is found and after fixing the steps, kavya finally got her tasty sandwich.
                                                                                                                                                                                  results in just a second.
                        Based on the above case, answer the following questions:

                        1.  What was the bug in the algorithm?
                                                                                                                                                Example 3: Traffic Lights

                                                                                                                                                Traffic lights  also  follow an algorithm.  They systematically
                        2.   Why is it important to follow the correct order of steps in an algorithm?                                          change from red to yellow to green in a fixed order and stay on

                                                                                                                                                for a certain time. Even in busy cities, more advanced algorithms

                      46         Artificial Intelligence (CT & AI)-V

| 43 44 45 46 47 48 49 50 51 52 53 |