Algorithm & Flowcharts
Algorithm & Flowcharts
ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།
Department of School Education
Ministry of Education & Skills Development
July 2023
Developed by Thinley & ICT teachers of Thimphu for ICT teachers of Bhutan as reference material
Algorithm
A step-by-step solution for specific problem
Why learn Algorithm?
❖ To understand the core idea behind a problem.
❖ To understand the flow of the problem.
❖ To give the designer a clear explanation of the needs and goal of the issue.
❖ To find a solution for the problem.
❖ To provide a straightforward explanation of how it works without getting into too
much technical detail.
❖ To analyze and evaluate the complexity (in terms of time and space) of a problem.
Algorithm
❖ An algorithm is a set of well-defined steps or instructions used to solve specific
problems or perform a particular task.
❖ Writing algorithms involves breaking down a complex problem into smaller and
more manageable steps. Usually, one of the following conventions is used while
writing algorithms:
○ Written descriptions.
○ Pseudo code.
❖ For an algorithm, you need to specify:
1) Input
2) Process
3) Output
Characteristics of Algorithm
❖ Clear: The steps in the algorithm should be easy to understand.
❖ Unambiguous: The steps in the algorithm should have only one possible
interpretation.
❖ Inputs: The algorithm should have one or more inputs.
❖ Outputs: The algorithm should have one or more outputs.
❖ Finite: The algorithm should terminate after a finite number of steps.
❖ Effective: The algorithm should produce the correct output for the given input.
❖ General: The algorithm should be able to work with different inputs and produce
the correct output.
❖ Independent: The algorithm should be independent of any programming
language.
Characteristics continue...
Example 1
Problem: Write an algorithm to multiply any two numbers and print the result.
STEP Algorithm
1 START
5 STOP/End
Example 2
❖ Design an algorithm to add any two numbers and display the result.
STEP Algorithm
1 START
3 addition = x + y
4 Print addition
5 STOP/End
Example 3
Problem: Write an algorithm to find the greatest of two numbers.
STEP Algorithm
1 START
3 Check if a>b:
5 Else:
7 STOP/End
Activities
Activity 1: Write an algorithm that adds two numbers.
Activity 4: Write an algorithm for finding the largest of any three given numbers.
Activity 5: Write an algorithm that prompts the user to input their exam marks and
determines whether they have passed or failed. The pass mark is 40 out of 100.
Answers
Activity 1: Write an algorithm that adds two numbers.
STEP Algorithm
1 START
3 addition = a + b
4 Print addition
5 STOP/End
Answers 2
Activity 2: Write an algorithm to find the area of the circle.
STEP Algorithm
1 START
3 area = PI*r**2
4 Print area
5 STOP/End
Answers 3
Activity 3: Write an algorithm to calculate the perimeter of a rectangle.
STEP Algorithm
1 START
4 Print perimeter
5 STOP/End
Answers 4
Activity 4: Write an algorithm for finding the largest of any three given numbers.
STEP Algorithm
1 START
7 else:
9 STOP/End
Answers 5
Activity 5: Write an algorithm that prompts the user to input their exam marks and
determines whether they have passed or failed. The pass mark is 40 out of 100.
STEP Algorithm
1 START
3 Check if m>=40:
4 Print ”Passed”
5 else:
6 Print “Failed”
7 STOP/End
Flowchart
Diagrammatic representation of an algorithm
Flowchart
❖ A flowchart is a diagrammatic representation of an algorithm. It is a way of
visualizing the steps involved in a process or task.
❖ A flowcharts can be helpful for both writing programs and explaining programs to
others.
1 START
Read any two numbers x, y
2 Read any two numbers x, y
3 addition = x + y
addition = x + y
4 Print addition
End
Example 2
Draw a flowchart to calculate the perimeter of a Square with side length of 5 units.
Algorithm 1. Flowchart
Step 1: START
Step 2: Store the value of a side in a variable named side
Step 3: Calculate and store the value of perimeter in the
variable named perimeter
Step 4: Display the perimeter
Step 5: END
Example 3
Draw a flowchart to check whether the entered age is eligible for casting the vote.
STEP Algorithm
1 START
2 Enter an age:
3 Check if age>=18:
5 else:
7 STOP/End
Activities
Activity 1: Draw a flowchart to find multiplication any numbers entered by the user.
Activity 4: Draw a flowchart to find the largest of any three numbers when a user reads
numbers from the keyboard.
Activity 5: Draw a flowchart that prompts the user to input their ICT exam mark and
determines whether they have passed or failed. The pass mark is 40 out of 100.
Answer 1
Activity 1: Draw a flowchart to find multiplication any numbers entered by the user.
START
multiplication = x * y
Print multiplication
End
Answer 2
Activity 2: Draw a flowchart to find the area of the circle.
START
area = PI*r**2
Print area
End
Answer 3
Activity 3: Draw a flowchart to calculate the perimeter of the rectangle.
START
perimeter = 2*(l+w)
Print perimeter
End
Answer 4
Activity 4: Draw a flowchart to find the largest of any three numbers when a user reads
numbers from the keyboard.
START
Check
Yes
x>y and x>z Print “x is greater than y and z”
No
Yes End
Check Print “y is greater than x and z”
y>x and y>z
No
Print “z is greater than x and
y”
Answer 4
Activity 4: Draw a flowchart to find the largest of any three numbers when a user reads
numbers from the keyboard.
End
Check
yes
x>y and x>z Read any three numbers x,y,z
No
Start
Check yes
Print “z is greater than x and y”
y>x and y>z
No
Print “y is greater than x and z”
Answer 5
Activity 5: Draw the flowchart that prompts the user to input their ICT exam mark and
determines whether they have passed or failed. The pass mark is 40 out of 100.
START
yes No
Check
m>=40
End