1.2 Characteristics of Algorithm
Characteristics of an Algorithm
Input Requirements
- An algorithm must accept zero or more inputs, indicating flexibility in its design. Some algorithms may not require any input at all.
Output Necessity
- Every algorithm must produce at least one output; otherwise, it serves no purpose. This is akin to a function in C language that, despite having no parameters, still returns a result.
Definiteness of Statements
- Each statement within an algorithm should be clear and unambiguous, possessing a single meaning. If humans cannot solve a problem, computers cannot either.
Finiteness of Execution
- An algorithm must have a finite number of steps and eventually terminate. While it can contain many statements, it should not run indefinitely without stopping.
Effectiveness and Relevance
- Algorithms should avoid unnecessary statements; every step must contribute towards achieving the objective. This principle parallels procedures in scientific experiments or cooking recipes where each step has significance.
Examples of Procedures
Importance of Clear Objectives
- Just like chemical experiments or cooking recipes require specific ingredients and apparatus to yield results, algorithms need defined objectives to ensure they produce meaningful outputs.
Known Steps Only
- All steps performed in an algorithm must be known and understood; there should be no ambiguity or "magical" elements involved in the process.
Conclusion on Effectiveness