books in school bag, finding shortest path to search a place, scheduling day-to-day activities, preparation for examination, etc. As we know that all programming languages share basic code constructs like conditions and iterations can be used to write an algorithm. A typical algorithm is shown in the following Figure . .
Input Process Output A Typical Algorithm Example Consider the example of Coffee preparation. To make coffee, we need to have the following ingredients: Water, milk, coffee powder and sugar. These ingredients are the inputs of an algorithm. Preparing a cup of coffee is called process.
The output of this process is coffee. The procedure for preparing coffee is as follows: . Take a bowl with coffee powder . Boil the water and pour it into the bowl 12th Computer Chapter - - Algorithmic Strategies .
Filter it . Boil milk . Mix sugar and filtered coffee along with boiled milk . Pour the coffee into the cup to serve This kind of procedure can be represented using an algorithm.
Thus, the algorithm consists of step-step-by instructions that are required to accomplish a task and helps the programmer to develop the program. Problem: Design an algorithm to find square of the given number and display the result. The algorithm can be written as: Step – start the process Step – get the input x Step –calculate the square by multiplying the input value ie., square ← x* x Step − display the result square Step − stop Algorithm could be designed to get a solution of a given problem. A problem can be solved in many ways.
Among many algorithms the optimistic one can be taken for implementation. An algorithm that yields expected output for a valid input is called an algorithmic solution. Algorithm Program • Algorithm helps to solve a given problem logically and it can be contrasted with the program • Program is an expression of algorithm in a programming language • Algorithm can be categorized based on their implementation methods, design techniques etc • Algorithm can be implemented by