Elementor #435

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?

Key takeaway: Every good algorithm must be correct, finite, unambiguous, and efficient — these are called the properties of an algorithm.

Properties of a Good Algorithm

Computer scientists (and textbooks) agree that a well-defined algorithm must satisfy the following 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 (practically doable by a computer or human).

Some authors also add:

  • Correctness — The algorithm must produce the correct output for every valid input.
  • Efficiency — It should use reasonable time and memory (though not strictly required for the definition, very important in practice).

How Does a Real Algorithm Look Like?

An algorithm can be written in many forms:

  • Plain English (natural language description)
  • Flowchart
  • Pseudocode (most common in learning DSA)
  • Actual programming language code

Let’s look at the same simple problem expressed in different ways.

Example Problem: Find the largest number in a list

1. Plain English Description

Start with the first number as the current maximum. Look at each remaining number in the list one by one. If any number is bigger than the current maximum, update the maximum to that number. When you have checked all numbers, the current maximum is the answer.

2. Pseudocode (Most Common Format)

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

  • Finiteness: Yes — only 1–2 steps
  • Definiteness: Yes — clear instructions
  • Input: Yes — one integer
  • Output: Yes — “Even” or “Odd”
  • Effectiveness: Yes — very basic operations

Bad Example: What is NOT an Algorithm?

  • “Sort the array somehow” → not definite
  • “Keep trying random numbers until you find the answer” → may never terminate (no finiteness)
  • “Solve the traveling salesman problem optimally for 100 cities” → no known efficient way (effectiveness issue for large input)
Understanding how algorithms look and their required properties is the first real step toward writing correct and efficient code.
Next: Learn how to analyze algorithms using Time & Space Complexity!

Practice writing pseudocode for simple problems — it builds strong DSA thinking.

Leave a Comment

Your email address will not be published.