Algorithms in Programming

Definition of Algorithm

Set of rules or instructions to follow to perform an operation on the different data structures.

First, try to understand what is Algorithm from practical life:

For example, imagine you are asked to give instructions to someone how to make a cup of tea.List down what are the istructions you need to follow to make a green tea.

There are two ways that you can explain, 1.explaining the process by using lots of words. 2.Giving short answer with proper information.

To make the instructions clear and unambiguous write the same sequence of steps in structured English like what is given above.

Step1 : Boil water.
Step 2: pour boiling water into the pot.

Step3:put some tea leaves into the pot..

Programming in algorithm

Characteristics of an algorithm

1.Well-ordered

Since an algorithm is a collection of operations or instructions, we must know the correct order in which to execute these instructions. If the order is not clear, we may perform the wrong instruction, or we may be uncertain which instruction should be performed next. This characteristic is very important when working with computers as a computer can execute an algorithm only if it knows the exact order of steps to perform

2.unambigous operations

An algorithm is a sequence of unambiguous instructions for solving a problem,i.e., for obtaining a required output for any legitimate input in a finite amount of time [Levitin, p. … This is all for the purpose of making the Description of the algorithms as “unambiguous” as possible.

3.effectively computable operations.

Each operation in an algorithm must be doable, that is, the operation must be something that is possible to do. For example assume that you were given an algorithm for planting a garden where the first step instruct you to remove all larg stones from the soil. This instruction may not be possible carry out if the particular plot of land is sand without stones. For computers, many mathematical operations such as division by zero or finding this square root of a negative number also impossible. Operations which are not effectively computable cannot be used in writing algorithms.

4.produce a result.


Unless an algorithm produces some result, we can never be certain whether the given solution is correct. Have you ever given a command to a computer and discovered that nothing changed? Without some visible change, we have no of determining the effect of our command. The same is true with algorithms. Only algorithms which produce results can be verified as either right or wrong.

5.finiteness

Algorithms should be composed of a finite number of operations and they should complete their execution in a finite amount of time. Suppose we wanted to write an algorithm to print all the integers greater than 1.

While our algorithm seems to be very clear, there are two problems. First, the algorithm must have an infinite number of steps because there are an infinite number of integers greater than one. Second, the algorithm will run forever trying to count infinity. These problems violate our definition that an algorithm must halt in a fir amount of time. Every algorithm must halt in a future amount of time.Every algorithm must reach some operation that tells it to stop.

Representations of an algorithms.

We can write an algorithm as a flowchart or with a textual method like pseudocode.

Using this two method we can concentrate on logic of the solution without worrying about the programming language syntax.

Flow charts

We can use a flow chart to describe an algorithm by showing how problem solution proceeds step by step. Here we use standard symbols that depicts a process. decision, input/output etc.

There is a start symbol to indicate the beginning of the process and an end to indicate the end. It is assumed that the sequence of steps in the process go from top to bottom.
This shows how the problem of making a cup of tea is represented with a flowchart.

Pseudocode

Pseudocode is an informal way of programming description that does not require any strict programming language syntax or underlying technology considerations. It is used for creating an outline or a rough draft of a program.

Sum-of-Even numbers-0 mber = 0

Repeal

Number Number 12 Sum of Even-numbers Sum-of-Even-numbers + Number

Until Number – 10


Energy backs

Leave a comment

Design a site like this with WordPress.com
Get started