Algorithms & Pseudo-Code” An algorithm is a step-by-step procedure to solve a problem. The process of solving a program becomes simpler and easier with the help of an algorithm. It is better it write algorithm before writing the actual computer program.
Properties of Algorithm:
1: The given problem should be broken down into simple and meaningful steps.
2: The steps should be numbered sequentially.
3: The steps should be descriptive and written in simple English.
The algorithm is written in pseudo-language that is similar to simple English. Pseudocode is used to specify program logic that is independent of any specific programming language. It simplifies program development by separating it into logic design and coding.
1: Logic Design:itwords.org
In this part, the logic of the program is designed. The logic design specifies the different steps required to solve the problem as well as the sequence of these steps. The use of pseudocode allows the programmer to focus on planning the logic of the program.
In this part, the algorithm is converted into a program. The steps of the algorithm are translated into the instruction of any programming language.
The following algorithm inputs two numbers calculate the sum and then displays the result on the screen.
1: Start 2: Input A 3: Input B 4: Total= A + B 5: Display Total 6: Exit
The following algorithm calculates the area of a circle when the radius is given.
1: Start 2: Input radius in r 3: Area = 3.14* r *r 4: Print area 5: End
The following algorithm finds the sum of the first fifty natural numbers.
1: Start 2: Sum = 0 3: N = 0 4: Repeat Step 5 and 6 While (N<=50) 5: Sum = Sum + N
6: N= N + 7: Print sum 8: End
Advantages of Algorithms Some advantages of an algorithm are as follows:
1: Reduced Complexity:
Writing algorithm and program separately simplifies the overall task by dividing it into two simpler tasks. While writing the algorithm, we can focus on solving the problem instead of concentrating on a particular language.
2: Increased Flexibility:
The algorithm is written so that the code may be written in any language. Using the algorithm, the problem could be written in Visual Basic, Java or C++, etc.