πŸ”‘ 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:

  1. Finiteness β€” The algorithm must terminate after a finite number of steps.
  2. Definiteness β€” Each step must be precisely and unambiguously defined (no confusion allowed).
  3. Input β€” Zero or more well-defined inputs must be given.
  4. Output β€” At least one well-defined output must be produced.
  5. 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

  1. Start with the first number as the current maximum.
  2. Check each remaining number one by one.
  3. If a number is bigger than current maximum, update it.
  4. 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”.