Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 42 - CT_AI_Class-5
P. 42

    WRITING SIMPLE ALGORITHMS                                                                                                  Step 6   Add ice cubes if desired.

                      Writing an algorithm means breaking a task into simple steps. While writing an                                             Step 7   End
                      algorithm make sure that anyone, even someone who has never  done the task

                      before, can follow your steps and get the right result. It is important to be clear and                                   LOGICAL THINKING AND DECISION MAKING
                      precise to avoid confusion or errors. Let's learn how to do this well.
                                                                                                                                                Logical thinking is when you make decisions based on facts and rules, not feelings
                                                   Writing Simple Algorithms                                                                    or guesses. While solving a maths problem or following a set of rules in a game,

                                                                                                                                                logical thinking is always used.
                                                                       Understand the problem
                                                                                                                                                Example:
                                                                       Before  you  write  a single step,  ask                                    Not logical (feelings/guess): "I think it will rain because I feel sad today."
                                                                       yourself: What is the goal? What do
                                                   Step 1
                                                                       I start with? What should happen at                                        Logical (facts/rules): "The weather app says 80% rain and dark clouds are in the
                                                                       the end?                                                                     sky. So, I will take an umbrella.”

                                                                                                                                                One of the  most  important  elements  in algorithmic  thinking  is  the  decision.
                                                                                                                                                Sometimes, you need to choose between options. This is called decision making.

                                                                                                                                                For example, deciding what to wear.
                       Break the task into small steps                         Step 2
                                                                                                                                                  If it is raining → Wear a raincoat.
                       Once you understand the problem,
                       break the process into the smallest                                                                                        If it is sunny → Wear light clothes.

                       possible steps.                                                                                                          These are called  conditions (if–then statements).  Conditions are used  to  make
                                                                                                                                                decisions  based  on specific  situations.  They  help in deciding  the  action  to  take

                                                   Step 3                     Check your steps                                                  depending on whether the condition is true or false.

                                                                              Read your own steps as if you have never                          Algorithm:
                                                                              seen them before  to  spot  gaps.  Have                            Step 1   Start
                                                                              someone  else follow  your instructions
                                                                              exactly. If they stumble, your instructions                        Step 2   Check if it is raining

                                                                              need more clarity.                                                 Step 3   If YES → Take an umbrella

                      For example, making a glass of lemonade.                                                                                   Step 4   If NO → Do not take an umbrella

                      Algorithm:                                                                                                                 Step 5   End

                      Step 1   Start

                      Step 2   Squeeze two lemons into a jug.
                                                                                                                                                                   If P stands for ‘+’, Q stands for ‘-’, R stands for ‘x’ and S stands for ‘÷’ then
                      Step 3   Add two cups of water to the jug.
                                                                                                                                                                   18 R 14 P 6 Q 16 S 4 is                .
                      Step 4    Mix in three teaspoons of sugar and
                                                                                                                                                                         a)  252                                            b)  253
                                stir well.

                      Step 5   Pour the lemonade into a glass.                                                                                                           c)  254                                            d)  256

                      40         Artificial Intelligence (CT & AI)-V

| 37 38 39 40 41 42 43 44 45 46 47 |