Computer Basics - What is an Algorithm
1. What is an Algorithm?
An algorithm is a step-by-step procedure or set of rules designed to solve a specific problem or perform a particular task.
-
Think of it as a recipe for solving a problem.
-
Each step must be clear, finite, and unambiguous.
Key Characteristics of an Algorithm:
-
Finite – Must end after a limited number of steps.
-
Well-defined – Each step is clear and unambiguous.
-
Input – Can have zero or more inputs.
-
Output – Produces at least one output.
-
Effective – Steps must be practical and executable.
Example (Simple Algorithm to Add Two Numbers):
-
Start
-
Read number A and number B
-
Sum = A + B
-
Display Sum
-
Stop
2. Types of Algorithms
-
Simple/Sequential Algorithm – Executes steps one after another.
-
Conditional/Decision Algorithm – Executes steps based on a condition (if-else).
-
Looping/Iterative Algorithm – Repeats steps until a condition is met (for, while loops).
-
Recursive Algorithm – A step calls itself to solve a smaller version of the problem.
3. Advantages of Using Algorithms
-
Solve problems systematically
-
Make programming easier
-
Improve efficiency and reduce errors
-
Help in designing flowcharts and code
4. What is a Flowchart?
A flowchart is a diagrammatic representation of an algorithm.
-
It shows the sequence of steps using different symbols.
-
Helps visualize the logic before programming.
Common Flowchart Symbols:
-
Oval (Terminator) – Start or Stop
-
Rectangle (Process) – Process or action step
-
Parallelogram (Input/Output) – Input or output operation
-
Diamond (Decision) – A decision point (Yes/No or True/False)
-
Arrow – Shows the flow of steps
Example (Flowchart for Adding Two Numbers):
(Start) → (Input A, B) → (Sum = A + B) → (Display Sum) → (Stop)
5. Steps to Create an Algorithm and Flowchart
-
Understand the Problem – Identify input, output, and requirements.
-
Define the Steps – Write a clear, sequential procedure.
-
Choose Tools – Decide whether to use pseudocode, flowchart, or both.
-
Draw Flowchart – Use proper symbols for each step.
-
Test – Check with example inputs to ensure correctness.
6. Relationship Between Algorithm and Flowchart
-
Algorithm: Step-by-step written procedure (textual).
-
Flowchart: Graphical representation of the algorithm.
-
Both are used to plan and design a solution before coding.
✅ In short:
An algorithm is a set of instructions to solve a problem, and a flowchart is the visual map of that algorithm. They help programmers think logically, avoid mistakes, and efficiently write programs.