Sunteți pe pagina 1din 2

UNIT – 1 (Data Structure Using C/C++).

Definition of Algorithm
An Algorithm can be defined as a step by step procedure that provides solution to a given problem. It
comprises of a well-defined set of finite number of steps or rules that are executed sequentially to obtain
the desired solution.

Characteristics of Algorithm
There are certain key characteristics that an algorithm must process. The following characteristics are:
1. An algorithm must comprise of finite number of steps.
2. It should have zero or more valid and clearly defined input values.
3. It should be able to generate at least a single valid output based on a valid input.
4. It must be definite, i.e., each instruction in the algorithm should be defined clearly.
5. It should be correct, i.e., it should be able to perform the desired task of generating correct
Output from the given input.
6. There should be no ambiguity regarding the order of execution of algorithm steps.
7. It should be able to terminate on its own, i.e., it should not go into an infinite loop.

Representation of an Algorithm
An Algorithm can be represented in number of ways, right from normal English Language phrases to
Graphical representation using Flowcharts.
Another way of representing an Algorithm is the Pseudocode. Pseudocode is an informal representation of
the algorithm that provides a complete outline of a program so that the programmer can easily understand
it and transform it into a program using the programming language of their choice.
Following are some of the general conventions that are followed while using Pseudocode:
1. Provide a valid name for the Algorithm written using Pseudocode.
2. For each line of instruction specify line number.
3. Always begins an identifier name with English Alphabet.
4. It is not necessary to explicitly specify the data type of the variables.
5. Always indent the statements present inside a block structure appropriately.
6. Use Read and Write word to specify input and output operations.
7. Use if or if else constructs for conditional statements. You must end an if statement with the
corresponding end if statement. Example Given Below:
If (conditional expression)
//Statement
End-if
Or
If (conditional expression)
//Statement
Else
//Statement
End-if
8. For looping or iterative statements, you can use for or while constructs. A For Loop must end
with an end for statement and a While Loop must end with an end while statement. Example
given below:
For i=0 to 10 do
{// Statement n}

S-ar putea să vă placă și