What is an Algorithm
Definition
An algorithm is a finite, step-by-step procedure used to solve a problem or perform a specific task. In simple
words, an algorithm is a set of instructions that tells a computer how to do something in an ordered manner.
Example (Daily Life Algorithm)
Making Tea
1. Boil water
2. Add tea leaves
3. Add sugar
4. Add milk
5. Boil and serve
This is an algorithm because it has clear steps and a definite outcome.
Algorithm in Computer Science
In computer science, an algorithm is a logical sequence of steps used to:
Perform calculations
Process data
Solve computational problems
Example: Algorithm to Add Two Numbers
1. Start
2. Read two numbers A and B
3. Calculate C = A + B
4. Display C
5. Stop
Characteristics of an Algorithm : -An algorithm must satisfy the following properties:
1. Input
o Takes zero or more inputs
2. Output
o Produces at least one output
3. Definiteness
o Each step is clearly defined
4. Finiteness
o Terminates after a finite number of steps
5. Effectiveness
o Each step is basic and executable
Why Are Algorithms Important?
Foundation of computer programming
Improves problem-solving skills
Helps write efficient programs
Used in every software application
Enables automation
Types of Algorithms (Important )
1. Searching Algorithms
Linear Search
Binary Search
2. Sorting Algorithms
Bubble Sort
Selection Sort
Merge Sort
Quick Sort
3. Mathematical Algorithms
Euclid’s GCD algorithm
Fibonacci algorithm
4. Graph Algorithms
Dijkstra’s Algorithm
BFS, DFS
5. Greedy Algorithms
Prim’s Algorithm
Kruskal’s Algorithm
6. Dynamic Programming Algorithms
Knapsack problem
Floyd–Warshall algorithm
Algorithm vs Program
Algorithm Program
Logical steps Implementation in code
Language independent Language dependent
Design stage Execution stage
Algorithm Representation
1. Natural Language
2. Pseudocode
3. Flowchart
4. Programming Language
Simple Example (Pseudocode)
Algorithm Find_Max
Input: Two numbers A, B
Output: Maximum number
If A > B
Print A
Else
Print B
End If
Advantages of Algorithms
Easy to understand
Language independent
Helps in debugging
Improves efficiency
Limitations of Algorithms
Time-consuming to design
Not visual (without flowchart)
Complex for large problems