![](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_1209,h_365/https://codewindow.in/wp-content/uploads/2021/11/Algo_Poster.png)
What is Algorithm?
An algorithm is a finite set of instructions that if followed accomplishes a particular task. In other word, an algorithm is any well defined computational procedure that transforms some value or set of values i.e. “Input” into some value or set of values i.e. “Output”.
Criteria of an Algorithm
a) Input : Zero or more Quantities
b) Output: At least one quantity is produced.
c) Definiteness: Each instruction is clear and unambiguous.
d) Finiteness: The algorithm must terminate after a finite number of steps.
e) Effectiveness: Every instruction must be very basic and feasible.
An algorithm can be represented by-
Languages (Like English)
Flow Charts
Pseudo Code (C, Pascal etc.)
An algorithm has two parts:
a) Heading: Algorithm name (<Parameter List>)
b) Body: Statements enclosed within braces { }. An algorithm may or may not return a value.
From the data structure point of view, following are the some important categories of algorithms:
a) Search : Algorithm to search an item in a data structure.
b) Sort : Algorithm to sort items in a certain order.
c) Insert: Algorithm to insert item in a data structure.
d) Update: Algorithm to update an existing item in a data structure.
e) Delete : Algorithm to delete an existing item from a data structure.
Notation of Algorithm used in Pseudo Code
Comments begin with // and continue until end of line. For multiple line comment use /* ……..*/
Blocks are indicated by matching braces { }. and statements are terminated by semi-colon(;). Semi-colon is known as Statement Terminator.
An identifiers begins with a letter. The data types of variables are not implicitly declared.
Asignment of values to variables is done as <variable>:<expression>;
Logical operators ‘and’, ‘or’, ‘not’, and relational operators <, <=, =, > are provided.
Elements of multi-dimensional arrays are accessed using [ and ] as example, Arr[i,j] – the (i,j) th element of the array Arr.
Conditional statement from : if <condition> then <statement> and if <condition> then <statement> else <statement>
Input and output are done using the instructions “read” and “write” respectively.
While: while<condition>do {…………}
For: for variable := value1 to value2 step do {…………}