What is an algorithm
- Siddharth Sharma
- Dec 7, 2024
- 3 min read
What is an Algorithm?
An algorithm is a well-defined, step-by-step procedure used to solve a specific problem or perform a task. It provides a systematic approach for problem-solving, ensuring the task is completed efficiently and effectively.
Understanding Algorithms
An algorithm is a clear, finite set of instructions designed to solve a specific problem or accomplish a task. In programming, algorithms determine how data flows and operations are performed. While you can express algorithms in various formats like natural language, pseudocode, or flowcharts, programming languages like C enable the effective implementation of these instructions.
Key Characteristics of an Algorithm
Input: Accepts zero or more inputs.
Output: Produces at least one result.
Definiteness: Each step must be precisely defined and unambiguous.
Finiteness: Must terminate after a finite number of steps.
Effectiveness: All steps should be simple enough to be executed in a finite amount of time.
Purpose of an Algorithm
To serve as a blueprint for solving problems.
To provide a logical foundation for writing computer programs.
To optimize the use of resources like time and memory.
Representation of Algorithms
Natural Language: Described using plain language.
Pseudocode: Uses structured, human-readable syntax.
Flowcharts: Uses symbols and diagrams for visualization.
Example Algorithm
Problem: Find the largest of three numbers.
Steps:
Start.
Input three numbers: A, B, C.
If A > B and A > C, then A is the largest.
Else if B > A and B > C, then B is the largest.
Else, C is the largest.
Output the largest number.
Stop.
Here's a C program to input three numbers and find the largest among them:
#include <stdio.h> // Include the standard input/output header file
int main() {
// Declare variables to store the three numbers
int A, B, C;
// Input three numbers
printf("Enter three numbers: ");
scanf("%d %d %d", &A, &B, &C);
// Compare and find the largest number
if (A >= B && A >= C) {
printf("The largest number is: %d\n", A);
} else if (B >= A && B >= C) {
printf("The largest number is: %d\n", B);
} else {
printf("The largest number is: %d\n", C);
}
return 0; // Exit the program
}Explanation of the Program
Input Section:
The scanf() function reads three integer values entered by the user and stores them in variables A, B, and C.
Logic Section:
The if statement compares A, B, and C to determine the largest.
Logical operators (&&): Ensure that all conditions are satisfied.
Output Section:
The printf() function displays the largest number.
Sample Run
Input:
Enter three numbers: 5 15 10
Output:
The largest number is: 15
Let me know if you need additional modifications!
The representation of an algorithm refers to how it is documented or visualized. Algorithms can be represented in various ways depending on the context, audience, or purpose. Below are the most common methods:
1. Natural Language Representation
The steps of the algorithm are described in plain, human-readable language.
Example:
Find the largest of three numbers:
Start.
Input three numbers: A, B, C.
If A > B and A > C, then A is the largest.
Else if B > C, then B is the largest.
Otherwise, C is the largest.
Print the largest number.
Stop.
2. Pseudocode
Pseudocode uses structured, informal programming-like syntax. It’s more precise than natural language but not as strict as real code.
Example:
Start
Input A, B, C
If A > B and A > C
Largest ← A
Else if B > C
Largest ← B
Else
Largest ← C
Print Largest
Stop3. Flowchart
A flowchart uses graphical symbols to depict the sequence of operations in an algorithm.
Key Symbols:
Oval: Start/End
Rectangle: Process (e.g., calculations, assignments)
Diamond: Decision (e.g., if/else conditions)
Arrow: Flow of control
Example: Flowchart for finding the largest of three numbers:
Start
Input A, B, C
Compare A, B, and C using decision diamonds
Output the largest number
End
This is flow chart of program;

4. Tabular Representation
Steps and conditions are written in a tabular format for clarity.
Step | Operation | Condition | Result |
1 | Input three numbers A, B, C | ||
2 | Compare A with B and C | A > B and A > C | A is largest |
3 | Compare B with C | B > C | B is largest |
4 | Default | C is largest | |
5 | Print the largest number |
Choosing a Representation
Natural Language: Best for explaining to non-programmers.
Pseudocode: Ideal for programmers and students learning coding concepts.
Flowcharts: Useful for visualizing complex logic.
Tabular Representation: Effective for summarizing conditions and actions.




Comments