0% found this document useful (0 votes)
9 views23 pages

Intro To Algorithms & Flowcharts Lesson 002

This document introduces algorithms and flowcharts, outlining their definitions, characteristics of good algorithms, and the importance of flowcharts in representing algorithms visually. It provides examples of algorithms for tasks such as cooking rice and calculating sums, as well as the symbols used in flowcharts and rules for creating them. The lesson concludes with a recap and a preview of upcoming content on Python programming.

Uploaded by

Samuel Fetor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views23 pages

Intro To Algorithms & Flowcharts Lesson 002

This document introduces algorithms and flowcharts, outlining their definitions, characteristics of good algorithms, and the importance of flowcharts in representing algorithms visually. It provides examples of algorithms for tasks such as cooking rice and calculating sums, as well as the symbols used in flowcharts and rules for creating them. The lesson concludes with a recap and a preview of upcoming content on Python programming.

Uploaded by

Samuel Fetor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

INTRODUCTION TO

ALGORITHMS &
FLOWCHARTS
LESSON OBJECTIVES
At the end of this lesson, I should;

 Be able to understand what an algorithm is


 Be able to understand and identify some characteristics of a
good computer program algorithm
 Be able to understand what a flow chart is.
 Be able to identify the symbols used in flowchart and their
meanings.
 Be able to identify the rules for drawing flowcharts
 Be able to represent algorithms on flowcharts.
ALGORITHM

 Have you ever given steps to guide someone to do something?


 Let’s assume someone wants to cook plain rice. State the steps
the person should follow to cook the plain rice.
 What do you know about the word recipe?
 Have you ever heard the word “Algorithm”? Share what you
know about it.
ALGORITHM

 An algorithm is a set of well-defined steps used to complete a


task.
 Algorithms help computer programmers better understand how
to write their instructions for the computer to perform a task.
 It is a simplified version of the steps the computer must follow
to perform a task.
 Algorithms can be likened to recipes for preparing meals
 As a computer programmer, it is very important for you to learn
CHARACTERISTICS OF A GOOD
ALGORITHM

 Well –defined inputs


 Well-defined outputs
 Well-defined processes
 Unambiguity: it should be precise & not opened to more than 1
interpretation
 Finiteness
 Language independence
 Feasibility: must be applicable/possible to do.
EXAMPLES OF ALGORITHMS
An algorithm for preparing plain rice

 Step [Link] the rice to be cooked.  Step 9. IF THE RICE IS BOILED THEN GOTO STEP 12
 Step 2. Procure the container. ELSE GOTO STEP 10
 Step 3. Procure the water. ENDIF
 Step 4. Wash the rice in the water.  Step 10. Heat the container.
 Step 5. Put the rice into the container.  Step 11. Go to step 9.
 Step 6. Pour water into the container.  Step 12. Turn off the flame.
 Step 7. IF WATER LEVEL = 1 INCH ABOVE THE RICE  Step 13. Move the container off the stove. Step
THEN GOTO STEP 8  14. Distribute the cooked rice.
ELSE GOTO STEP 6  Step 15. STOP.
ENDIF
 Light the burner on the stove.
EXAMPLES OF ALGORITHMS
An algorithm to calculate the sum of two
numbers.
1. Start
2. Input A, B (A represents the first number the user will enter and B
represents the second. A and B are known as variables which will be
discussed later)
3. Calculate the sum of the two numbers; S = A+B (note that S is a variable
used to store the sum of the two numbers)
4. Display the result of the calculation (S)
5. Stop
EXAMPLES OF ALGORITHMS
Write an algorithm to calculate the average of
two numbers.
1. Start
2. Input Num1 , Num2
3. Calculate the sum of the two numbers; S=Num1 + Num2
4. Calculate the average; Avg= S/2
5. Display Avg
6. Stop
EXAMPLES OF ALGORITHMS
Write an algorithm to calculate the volume of a
rectangular box.
1. Start
2. Input L, B, H
3. Calculate the Volume; V= L*B*H
4. Display V
5. Stop
FLOWCHART

 It is the pictorial representation of algorithms using predefined


symbols.
FLOWCHART SYMBOLS & THEIR
MEANINGS
FLOWCHART SYMBOLS & THEIR
MEANINGS
FLOWCHART SYMBOLS & THEIR
MEANINGS
GOLDEN RULES FOR WRITING
ALGORITHMS

● Only the standard symbols should be used in program flowcharts.


● The program logic should depict the flow from top to bottom and from left to
right.
● Each symbol used in a program flowchart should contain only one entry point
and one exit point, with the exception of the decision symbol. This is known as the
single rule.
● The operations shown within a symbol of a program flowchart should be
expressed independently of any particular programming language.
● All decision branches should be well-labeled.
FLOWCHARTS FOR ALGORITHMS
Flowchart to represent algorithm for calculating sum
of 2 numbers
Start

A represents the first number


Input A, B --------------
B represents the second number

S represents the sum of the 2


-------------
S = A+B numbers

Display S

END/STOP
FLOWCHARTS FOR ALGORITHMS
Flowchart to represent algorithm for calculating Average of 2
numbers
Start

Input A, B ------------------------------------
A represents the first number
B represents the second number

S stands represents the sum of the


S = A+B ------------------------------------
2 numbers

Avg = S/2 ------------------------------------ Avg represents the average of the


2 numbers

Display Avg

END/STOP
FLOWCHARTS FOR ALGORITHMS
Flowchart to show how a student’s registration number and grades in 3 subjects, m1, m2, and m3, are
displayed along with the total average grade.
FLOWCHARTS FOR ALGORITHMS
Flowchart to represent algorithm for calculating Average of 2
numbers
Start

Input REG-NO

Print “Enter grade


of three subjects

Input M1, M2, M3

T=M1+M2+M3

AVG=T/3

Print “Average Score is”, AVG,


“for student with regn. No. ”, REG-NO

END/STOP
FLOWCHARTS FOR ALGORITHMS
DECISION MAKING ALGORITHM FLOWCHARTS

Question: Draw the flowchart of a program that calculates the area of a


square. If the area is a number divisible by 2, it should display “Even
Number”, else it should display “Might be odd number”.
FLOWCHARTS FOR ALGORITHMS
DECISION MAKING ALGORITHM FLOWCHARTS

ANSWER Start

Input L

A = L*L

“Might be odd number” No Is A divisible Yes “Even number”


by 2?

END/STOP
QUICK RECAP

 An algorithm is a set of well-defined steps used to complete a


task.
 Algorithms can be likened to recipes for preparing meals
 Some characteristics of a good algorithm are; well defined
inputs, well defined processing, well defined outputs,
unambiguity, finiteness, feasibility etc.
 Flowchart is the pictorial representation of algorithms using
predefined symbols.
What is Next

 Introduction to Python programming language


 Python basic syntax
DALIJAY TECH HUB

You might also like