π Key Takeaway: Every good algorithm must be correct, finite, unambiguous, and efficient.
In the previous post we understood what is an algorithm. Now letβs go one step deeper: How does an algorithm actually look? What are its essential characteristics? And how do real algorithms appear in practice?
Properties of a Good Algorithm
Computer scientists agree that a well-defined algorithm must satisfy these five important properties:
- Finiteness β The algorithm must terminate after a finite number of steps.
- Definiteness β Each step must be precisely and unambiguously defined (no confusion allowed).
- Input β Zero or more well-defined inputs must be given.
- Output β At least one well-defined output must be produced.
- Effectiveness β Every step must be basic enough that it can be carried out exactly and in a finite amount of time.
Some authors also add:
- Correctness β Produces correct output for every valid input.
- Efficiency β Uses reasonable time and memory (very important in practice).
How Does a Real Algorithm Look Like?
An algorithm can be expressed in multiple ways:
Plain English
Flowchart
Pseudocode
Programming Code
Example Problem: Find the Largest Number in a List
1. Plain English Description
- Start with the first number as the current maximum.
- Check each remaining number one by one.
- If a number is bigger than current maximum, update it.
- After checking all numbers, return the maximum.
2. Pseudocode (Most Popular in DSA)
Algorithm FindMaximum(A, n)
// A is array of n numbers
max β A[1]
for i β 2 to n do
if A[i] > max then
max β A[i]
end if
end for
return max
3. In C-like Code
int findMax(int arr[], int n) {
int max = arr[0];
for(int i = 1; i < n; i++) {
if(arr[i] > max) {
max = arr[i];
}
}
return max;
}
Another Classic Example: Check if a Number is Even or Odd
Pseudocode
Algorithm IsEven(number)
Input: number (integer)
if number mod 2 == 0 then
Output "Even"
else
Output "Odd"
end if
Properties Check
| Property | Status | Reason |
|---|---|---|
| Finiteness | β Yes | Only 1β2 steps |
| Definiteness | β Yes | Clear instructions |
| Input | β Yes | One integer |
| Output | β Yes | “Even” or “Odd” |
| Effectiveness | β Yes | Simple modulo operation |
Bad Examples: What is NOT an Algorithm?
These are NOT valid algorithms:
"Sort the array somehow"β Not definite"Keep trying random numbers until you find the answer"β No finiteness (may never stop)"Solve the Traveling Salesman Problem optimally for 100 cities"β Effectiveness issue for large input
Understanding algorithm properties is the foundation for writing correct, reliable, and efficient code.
Up Next: Learn Time Complexity β How to measure how fast an algorithm runs.
π‘ Practice: Write pseudocode for everyday tasks like βmaking teaβ or βsearching a contactβ.
π‘ Practice: Write pseudocode for everyday tasks like βmaking teaβ or βsearching a contactβ.