What is an Algorithm?
An algorithm is a finite, ordered sequence of unambiguous instructions used to solve a computational problem.
Algorithm vs Program
| Algorithm |
Program |
| Step-by-step procedure |
Implementation in programming language |
| Language independent |
Language dependent |
| Design phase |
Implementation phase |
| Finite logical steps |
Executable code |
Characteristics of Algorithms
- Input: Algorithm takes zero or more inputs from the external environment
- Output: Algorithm produces at least one output as the result
- Definiteness: Each step must be clear, unambiguous, and precisely defined
- Finiteness: Algorithm must terminate after finite number of steps
- Effectiveness: Steps must be basic enough to be carried out by a human using basic operations
Algorithm Analysis
Why Analyze Algorithms?
To compare different algorithms and choose the best one for a given problem.
Analysis Parameters
1. Time Complexity
- Definition: Amount of time algorithm takes to complete
- Measurement: Number of basic operations (comparisons, assignments, arithmetic)
2. Space Complexity
- Definition: Amount of memory space algorithm uses