### Day 24: All about Algorithms

Hello Dear Students,
Hope you all are doing good.

Aaj hum algorithms ke baare mein study karenge, algorithm introduction, basics, algorithm complexity.

Let's get started..

ALGORITHM -
•  Algorithm word comes from the mathematician Mohamad-Al-Khowarizmi, who invented the addition, subtraction, multiplication and division on the decimal numbers.
• Algorithm means step by step procedure kisi bhi problem ko solve karne ke liye.
• Jab hum data ko store karne ke liye data structure ko choose kar lete hain, then us data structure ke operations ko process karne ke liye algorithms use karte hain.
• Algorithm ko simple english language mein likha jata hai so that easily understandable ho sake. Pseudo-code language.
• Algorithm is not written in programming language.
• Effective algorithm wohi hota hai jo problem ko solve karne ke liye minimum resources ko use kare.

ALGORITHM BASICS - For writing an algorithm, we use different aspects which are as follows-
1. Comments- Comments means jo sirf user ki understanding ke liye ho. User ne konsa step kyu kiya hai mostly wo comment mein likha jata hai. Algorithm mein comment likhne ke liye []square brackets use ki jati hai. For example, [comment here...].
2. Identifying Number - Har ek algorithm ka ek unique number hota hai jisse pata lagta hai ki ye algorithm konsa hai. For example, Algorithm 4.3, Algorithm 3.6, etc. and algorithm step by step procedure hota hai so har ek step numbers bhi hote hain Step 1, Step 2 and so on.
3. Naming Convention - Variable names and Algorithm names always capital letters mein likhe jate hain. For example, VAR, LSEARCH, etc.
4. Assignment Statement - Assignment statement is used to assign value to a variable. Jab hum variable ko declare karte hain then uski value ko assign karne ke liye assignment statement use hoti hai. Assignment statement mein 2 cheeze hoti hain, assignment notation i.e. "Set" and operator ":=". For example, Set VAR:=10. VAR is variable and value is 10 assigned by assignment statement.
5. Operators - Different operators hote hain operations ko perform karne ke liye, For example, less than <, greater than>, and so on.
6. Input Output Statements - Input data can be like Read VAR, VAR is variable name whose values will be input. Output data can be like Write VAR, to print value of variable name VAR.
7. Control Structure - There are 3 control structures-
1. Sequence Logic/Flow- In this, step by step execution of the process is done.
2. Selection Logic/Conditional Logic - In this, If, If-Else, If then, etc, are used.
3. Iteration/ Repetition Logic Flow - In this, Loops, Jumps are used.

ALGORITHM COMPLEXITY
• Ek algorithm ka main purpose hota hai data ko process karna.
• Jab algorithms banaye jate hain so usko banane ke liye space and time lagta hai.
• Ek effective algorithm wohi hota hai jo less space consume kare, less time le processing ke liye and minimum resources use kare.
• Ek problem ko solve karna is not enough but us problem ko effectively solve karna is important.
• For example, to calculate the sum of 2,2,2,2,2,2. It can be like 2+2+2+2+2+2=12. But effective way is 2*6=12. So, solving problem with effectiveness is most important.
• Algorithm ko effective hone ke liye 2 factors important hote hain, Time and Space.
• Agar ek algorithm ko process hone mein jyada time lag raha hai then wo uski time complexity hoti hai.
• Agar ek algorithm ko process hone mein jyada space consume hoti hai then wo uski space complexity hoti hai.
• Algorithm complexity is function f(n) that gives running time and memory space required by an algorithm for processing n input data size.

SPACE COMPLEXITY - Space complexity is number of cells an algorithm requires. Agar small memory space consume hoga then wo good algorithm hai. Function f(n) describe karta hai amount of memory ko jo algorithm consume karta hai processing mein.

TIME COMPLEXITY - Time complexity is amount of time an algorithm needs to run algorithm. Complexity basically input size par depend karti hai, For example, agar input size less hoga then complexity bhi less hogi and agar input size large hoga then complexity bhi large hogi. Time complexity also depend on the operations performed in algorithm.

COMPLEXITY TYPES - Complexity depend karti hai input size par, it is of 3 types-
• Worst Case Complexity - Worst case means longest running time means maximum steps taken for input size n. Ye wo case hai jisme space sabse jyada consume hoti hai and time bhi bahut jyada lgta hai. For example, Agar hum kuch search karenge, 100 values hain and jo value search karni hai wo 90 position par hai, then hum pehle 90 positions par visit karenge then hume value find hogi. So, this is worst case complexity.
• Best Case- Best case means smallest running time and minimum steps taken for input size n. Ye wo case hai jisme sabse less space consume hoti hai and time bhi less consume hota hai. For example, Agar hum search karte hain 100 values mein se and wo value 10 position par hi ho, then wo best case hoga.
• Average Case - Average case means medium difficulties means worst case and best case ke medium. For example, agar hum search karte hain 100 values mein se and wo value 50 position tak ho then wo average case complexity hoti hai.

Best of Luck Students,
Do visit our website regularly for more content and for daily tests.

Regards,
UGC NET EXPERTS