ALGORITHMS
INTRODUCTION
Algorithms are one of the most basic tools that are used to develop the problem the problem solving logic.
“An algorithm is defined as finite sequence of explicit instructions that, when provided with a set of input values produces an output and then terminates.”
In algorithm, after a finite number of steps, a solution of the problem is achieved. Algorithm can have steps that repeat (iterate) or require decisions (logic and comparison) until task is completed.
Different algorithms may accomplish the same task, with a different set of instructions, in more or less the same time, space and efforts.
CHARACTERISTICS OF ALGORITHMS
Algorithms are not computer programs, as they cannot be executed by a computer
In order to qualify as a good algorithm, it must posses he following characteristics:
1. Each and every instruction in an algorithm should be precise and unambiguous.
2. The instruction in an algorithm should not be repeated infinitely.
3. It should ultimately terminate.
4. Algorithms are written in sequence.
5. Algorithms look like normal English.
6. The desired result should be obtained only after the algorithm terminates.
QUALITIES OF A GOOD ALGORITHM
There are so many methods are logics available to solve the problem individually. All of those methods and logics may be good, for given problem there may be so many algorithms not of all equality.
The following are the primary factors that are often used to judge the quality of algorithms:
S.No. | Factors | Quality of good Algorithm |
1. | Time | To execute a program, the computer system takes some amount of time. The lesser the time taken, the better the algorithm is. |
2. | Memory | To execute a program, computer system takes some amount of memory storage. The lesser the memory required the better the algorithm is. |
3. | Accuracy | Multiple algorithms may provide suitable or correct solutions to a given problem, some of these may provide more accurate results than others, and such algorithms may be suitable. |
4. | Sequence | The procedure of an algorithm must be in a sequence and some of the instructions of an algorithm may be repeated number of times until a particular condition is met. |
5. | General Ability |
The designed algorithm solves a single isolated problem and more often algorithms are designed to handle a range of input data to meet these criteria, so the algorithms must be generalized. |
REPRESENTATION OF ALGORITHMS
The algorithms can be represented in several ways. Generally the programmer follows one of the following ways to represent algorithms.
i. Normal English
ii. Flowchart
iii. Pseudocode
iv. Decision table
v. Program
1. | | The Algorithms can be easily represented in step by step sequential order in normal English, such algorithms are easy to understand, write and read. |
2. | Flowchart | The flowchart is a pictorial representation of an algorithm i.e. the sequential steps in an algorithm can be represented as flowchart using the standard symbols. |
3. | Pseudocode | Pseudocode is also a formal decision tool utilized very well with the rules of structured design and programming. |
4. | | A decision table helps a lot in designing a specific segment of a design. |
5. | Program | The algorithms can be represented as a program using any high level language that becomes a program.
|
HOW TO MAKE AN ALGORITHM
Now let’s get into the process of making algorithm. Let’s start with simple algorithms. Different algorithms may produce the same desired result. For example in an algorithm to find the circumference of the circle the circumference could be found out either by multiplying 2 with π and radius or only π with diameter. However, performing an algorithm correctly does not guarantee a solution, if the algorithm is flawed or not appropriate to the context. For example, this algorithm fails if radius is not present.
Example 1: Algorithm to find the area and circumference of the Circle.
Step 1: Start
Step 2: Read the radius
Step 3:Find the area and the circumference of the circle using the formula
area<--3.14*r*r
circumference<--2*3.14*r
Step 4:Print the area and circumference of the circle
Step 5: Stop
Example 2: Algorithm to find the largest of three numbers A, B and C.
Step 1: Start
Step 2: Read three numbers say A,B,C.Find the larger number between A and B
and store it in MAX_AB.
Step 4: Find the larger number between MAX_AB and C and store it in MAX
Step 5:Display MAX
Step 6: Stop