Ia 1 QB
Ia 1 QB
Definition of an Algorithm
Notion of an Algorithm
The notion of an algorithm revolves around step-by-step computation to achieve a goal. It can be
expressed in different forms, such as:
Algorithms must be precise, unambiguous, and effective, ensuring they solve a problem in a finite
amount of time.
1. Finiteness
o The algorithm must terminate after a finite number of steps. It should not run
indefinitely.
2. Definiteness (Unambiguity)
o Each step of the algorithm must be clear and precisely defined. There should be no
ambiguity in instructions.
3. Input
4. Output
o It must produce at least one output, which is the result after execution.
5. Effectiveness
o Every step should be basic and executable within a finite amount of time, without
requiring infinite resources.
6. Correctness
o The algorithm must produce the correct result for all valid inputs.
7. Generality
8. Optimization (Efficiency)
o A good algorithm should be optimized in terms of time complexity (speed) and space
complexity (memory usage).
1. Start
5. Stop
Algorithm GCD(a, b)
1. While b ≠ 0 do:
2. a ← a mod b
3. Swap a and b
4. Return a as the GCD