# Algorithms – Basics of Programming

## Algorithm – Introduction:

Algorithms are the basic and essential part of any programming language thus it is required for making programs. Because it is used by the computer for the solution to a problem. Because of this, the algorithm becomes different from words such as process, technique, or method.

Definition of algorithm in programming:

The algorithm is the well defined, finite computational instructions because it accomplishes a particular task. Hence they take inputs according to the requirements and produce some value or a set of values as output.

### Algorithm needs to satisfy some basic criteria as given below:

1. Zero or more quantities are externally supplied: Input.
2. At least one quantity is produced: Output.
3. Each instruction is clear and unambiguous because it makes it simple and easy to understand: Definiteness.
4. The algorithm ends after a finite number of steps because limited steps are easy to understand.
5. For every input instance, it halts with the correct output hence, input and correct output are must: Correct

An algorithm can be seen as a basic component of any Programming language. Hence its a tool for solving a well-specified problem.

The problem specified can be solved easily using an algorithm because they make the desired relationship between the Input and the Output.

The algorithm can also be said as the specific computational procedure for achieving the Input/Output relation.

### Properties of good Algorithms:

An algorithm should be written in simple English: easily understandable by the user at a later time.

It must be unambiguous, precise, and lucid because of its simplicity.

Algorithms provide the correct solutions because they define the basic structure of the program.

It must have an endpoint because of the limited steps required for simplifying the structure of the program.

For the desired output, it must follow input and thus process instructions.

It must have simplicity in the logic because it can be used for the processing of data.

It must cover all conditions and can be able to handle all unexpected conditions arisen during the implementation.

It is a step-by-step procedure, which is easily understandable by the user in later time.

Algorithms helps in the easy development of a Program because of its simplicity and better understanding.

It has a beginning and the endpoint under which some finite steps are explained, thus anyone can produce the desirable outputs according to the input.

A programming algorithm is easily debugged hence, any logical error can be easily repaired.

It doesn’t depend on the programming language therefore, it can be used in any programming language to define the structure and working of the program

## Some Basic Examples of Algorithms:

#### Find the sum of two numbers:

```Step 1: Start;
Step 2: input x and y;
Step 3: sum=x+y;
Step 4: print sum of x and y is [sum];
Step 5: End;```

#### Perform the arithmetic operations according to the requirement of the user:

```Step 1: Start;
Step 2: input x and y;
Step 3: print choices for the user to choose options:
2. subtraction
3. division
4. multiplication
5. Remainder
Step 4: input choice(1-5);
Step 5: compute the result
if(choice is 1)
result=x+y;
if(choice is 2)
result=x-y;
if(choice is 3)
result=x/y;
if(choice is 4)
result=x*y;
if(choice is 5)
result=x%y;
Step 6: print result;
Step 7: End;```

#### Find the largest of three numbers:

```Step 1: Start;
Step 2: input x, y, z;
Step 3: compute the largest of three numbers:
big=x;
if(y>big) then big=y;
if(z>big) then big=z;
Step 4: print [big];
Step 5: End;```

To know more about Computer, programming languages and to connect with the digital world – Click Here