Algorithm and Flowchart For students From Basic to Advanced (Level - 2)

 

Algorithm & Flowchart

Algorithm and Flowchart
Algorithm and Flowchart

Level 2 – Intermediate

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).

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     


Basic Rules for Flowcharts

  • Flow usually goes from top to bottom and left to right.
  • Every flowchart should have one Start and one End.
  • Use arrows to clearly show how to move from one step to the next.
  • Decisions should have two branches: commonly Yes/No or True/False.
  • Avoid using too many crossing lines and keep it tidy and readable.

Flowchart Examples 

Example 1: Check If a Number Is Even or Odd.
Problem: Read a number N and check if it is even or odd.
                                                                                                              
Even or Odd
Algorithm:                                               

Step 1: Start.

Step 2: Read N.

Step 3: If N mod 2 = 0, then
             Display “Even”.

Step 4: Else
             Display “Odd”.

Step 5: End.  

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

FeatureAlgorithmFlowchart
FormWritten in words or pseudocodeDiagram with symbols and arrows
AppearanceText, step-by-step listVisual / graphical representation
Ease of WritingEasier and faster to writeTakes more time to draw neatly
Ease of UnderstandingGood for people comfortable with textVery good for visual learners
Level of DetailCan be very detailed in wordsFocuses on structure and flow
Use in PlanningFirst step in planning a solutionNext step to visualize the algorithm
ModificationEasier to edit or insert stepsEditing may require redrawing connections
Use in ProgrammingHelps convert to codeHelps 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)

  1. Write an algorithm to find the largest of two numbers.
  2. Write an algorithm and draw/describe a flowchart to find the largest of three numbers.
  3. Write an algorithm to calculate the factorial of a number N.
  4. Write an algorithm and flowchart to check whether a number is even or odd.
  5. Write an algorithm to find the sum of first N natural numbers.
  6. Write an algorithm and flowchart to calculate the average of 5 subject marks.
  7. Write an algorithm to check whether a given number is positive, negative or zero.
  8. Write an algorithm and flowchart to display the grade of a student based on marks (A/B/C/D, like earlier).
  9. Write an algorithm to find the smallest of three numbers.
  10. Write an algorithm and flowchart to read 10 numbers and find their sum (you may assume we read them one by one).
  11. Write an algorithm to check whether a given year is a leap year or not.
  12. Write an algorithm and flowchart to swap the values of two variables A and B using a temporary variable.
  13. Write an algorithm to find the square of a number without using multiplication (use repeated addition).
  14. Write an algorithm to count how many of 5 entered numbers are positive.
  15. Write an algorithm and flowchart to print numbers from 1 to N.
  16. State and explain the properties of a good algorithm.
  17. Explain the use of the decision symbol (diamond) in a flowchart with an example.
  18. What is the difference between input symbol and process symbol in a flowchart?
  19. Why should every algorithm and flowchart have a finite number of steps?
  20. 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 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.

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.

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 1: Start.

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 1: Start.

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           
                      

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.
Q9. Algorithm – Smallest of ThreeNumbers   Flowchart
Problem: Find the smallest of A, B, C.

Algorithm:                                                                                                           

Step 1: Start.

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.


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.

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).
Q12: Swapping Two Variables (Hint)    

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

Comments