- Get link
- X
- Other Apps
Recent - Posts
- Get link
- X
- Other Apps
Algorithm & Flowchart
![]() |
| Algorithm and Flowchart |
Level 2 – Intermediate
Before continuing please visit: Algorithm and Flowchart For students From Basic to Advanced (Level - 1)
Formal Concept of Algorithm
More Formal Definition:
An algorithm is:
A finite sequence of well-defined instructions, written in a specific order, that takes some input and produces an output to solve a particular problem.
Properties of an Algorithm
Input
- An algorithm requires one or more inputs.
- Example: Numbers A and B for an addition algorithm.
Output
- An algorithm generates a minimum of one output.
- Example: Sum of A and B
Definiteness (Clarity)
- Every step must be clear and unambiguous.
- No unclear or perplexing directions.
Finiteness
- The algorithm must complete after a fixed number of steps.
- It should not go on forever.
Effectiveness
- Every step needs to be easy enough to complete with simple procedures.
- No “magic” or impossible steps.
Algorithm Examples
Example 1: Sum of First N Natural Numbers
Problem: Find the sum of first N natural numbers (1 + 2 + 3 + ... + N).
Algorithm :
Step 1: Start.
Step 2: Read N.
Step 3: Set Sum = 0.
Step 4: Set i = 1.
Step 5: Repeat the following steps while i ≤ N:
Add i to Sum (Sum = Sum + i).
Increase i by 1 (i = i + 1).
Increase i by 1 (i = i + 1).
Step 6: When i > N, stop the loop.
Step 7: Display Sum.
Step 8: End.
Example 2: Check If a Number Is Even or Odd
Problem: Read a number and check whether it is even or odd.
Algorithm:
Step 1: Start.
Step 2: Read a number N.
Step 3: Calculate Remainder = N mod 2.
Step 4: If Remainder = 0, then
N is Even.
Display “Even”.
Step 5: Otherwise,
N is Odd.
Display “Odd”.
Step 6: End.
Example 3: Find the Largest of Three Numbers
Problem: Given three numbers A, B, C, find the largest.
Algorithm:
Step 1: Start.
Step 2: Read A, B, C.
Step 3: Assume A is the largest. Set Largest = A.
Step 4: If B > Largest, then set Largest = B.
Step 5: If C > Largest, then set Largest = C.
Step 6: Display Largest.
Step 7: End.
Concept of Flowchart
A flowchart uses common symbols and arrows to depict an algorithm.
Common Flowchart Symbols
Example 2: Find the Largest of Three Numbers
Problem: Read three numbers A, B, C and find the largest.
Algorithm:
Step 1: Start.
Step 2: Read A, B, C.
Step 3: Set Largest = A.
Step 4: If B > Largest, then Largest = B.
Step 5: If C > Largest, then Largest = C.
Step 6: Display Largest.
Step 7: End.
Example 3: Calculate Factorial of a Number
Problem: Find factorial of a positive integer N.
Factorial N! = 1 × 2 × 3 × … × N.
Algorithm
Step 1: Start.
Step 2: Read N.
Step 3: Set Fact = 1.
Step 4: Set i = 1.
Step 7: While i ≤ N, do:
Fact = Fact × i.
i= i + 1.
Step 5: When i > N, stop loop.
Step 6: Display Fact.
Step 7: End.
Example 4: Sum of First N Natural Numbers
Problem: Find the sum S = 1 + 2 + 3 + … + N.
Algorithm:
Step 1: Start.
Step 2: Read N.
Step 3: Set Sum = 0.
Step 4: Set i = 1.
Step 5: While i ≤ N:
Sum = Sum + i.
i = i + 1.
Step 6: Display Sum.
Step 7: End.
Example 5: Display Grade Based on Marks
Problem: Read a student’s marks (0–100) and display grade:
Marks ≥ 90 : Grade A
Marks ≥ 75 and < 90 : Grade B
Marks ≥ 50 and < 75 : Grade C
Marks < 50 : Grade D
Algorithm:
Step 1: Start.
Step 2: Read Marks.
Step 3: If Marks ≥ 90,
display “Grade A”.
Step 4: Else if Marks ≥ 75,
display “Grade B”.
Step 5: Else if Marks ≥ 50,
display “Grade C”.
Step 6: Else display “Grade D”.
Step 7: End.
Difference Between Algorithm and Flowchart
Comparison Table
| Feature | Algorithm | Flowchart |
|---|---|---|
| Form | Written in words or pseudocode | Diagram with symbols and arrows |
| Appearance | Text, step-by-step list | Visual / graphical representation |
| Ease of Writing | Easier and faster to write | Takes more time to draw neatly |
| Ease of Understanding | Good for people comfortable with text | Very good for visual learners |
| Level of Detail | Can be very detailed in words | Focuses on structure and flow |
| Use in Planning | First step in planning a solution | Next step to visualize the algorithm |
| Modification | Easier to edit or insert steps | Editing may require redrawing connections |
| Use in Programming | Helps convert to code | Helps think about logic and branching |
When to Use Which
Use an algorithm when:
- You want a quick rough design in words.
- You will later convert it into a flowchart or program code.
- Use a flowchart when:
- You need to present or teach the solution.
- You want to debug or check for missing paths or steps.
- You want to show the logic clearly to someone else.
- You are first planning the solution.
- Often, we write the algorithm first, then draw the flowchart, and finally write the program.
Common Mistakes Made by Students
In Algorithms
- Missing Start or End (no clear beginning or conclusion).
- Writing steps in wrong order.
- Skipping important steps (e.g., not reading input).
- Using unclear language (e.g., “do it correctly” without saying how).
- Mixing multiple actions in one step, making it hard to understand.
In Flowcharts
- Forgetting Start or End terminators.
- Using wrong symbols (e.g., using a rectangle instead of a diamond for a decision).
- Missing Yes/No branches from a decision.
- Arrows crossing too much and making the flowchart messy.
- Arrows not clearly showing the direction of flow.
- Loops that do not lead back properly (missing arrow returning to decision).
Tips to Avoid Mistakes
- Always plan: Input → Process → Output.
- Check if every decision has two exits (Yes/No or True/False).
- Make sure there is only one Start and one End.
- Read your algorithm/flowchart as if you are the computer:
- Can you follow each step without guessing?
- Use a rough draft first, then draw a clean final version.
Practice Questions – Level 2
A. Question Set (20 Questions)
- Write an algorithm to find the largest of two numbers.
- Write an algorithm and draw/describe a flowchart to find the largest of three numbers.
- Write an algorithm to calculate the factorial of a number N.
- Write an algorithm and flowchart to check whether a number is even or odd.
- Write an algorithm to find the sum of first N natural numbers.
- Write an algorithm and flowchart to calculate the average of 5 subject marks.
- Write an algorithm to check whether a given number is positive, negative or zero.
- Write an algorithm and flowchart to display the grade of a student based on marks (A/B/C/D, like earlier).
- Write an algorithm to find the smallest of three numbers.
- Write an algorithm and flowchart to read 10 numbers and find their sum (you may assume we read them one by one).
- Write an algorithm to check whether a given year is a leap year or not.
- Write an algorithm and flowchart to swap the values of two variables A and B using a temporary variable.
- Write an algorithm to find the square of a number without using multiplication (use repeated addition).
- Write an algorithm to count how many of 5 entered numbers are positive.
- Write an algorithm and flowchart to print numbers from 1 to N.
- State and explain the properties of a good algorithm.
- Explain the use of the decision symbol (diamond) in a flowchart with an example.
- What is the difference between input symbol and process symbol in a flowchart?
- Why should every algorithm and flowchart have a finite number of steps?
- List at least five common mistakes students make in flowcharts and how to avoid them.
Solutions:
Q1. Algorithm to Find Largest of Two Numbers
Problem: Given two numbers A and B, find the larger one.
Algorithm:
Step 1: Start.Step 2: Read A and B.
Step 3: If A > B, then
Display “A is largest” (or display A).
Step 4: Else
Display “B is largest” (or display B).
Step 5: End.
Q2. Algorithm and Flowchart – Largest of Three Numbers
We already described this earlier, but summarizing:
Algorithm:
Step 1: Start.
Step 1: Start.
Step 2: Read A, B, C.
Step 3: Set Largest = A.
Step 4: If B > Largest, then Largest = B.
Step 5: If C > Largest, then Largest = C.
Step 6: Display Largest.
Step 7: End.
Q3. Algorithm – Factorial of a Number N
I have already explained about it in detail, here below is a compact version.
Algorithm:
Step 1: Start.Step 2: Read N.
Step 3: Set Fact = 1.
Step 4: Set i = 1.
Step 5: While i ≤ N:
Fact = Fact × i.
i = i + 1.
i = i + 1.
Step 6: Display Fact.
Step 7: End.
Q4. Algorithm and Flowchart – Even or Odd
I have described it in detail, here is a compact version of it.
Algorithm:
Step 1: Start.Step 2: Read N.
Step 3: If N mod 2 = 0:
Display “Even”.
Step 4: Else:
Display “Odd”.
Step 5: End
Q5. Algorithm – Sum of First N Natural Numbers
I have done it in detailed previously, here is a another (loop) version of it.
Algorithm (Loop Method):Step 1: Start.
Step 2: Read N.
Step 3: Sum = 0.
Step 4: i = 1.
Step 5: While i ≤ N:
Sum = Sum + i.
i = i + 1.
i = i + 1.
Step 6: Display Sum.
Step 7: End.
Q6. Algorithm and Flowchart – Average of 5 Subject Marks
Problem: Read marks of 5 subjects and display the average.Algorithm:
Step 2: Read marks M1, M2, M3, M4, M5.
Step 3: Total = M1 + M2 + M3 + M4 + M5.
Step 4: Average = Total / 5.
Step 5: Display Average.
Step 6: End.
Q7. Algorithm – Check Positive, Negative or Zero
Problem: Read a number N and say if it is positive, negative or zero.
Algorithm:
Step 2: Read N.
Step 3: If N > 0, display “Positive”.
Step 4: Else if N < 0, display “Negative”.
Step 5: Else display “Zero”.
Step 6: End.
Q8. Algorithm and Flowchart – Grade of a Student
Step 1: Start.
Step 2: Read Marks.
Step 3: If Marks ≥ 90,
display “Grade A”.
Step 4: Else if Marks ≥ 75,
display “Grade B”.
Step 5: Else if Marks ≥ 50,
display “Grade C”.
Step 6: Else display “Grade D”.
Step 7: End.
Q9. Algorithm – Smallest of ThreeNumbers Flowchart
Problem: Find the smallest of A, B, C.Algorithm:
Step 2: Read A, B, C.
Step 3: Set Smallest = A.
Step 4: If B < Smallest,
then Smallest = B.
Step 5: If C < Smallest,
then Smallest = C.
Step 6: Display Smallest.
Step 7: End.
Algorithm:
Step 1: Start.
Q10. Algorithm and Flowchart – Read 10 Numbers and Find Their Sum
Problem: Read 10 numbers and find their sum.
Algorithm:
Step 1: Start.Step 2: Sum = 0.
Step 3: Count = 1.
Step 4: While Count ≤ 10:
Read Number.
Sum = Sum + Number.
Count = Count + 1.
Sum = Sum + Number.
Count = Count + 1.
Step 5: Display Sum.
Step 6: End
Hints
Q11: Leap Year Algorithm (Hint)
- A year is a leap year if:
- (Year is divisible by 400) OR
- (Year is divisible by 4 AND not divisible by 100).
Use temp:
- temp = A
- A = B
- B = temp
Q13: Square by Repeated Addition (Hint)
- Square of N = N × N.
- Use a loop to add N to Sum, N times.
Q14: Count Positive Numbers (Hint)
- Use a loop for 5 numbers. Each time:
- Read number
- If number > 0, increase PositiveCount.
Q15: Print 1 to N (Hint)
- Use a loop with a counter i from 1 to N.
- Output i each time.
Q16: Properties of a Good Algorithm (Answer)
- Input, Output, Definiteness, Finiteness, Effectiveness (already explained above).
Q17: Use of Decision Symbol (Answer)
- Used when we must choose between paths based on a condition (Yes/No, True/False).
- Example: “Is N mod 2 = 0?” leading to Even or Odd.
Q18: Input vs Process Symbol (Answer)
- Input/Output (parallelogram): reading values from user or displaying results.
- Process (rectangle): performing calculations or operations (e.g., Sum = A + B).
Q19: Finite Steps (Answer)
- If there are infinite steps, the algorithm/flowchart will never finish, so we never get an answer.
- A solution must complete in a finite number of steps.
Q20: Common Flowchart Mistakes (Answer)
- Examples: no Start/End, wrong symbols, missing arrows, incorrect decision branches, messy layout.
- Avoid by planning, checking each path, and using correct symbols.
Goto : Part - 1
Algorithm
computer science
Flowchart
Flowchart Symbols
Intermediate
Level-2
mathematics
Programming
Programming tools
programs
- Get link
- X
- Other Apps













Comments