Skip to main content

Introduction to Algorithms

An algorithm is a finite, step-by-step sequence of well-defined, logical instructions designed to solve a specific computational problem or perform a task.

At its core, an algorithm takes a set of inputs, performs a series of systematic operations, produces a meaningful output, and halts (terminates).


1. Core Workflow of an Algorithm​

The fundamental execution flow of any algorithm can be represented as:

Key Components:​

  1. Input: The raw data or parameters provided to the algorithm (can be zero or more).
  2. Algorithm Steps: A sequence of arithmetic operations, conditionals, loops, or other computations.
  3. Output: The final computed results or solution returned by the algorithm.

2. Real-World Applications​

Algorithms power modern software, from simple utilities to complex artificial intelligence systems.

  • PageRank Algorithm (Google Search): Evaluates the quality and quantity of links to a webpage to determine its search engine ranking.
  • Face Detection Algorithms (Apple FaceID / Camera Apps): Analyzes pixel grids to identify key facial geometry, landmarks, and authenticate users or adjust focus.
  • Pathfinding Algorithms (Google Maps): Computes the shortest or fastest route between coordinates using weighted graphs representing traffic, distance, and road type.

3. Qualities of a Good Algorithm​

Not all procedures qualify as good algorithms. A high-quality algorithm must meet these criteria:

  1. Clear and Unambiguous: Each step should be precise and lead to a single, predictable outcome.
  2. Clearly Defined Inputs/Outputs: The exact types, ranges, and structures of input and output must be specified.
  3. Finiteness: The algorithm must terminate after executing a finite number of steps, preventing infinite loops.
  4. Feasibility: It must run efficiently on physical hardware within reasonable time and memory constraints.
  5. Language Independence: The logic must be generic enough to be implemented in any programming language (e.g., Java, Python, C++).

4. What is Pseudocode?​

Pseudocode is an informal, high-level description of an algorithm written in human-readable language rather than actual programming syntax.

It is used as a blueprint during the design phase of software, allowing developers to focus on logical flows and edge cases before writing code.


5. Pseudocode Examples​

Here are some standard algorithmic tasks represented in clean pseudocode:

A. Finding the Largest of Two Numbers​

This example demonstrates a conditional decision-making process.

START
INPUT A, B

IF A > B THEN
PRINT A
ELSE
PRINT B
END IF
STOP

Control Flow Visualization​

Here is how the control flow moves through this logic:

B. Addition of Two Numbers​

A simple arithmetic sequence without branching.

START
INPUT A
INPUT B

SUM = A + B

PRINT SUM
STOP

C. Checking Whether a Number is Even or Odd​

Demonstrates modulo arithmetic and conditional branches.

START
INPUT N

IF N % 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
END IF
STOP

6. Summary Comparison​

Metric / FeatureDescription
Primary GoalSolve a problem logically and terminate within finite time.
FormatCan be represented as a Flowchart, Pseudocode, or actual Source Code.
Logic ConstructionFocuses on correctness, completeness, and optimization.
Performance MeasuresTime Complexity (how fast it runs) and Space Complexity (how much memory it uses).
info

KEY SUMMARY

  • An algorithm is the underlying mathematical/logical solution to a problem.
  • Pseudocode is a text-based, human-readable blueprint of that solution.
  • A flowchart is a diagrammatic representation of the solution's control flow.
  • A good algorithm must be finite, unambiguous, and language-independent.