Algorithm
What is Algorithm?
An algorithm is a step-by-step procedure or set of rules designed to perform a specific task or solve a particular problem. It is a sequence of instructions that are followed to achieve a desired outcome. Algorithms are fundamental to computer science and programming, as they provide a clear and efficient way to process data and perform computations.
Characteristics of an Algorithm
Algorithms have several key characteristics that define their structure and ensure they function correctly and efficiently. Here are the main characteristics of an algorithm:
1. Clear and Unambiguous:
Algorithm should be clear and unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning.
2. Well-Defined Inputs:
If an algorithm says to take inputs, it should be well-defined inputs.
3.Well-Defined Outputs:
If an algorithm says to take inputs, it should be well-defined inputs.
4.Finite-ness:
The algorithm must be finite, i.e., it should not end up in an infinite loops or similar.
5. Feasible:
The algorithm must be simple, generic and practical, such that it can be executed upon with the available resources. it must not contain some future technology, or anything.
6. Language Independent:
Advantage of Algorithm
- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
Disadvantage of Algorithm
- Writing an algorithm takes a long time so it is time-consuming.
- Branching and Looping statements are difficult to show in Algorithms.
Some Example:-
- START
- Declare 3 Integer variable num1, num2, and num3.
- Take the three numbers, to be added, as inputs in variables num1, num2, num3 respectively.
- Declare an integer variables sum to store the resultant sum of the 3 numbers.
- Add the 3 numbers and store the result in the variable sum.
- Print the value of variable sum.
- END
- Start
- Declare variables: side_length (to store the length of the side of the square) and area (to store the computed area of the square).
- Prompt the user to input the length of the side of the square.
- Read the input value and store it in side_length.
- Calculate the area using the formula: