ALGORITHMS ALGORITHM ► The sequence of steps to be performed in order to solve a problem by the computer. ► a process that performs some sequence of operations in order to solve a given problem ► a set of well-defined instructions to solve a particular problem. ► a set of step-by-step procedures, or a set of rules to follow, for completing a specific task or solving a particular problem. QUALITIES OF A GOOD ALGORITHM ► Input and output should be defined precisely. ► Each step in the algorithm should be clear and unambiguous. ► Algorithms should be most effective among many different ways to solve a problem. ► An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages. Example of an Algorithm ► Algorithm of baking a cake: 1. Preheat the oven 2. Gather the ingredients 3. Measure out the ingredients 4. Mix together the ingredients to make the batter 5. Grease a pan 6. Pour the batter into the pan 7. Put the pan in the oven 8. Set a timer 9. When the timer goes off, take the pan out of the oven Example of an Algorithm ► Algorithm of a friend arriving at a railway station: ❖Possible of 3 algorithms ▪ Taxi algorithm ▪ Call me algorithm ▪ The bus algorithm PSEUDOCODE Pseudocode ► a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled natural language rather than in a programming language. Pseudocode is sometimes used as a detailed step in the process of developing a program. ► an informal way of programming description that does not require any strict programming language syntax or underlying technology considerations. ► used for creating an outline or a rough draft of a program ► one of the methods which can be used to represent an algorithm for a program. It does not have a specific syntax like any of the programming languages and thus cannot be executed on a computer. ► a plain-text description of a piece of code or an algorithm ► not written in any particular programming language. It's written in plain English that is clear and easy to understand Note: Pseudocode is not an actual programming language. Example of a Pseudocode ► Pseudocode of in getting the average of grades Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total endwhile Set the class average to the total divided by ten Print the class average.