Writing Algorithms

Writing Algorithms
An algorithm is a step-by-step procedure to solve a problem. Writing a good algorithm is the first step towards writing a successful program. Algorithms can be written in three main ways — Natural Language, Pseudocode, and Flowchart — each offering a unique way to represent your logic.
Introduction
Before you write a computer program, you need to plan how the program will work. This plan is called an algorithm. Writing an algorithm is like drawing a blueprint before building a house — it helps you organize your thoughts, define the logic, and avoid mistakes.
There are three popular ways to write algorithms: Natural Language, Pseudocode, and Flowchart. Each has its strengths and is used based on the audience and complexity of the problem.
Real-Life Analogy
Writing an algorithm is like drawing a floor plan for a house. Before construction begins, the architect sketches every room, door, and window. Similarly, before coding, you write an algorithm to plan every step of your program.
What is an Algorithm?
An algorithm is a finite sequence of well-defined instructions used to solve a problem. It takes some input, processes it, and produces the required output.
Well-Defined Instructions
Every step in an algorithm must be clear, unambiguous, and actionable.
Finite Steps
A good algorithm must complete in a finite number of steps — never run forever.
Solves a Problem
Every algorithm has a purpose: to solve a problem by taking input and producing the required output.
Why Write Algorithms?
Writing an algorithm before coding brings many benefits. Let's explore the main reasons why algorithms are essential.
Organizes Thoughts
- Helps in organizing thoughts
- Breaks complex problems into small steps
- Provides a clear plan
Easy to Understand
- Makes the solution easy to understand
- Helps others follow your logic
- Improves teamwork
Correct & Efficient Programs
- Helps in writing correct and efficient programs
- Reduces bugs
- Improves performance
Blueprint Before Coding
- Acts as a blueprint before coding
- Saves time during implementation
- Reduces trial-and-error
Ways to Write Algorithms
Algorithms can be written in three main ways, each suited for different audiences and purposes.
Natural Language
Writing the algorithm in simple English like a normal conversation. Easy for beginners and non-programmers to understand.
Pseudocode
Writing the algorithm using simple English statements with programming style. Bridges natural language and code.
Flowchart
Representing the algorithm using symbols and arrows. A visual diagram that makes logic easy to see and follow.
A. Natural Language
The Natural Language approach uses simple, everyday English to describe the steps of an algorithm. It's the easiest way to start and requires no special knowledge.
Advantages
- Easy to write and read
- No special notation required
- Understandable by anyone
- Perfect for beginners
Disadvantages
- Can be ambiguous or unclear
- Not standardized
- Harder to translate to code
- Verbose for complex problems
Example — Find Largest of Two Numbers (Natural Language)
1. Start
2. Take two numbers A and B
3. If A > B then A is largest
4. Else B is largest
5. Display the largest number
6. Stop
B. Pseudocode
Pseudocode combines simple English with programming style. It uses keywords like START, INPUT, IF, THEN, ELSE, PRINT, and STOP but doesn't follow strict syntax of any programming language.
Advantages
- Bridges natural language and code
- Standardized keywords
- Easy to translate to any programming language
- Removes ambiguity
- Language-independent
Common Pseudocode Keywords
| Keyword | Purpose |
|---|---|
| START / BEGIN | Start of the algorithm |
| STOP / END | End of the algorithm |
| INPUT / READ | Take input from user |
| PRINT / OUTPUT / DISPLAY | Display result |
| IF...THEN...ELSE | Decision making |
| WHILE / FOR / REPEAT | Looping |
| ← or = | Assignment operator |
| ENDIF / ENDWHILE / ENDFOR | End of block |
Example — Find Largest of Two Numbers (Pseudocode)
START
INPUT A, B
IF A > B THEN
LARGEST ← A
ELSE
LARGEST ← B
ENDIF
PRINT LARGEST
STOP
C. Flowchart
A Flowchart represents an algorithm using standard symbols and arrows. It's a visual way to see the flow of logic, making it easier to understand complex decisions and loops.
Common Flowchart Symbols
| Symbol | Name | Purpose |
|---|---|---|
| Oval | Terminator | Start or Stop of algorithm |
| Parallelogram | Input/Output | Input data or output result |
| Rectangle | Process | Perform a calculation or step |
| Diamond | Decision | Ask a Yes/No question |
| Arrow | Flow Line | Shows direction of flow |
| Circle | Connector | Connects different parts |
Example — Find Largest of Two Numbers (Flowchart)
Start (Oval)
↓
Input A, B (Parallelogram)
↓
Is A > B? (Diamond)
├── Yes → LARGEST = A (Rectangle)
└── No → LARGEST = B (Rectangle)
↓
Print LARGEST (Parallelogram)
↓
Stop (Oval)
Steps to Write an Algorithm
Follow these 8 essential steps every time you write an algorithm.
Step 1: Understand the Problem
Understand the Problem
Read the problem carefully and understand what is being asked.
Step 2: Analyze the Problem
Analyze the Problem
Identify what the problem requires and how it can be solved.
Step 3: Identify Inputs and Outputs
Identify Inputs and Outputs
Decide what data is needed as input and what result is expected as output.
Step 4: Develop the Logic
Develop the Logic
Create step-by-step logic to solve the problem.
Step 5: Represent the Algorithm
Represent the Algorithm
Write the algorithm using natural language, pseudocode, or draw a flowchart.
Step 6: Test the Algorithm
Test the Algorithm
Test the algorithm with sample data to ensure it works for all cases.
Step 7: Refine and Debug
Refine and Debug
Check for errors and improve the algorithm if needed.
Step 8: Implement (Coding)
Implement (Coding)
Convert the algorithm into a program using any programming language.
Example — Find Largest of Two Numbers
Let's compare a good algorithm with a bad one for the same problem.
Good Algorithm (Clear & Correct) ✓
1. Start
2. Input two numbers A and B
3. If A > B then L = A
Else L = B
4. Print L
5. Stop
Why It's Good: Clear, complete, correct, and terminates.
Bad Algorithm (Vague & Confusing) ✗
1. Start
2. Take two numbers
3. Compare somehow
4. Do some processing
5. Display the largest number
6. Go to step 3
7. Stop (maybe)
Why It's Bad: Vague, infinite loop, unclear termination.
Characteristics of a Good Algorithm
A well-written algorithm satisfies these 9 essential characteristics.
| # | Characteristic | Focus | Goal |
|---|---|---|---|
| 1 | Input | Accept data | Valid input |
| 2 | Output | Produce result | Useful output |
| 3 | Definiteness | Clear steps | Unambiguous |
| 4 | Finiteness | End in finite steps | Termination |
| 5 | Effectiveness | Simple operations | Feasible |
| 6 | Generality | Work for all cases | Reusable |
| 7 | Correctness | Accurate result | Reliability |
| 8 | Efficiency | Less time & memory | Optimization |
| 9 | Simplicity | Easy to understand | Clarity |
More Complete Examples
Example 1: Check if a Number is Even or Odd
Natural Language
1. Start
2. Take a number N
3. If N is divisible by 2, then it's Even
4. Otherwise, it's Odd
5. Display the result
6. Stop
Pseudocode
START
INPUT N
IF N MOD 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
ENDIF
STOP
Example 2: Sum of First N Natural Numbers
Pseudocode
START
INPUT N
SUM ← 0
FOR i ← 1 TO N
SUM ← SUM + i
ENDFOR
PRINT SUM
STOP
Example 3: Calculate Factorial of N
Pseudocode
START
INPUT N
FACT ← 1
FOR i ← 1 TO N
FACT ← FACT * i
ENDFOR
PRINT FACT
STOP
Example 4: Find Area of a Rectangle
Pseudocode
START
INPUT L, B
AREA ← L * B
PRINT AREA
STOP
Comparison of Writing Methods
| Aspect | Natural Language | Pseudocode | Flowchart |
|---|---|---|---|
| Format | Plain English | English + keywords | Visual diagram |
| Ease of Writing | Very Easy | Moderate | Slower |
| Precision | Can be ambiguous | Precise | Very precise |
| Best For | Beginners, non-tech users | Programmers | Complex logic |
| Visual | No | No | Yes |
| Convertible to Code | Difficult | Easy | Medium |
Did You Know?
Interesting Fact
The word "Algorithm" comes from the name of the great mathematician Muhammad ibn Musa Al-Khwarizmi, who lived in the 9th century! His work on Indian numerals and calculation methods laid the foundation for modern computing.
Tips for Writing Better Algorithms
Best Practices
- Start by understanding the problem completely.
- Use clear and precise language.
- Number your steps for clarity.
- Include Start and Stop at the beginning and end.
- Handle edge cases (empty input, negative numbers).
- Use simple, everyday words in natural language.
- Choose the right format for your audience.
- Test with different inputs before coding.
- Keep it simple and readable.
- Refine based on feedback.
- Use tools like Draw.io for flowcharts.
- Practice with common problems (sum, factorial, prime, sorting).
Common Mistakes to Avoid
Mistake 1: Vague Steps
- "Compare somehow"
- "Do processing"
- Violates Definiteness
Mistake 2: No Termination
- Missing Stop step
- Infinite loops
- Violates Finiteness
Mistake 3: Missing Input/Output
- Not specifying inputs
- No clear output
- Incomplete algorithm
Mistake 4: Skipping Testing
- Not verifying with sample data
- Bugs remain undetected
- Fails at implementation
Mistake 5: Overcomplicating
- Too many nested conditions
- Complex when simple works
- Violates Simplicity
Mistake 6: Wrong Format
- Using flowchart for simple logic
- Using natural language for complex
- Choose based on need
Frequently Asked Questions
Q1. What are the 3 ways to write algorithms?
The 3 main ways are: Natural Language, Pseudocode, and Flowchart.
Q2. Which is the best way to write algorithms?
It depends on the audience. Use natural language for beginners, pseudocode for programmers, and flowcharts for complex visual logic.
Q3. What is pseudocode?
Pseudocode is a way to write algorithms using English-like statements with programming keywords like IF, THEN, ELSE, PRINT — without being tied to any specific programming language.
Q4. Is pseudocode a programming language?
No! Pseudocode is NOT a programming language. It cannot be executed. It's just a way to describe algorithms clearly.
Q5. When should I use a flowchart?
Use flowcharts for algorithms with complex decisions, loops, and multiple paths where visual representation helps understanding.
Q6. Can I write the same algorithm in all three ways?
Yes! The same algorithm can be represented in natural language, pseudocode, or flowchart. Each is a different way to express the same logic.
Q7. Do I need to write an algorithm before coding?
Highly recommended! Writing an algorithm helps you plan, avoid mistakes, and produce cleaner, more efficient code.
Q8. What tools can I use to draw flowcharts?
Popular tools include Draw.io, Lucidchart, Microsoft Visio, Canva, and even PowerPoint.
Q9. How long should an algorithm be?
An algorithm should be as long as needed to clearly express the logic — no more, no less. Focus on clarity, not length.
Q10. Can algorithms have loops and conditions?
Absolutely! Loops (FOR, WHILE) and conditions (IF, ELSE) are common constructs used in algorithms to handle repetition and decision-making.
Key Takeaways
- An algorithm is a step-by-step procedure to solve a problem.
- 3 ways to write: Natural Language, Pseudocode, Flowchart.
- Natural Language uses simple English.
- Pseudocode combines English with programming keywords.
- Flowcharts use symbols and arrows for visual logic.
- Follow 8 steps for systematic algorithm development.
- A good algorithm has 9 essential characteristics.
- Test with multiple inputs before coding.
- Choose the writing method based on audience and complexity.
- Practice regularly to improve your skills.
Key Takeaway
A good algorithm is clear, correct, efficient, and easy to
understand. It is the first step towards writing a
successful program. Master the three writing methods — Natural
Language, Pseudocode, and Flowchart — and you'll be equipped to
tackle any programming challenge.
⭐ UNDERSTAND THE ALGORITHM, MASTER THE PROGRAM! ⭐
Best of Luck! Practice more examples, think
logically, code confidently. You can do it!
Flowchart → Visual Thinking → Smart Solutions → Better
Results! 🚀
Home & Online Tuition
Learn from an experienced tutor with personalized guidance.
Available Locations
Expert Home & Online Tuition
Personalized one-to-one tuition that focuses on concept building, practical learning, problem-solving skills, and excellent academic performance. Suitable for school students looking for structured, interactive, and result-oriented learning.
Subjects We Teach
Why Choose Our Tuition?
✅ Concept-Based Learning
✅ Practical Examples
✅ Weekly Tests
✅ Doubt Solving Sessions
✅ Practice Worksheets
✅ MCQ & Assignments
✅ Exam Preparation
✅ Flexible Class Timings