Algorithm

Introduction

An algorithm is a method or process to solve a problem. In other words, an algorithm is a set of steps required to solve a problem. If algorithms written in English like sentences, then it is called Pseudo Code.

Program design process has two phases:

1. Problem Solving: Creates an algorithm that solves the problem.
2. Implementation: Translates the algorithm into programming language/machine language.

Algorithm Properties

1. Input: It is a set of values as input data.
2. Output: This is the result of the program.
3. Finiteness: Must terminate in the countable number of steps.
4. Definiteness: Each step of an algorithm must be stated clearly.
5. Effectiveness: Each step of an algorithm must be convertible into program statements.

Example 1
Write an algorithm to calculate the sum of two numbers.

Solution
Step 1: Start the program.
Step 2: Read two integer numbers and store them in num1 and num2.
Step 3: Compute sum = num1 + num2
Step 4: Print sum value.
Step 5: Stop the program.

Example 2
Write an algorithm to calculate the sum and the average of three numbers.

Solution
Step 1: Start the program.
Step 2: Read three integer numbers and store them in num1, num2 and num3.
Step 3: Compute sum = num1 + num2 + num3
Step 4: Print sum value.
Step 5: Compute average = sum / 3
Step 6: Print average value.
Step 7: Stop the program.

Algorithm advantages and disadvantages

Advantages
1. Very easy to write.
2. Easy technique to understand the logic.
3. Easy identification of the mistakes/errors by non-computer person.

Disadvantages
1. Time-consuming.
2. Difficult to branching and looping.
3. Big tasks are difficult to put in the algorithm.



Post a Comment

0 Comments