Introduction to Algorithm
1. Algorithm Kya Hota Hai?
An algorithm is a method used to solve a problem in a series of steps. An algorithm is a set of instructions that is bound by time. It solves a particular problem. Algorithms are done in mathematical and computer science as well as in a number of daily tasks.
For example
If you want to prepare tea, then there has to be a method where steps are followed sequentially as follows: Put on the kettle, Add in the tea leaves, Add milk and sugar, Allow tea to boil, Pour tea into the cup using a strainer.
This is an algorithm which defines steps involved in making tea.
2. Algorithm Ki Importance
Algorithms are crucial because they increase efficiency in problem solving and computer operations. Some major advantages of dip algorithms are:
Efficiency -Algorithm creates an efficient and optimized system.
Accuracy - Well structured algorithms reduce mistakes and errors.
Automation - Aids in performing monotonous work automatically using machines and software.
Optimization - Algorithms optimize resource use (time and memory).
Scalability - Badi problems ko asani se tackle karne mein help karta hai.
3.Types of Algorithm
Algorithms are of different types and each type is designed to solve certain problems. Some of them are the main ones1. Brute Force Algorithm
Yeh is easiest aur simplest Algorithm ke type that check each and every possible solution until he gets toExample: Linear Search Algorithm checks for each and every elements provided in the list to find the specific item required.
2. Divide and Conquer Algorithm
This technique solves main problem by dividing it into smaller sub problems. And then these sub problems are solved independently in a recursive manner.Example: Merge Sort and Quick Sort Algorithms.
3. Greedy Algorithm
Steps is these algorithms is that each algorithm will choose the best possible solution. In this case optimal solution locally.Example: Used in Dijkstra’s Algorithm where the desire is to find the shortest path between two points.
4. Dynamic Programming Algorithm
This algorithm in particular during the tasks has many steps within the complexity is that solve complex problems use subproblems can which solution is kept to avoid performing the same calculation multiple times.Example: Fibonacci Series, and knapsack problem.
5. Backtracking Algorithms
Is algorithm ko backtracking algorithm is liye kehte hain kyunki yeh kisi bhi pehle wale step par waapas jaane ki salahiyat rakhta hai agar ek kadam orthogonal hote hai.Example: N-Queens problem and Sudoku Solver.
6. Randomized Algorithm
QuickSort mein randomized algorithms isi liye istemal hote hain kyunki random ka ferishta har waqt saath hota hai.Example: QuickSort (Randomized Pivot Selection).
4. Representation Of Algorithms
Kabhi kabhi algorithm ka presentation bahut hi khatarnaak hota hai jiski woh definition ke mutabik nahi hoti. Is wajah se algorithms ko ghalep aur gholne ke liye unka padne waalon ke liye bayancez aur sikhar kya kaen option milte dikhana pare.1. Pseudocode
Pseudocode is an informal description of a computer program or algorithm that does not need a formal programming language syntax.Example:
Algorithm FindMax(arr, n):
max_value <- arr[0]
for i from 1 to n-1:
if arr[i] > max_value:
max_value <- arr[i]
return max_value
2. Flowchart
A flowchart is a type of diagram that represents an algorithm, workflow or process. Symbols used are:Oval → Start and end
Rectangle → Process
Diamond → Decision
Arrow → Flow of Execution
5. Algorithm Complexity Analysis
The efficiency of an algorithm is analyzed by the use of complexity.1. Time Complexity
Time Complexity kisi algorithm ko execute karne ke liye lagne wale samay ko darshata hai input size ke according kis hisab se. Yeh Big O Notation se dikhaya jaata hai.
Common Time Complexities:
O(1) → Constant Samay: Koi element access karna in an array.
O(log n) → Logarithmic Samay: Binary Search.
O(n) → Linear Samay: Linear Search.
O(n log n) → Log Linear Samay: Merge Sort, Quick Sort.
O(n²) → Quadratic Samay: Bubble Sort, Selection Sort.
O(2ⁿ) → Exponential Samay: Recursive Fibonacci.
2. Space Complexity
Space Complexity define karti hai ki kisi algorithm ko execute karne ke liye kitni adhik ya memoribil chahiye hoti hai.
Example: Agr ek algorithm sirf kuch variables ko he use kare toh iski sthan complexicity O(1) hi rahein, par agar wo ek suvihar array ko use kare toh O(n) ho sakti.
6. Algorithms Ka Real-World Use
Algorithms ka real duniya mein kaafi use aur value hai. Yeh sabse zyada jarurat hai1. Searching & Sorting Algorithms
Google Search mein page ranking aur binary search pero aadharit hota hai.For E-Commerce Sites, Quick Sort merge sort ka use product programs sort karne mein h karta hai.