C Language
DSA
Software Engineering
Software Architecture
Operating System
Big Data
Data Mining and Warehousing
TOC
Ada
C++

Topics

  • 1. Definition of Algorithm
  • 2. Characteristics (Properties) of an Algorithm
  • 3. Algorithm and Program Notes
  • 4. Definition of Pseudocode
  • 5. Comparison: Algorithm vs Pseudocode
  • 6. Steps to Design an Algorithm
1. Definition of Algorithm

An algorithm is a step-by-step procedure to solve a problem. It is a sequence of instructions that operates on input data to produce a desired output in a finite number of steps.

            note : An algorithm is independent of any programming language.

Flow from Problem to Program

     Problem
         ↓
    Algorithm
         ↓
    Data Structure
         ↓
    Program
          ↓
   Computer executes program

2. Characteristics (Properties) of an Algorithm
  • Definiteness / Clarity

    • Each step of an algorithm must be clear, simple, and unambiguous.

    • Every instruction should have only one interpretation.

  • Input

    • An algorithm must receive zero or more inputs supplied externally.

    • Example: Numbers to add, array elements to sort, etc.

  • Output

    • An algorithm must produce at least one result as output.

    • Example: Sum of numbers, sorted array, etc.

  • Finiteness

    • An algorithm must terminate after a finite number of steps.

    • It should not run indefinitely.

  • Effectiveness

    • Instructions of an algorithm must be simple enough to be carried out manually using pen and paper.

    • No step should require extraordinary intelligence to perform.

3. Algorithm and Program Notes

Example: Multiplying Two Numbers

1. Problem

Multiply two numbers and display the result.


2. Algorithm

Step-by-step solution in simple language:

  1. Step 1: Store two inputs, a and b.

  2. Step 2: Multiply a and b, store the result in c.

  3. Step 3: Output c.

 Note: Algorithm is written in natural language, easy to understand, independent of programming language.


3. Program

Implementation of the algorithm in C language:

 
#include <stdio.h>

int main() {
int a, b, c;

printf("Enter two numbers: ");
scanf("%d %d", &a, &b);

c = a * b;

printf("The result is %d\n", c);

return 0;
}
 

 Note: A program is written in a computer language, executed by a computer, and depends on hardware, operating system, and compiler.


Comparison: Algorithm vs Program

Aspect Algorithm Program
Definition Step-by-step instructions to solve a problem Implementation of an algorithm using a programming language
Language Written in natural language Written in a computer language
Dependency Independent of OS and hardware Depends on OS, hardware, and compiler
Execution Conceptual – can be executed on paper Executed by a computer
Phase in SDLC Comes in Design/Planning Phase Comes in Implementation Phase
Steps Clear and unambiguous Detailed instructions extended for the computer
Testing No testing required on paper Needs compilation, debugging, and testing

 

4. Definition of Pseudocode
  • Pseudocode is a method of writing an algorithm step by step.

  • It is a high-level description of an algorithm that combines:

    • Natural language (English-like instructions)

    • Mathematical logic

 Key Point: Pseudocode is not a programming language and does not require execution.

Characteristics of Pseudocode

  1. Step-by-step instructions to solve any problem.

  2. Does not require specifying input and output explicitly.

  3. Written in natural language, sometimes mixed with simple mathematical symbols.

  4. No specific syntax rules.

  5. Does not raise errors because it is not executed.

  6. High-level description of an algorithm.

5. Comparison: Algorithm vs Pseudocode
Aspect Algorithm Pseudocode
Definition Step-by-step instructions to solve a problem High-level description of an algorithm
Language Natural language Natural language + basic mathematical logic
Input/Output Must define input and output Not strictly required
Execution Conceptual, can be executed manually Cannot be executed; purely descriptive
Syntax No strict syntax rules No specific syntax rules
Purpose To design a solution conceptually To make algorithm easier to implement in code

Pseudocode Example

Problem: Find the greatest of two numbers

 
Start
Input: a, b
If a > b then
Print "a is greatest"
Else
Print "b is greatest"
End