Algorithm
What is an Algorithm?
An algorithm is a step-by-step procedure or set of instructions designed to solve a problem or accomplish a task in a finite number of steps. It’s written in clear, simple language so humans can understand the logic before coding it.
Characteristics of a Good Algorithm
An algorithm should have these properties:
-
Unambiguous: Every step must be clear with only one interpretation.
-
Input: It can have zero or more well-defined inputs.
-
Output: It must produce at least one output.
-
Finiteness: It must finish after a finite number of steps.
-
Feasibility: It should be practical to implement.
-
Language-independent: It should not depend on any specific programming language.
Advantages of Algorithms
Algorithms help in problem solving because:
-
They are easy to understand.
-
They provide a clear sequence of steps for problem solving.
-
They are independent of programming languages.
-
They simplify converting logic into actual programs.
-
They help break complex problems into simpler steps.
Disadvantages of Algorithms
While useful, algorithms have some downsides:
-
Writing detailed algorithms can be time-consuming.
-
Large algorithms can become complex.
-
They are not suitable for representing loop behavior visually without flowcharts.
🧠 Typical Example — Algorithm to Add Two Numbers
Here’s a simple algorithm example (common in O Level notes):
-
Start
-
Input two numbers A and B
-
Compute
Sum ← A + B -
Print
Sum -
Stop