WRITING AN
ALGORITHM
ALGORITHM
• A formula or set of steps for solving a particular problem
• A logical sequence of steps that solve a problem
• It is used as a guide to solve problems
• Can be expressed in English like language called PSEUDOCODE
• Can be also expressed in graphical form called FLOWCHART
PROPERTIES OF AN ALGORITHM
FINITENESS There is an exact number of steps to be taken.
ABSENCE OF AMBIGUITY Every instruction is precisely described and clearly
specified
SEQUENCE OF EXECUTION Instructions are performed from start to bottom.
INPUT AND OUTPUT The unknown of the problem is specified and with
the expected outcome.
EFFECTIVENESS The solution prescribed is guaranteed to give a
correct answer and specified process is carried out.
SCOPE DEFINITION Applies to a specific problem or class of problem.
IPO MODEL
The Input-Process-Output Model presents the flow how data
entered by the user should be processed by the machine to
produce result.
Input-Process-Output MODEL
INPUT PROCESS OUTPUT
A requirement A computation or Provision of the
from the user action based from result
the input
Input-Process-Output MODEL
PROBLEM: Create a Program that will display the sum of two numbers.
SOLUTION: If we add 2 numbers x, y, then we get the sum of z.
INPUT PROCESS OUTPUT
Addition (+)
x, y z
x+y
PSEUDOCODE
• An artificial and informal language that helps programmers develop algorithms
• A shorthand notation for programming which uses a combination of informal
programming structures and verbal description of code
• Emphasis is placed on expressing the behavior or outcome of each portion of code
rather than on strict correct syntax
WRITING A PSEUDOCODE
Common Action Keywords in Writing Pseudocode
Several keywords are often used to indicate common input, output and processing
operations.
Input: READ, OBTAIN, GET
Output: PRINT, DISPLAY, SHOW
Compute: COMPUTE, CALCULATE, DETERMINE
Initialize: SET INIT
Add One: INCREMENT, BUMP
WRITING A PSEUDOCODE
PROBLEM 1: Create a Program that will display the sum of two numbers.
IPO CHART PSEUDOCODE
Input: x, y Start
Process: Addition (x+y=z) SET the values x and y
Output: z GET the values x and y
COMPUTE oft the value of z “x+y=z”
PRINT z
End
WRITING A PSEUDOCODE
PROBLEM 2: Write a program that would tell the grade of a student if “PASSED” or
“FAILED”.
IPO CHART PSEUDOCODE
Input: grade Start
Process: Decision Making INIT student grade
grade >=75 or <75 READ student grade
CALCULATE grade if greater than or equal to 75
Output: PASSED or FAILED
PRINT “PASSED” else PRINT “FAILED”
End
WRITING A PSEUDOCODE
PROBLEM 3: Create an IPO chart, Pseudocode and Flowchart of a program showing the steps on
making a glass of orange juice.
IPO CHART PSEUDOCODE
Input: powdered juice, glass water, spoon GET powdered juice, glass, water, spoon
Process:
POUR powdered juice into glass
• pour powdered juice into glass
• fill up glass to top with water FILL UP glass to top with water
• stir the mixture STIR the mixture
Output: orange juice DISPLAY orange juice
FLOWCHARTING
• One of the processes used in designing or planning the solution to a
problem
• A graphical representation to the solution of the problem
• Uses shapes to show instructions and arrow lines and heads to display
the flow
FLOWCHARTING GUIDELINES
1. The flowchart should flow from top to bottom.
2. If the chart becomes complex, utilize connecting blocks
3. Avoid intersecting flowlines.
4. Use meaningful description in the symbol.
FLOWCHARTING SYMBOLS
INPUT
TERMINAL INITIALIZATION
OUTPUT
PROCESS DECISION
OFF-PAGE
ON-PAGE
CONNECTOR
FLOW LINES CONNECTOR
FLOWCHARTING SYMBOLS
TERMINATOR Indicates the start and end of the algorithm.
INITIALIZATION Used to represent starting values of variables.
INPUT Used to represent any of the devices used to accept or give our
OUTPUT data.
FLOWCHARTING SYMBOLS
PROCESS Used to represent an operation or a procedure
DECISION Used to evaluate condition and decide for a course of action
Connects the steps of the flowchart and indicates the sequence of
FLOW LINES
procedures,
FLOWCHARTING SYMBOLS
ON-PAGE connects one step of the flowchart to another step on the same
CONNECTOR
page.
OFF-PAGE Connects one step of the flowchart to another step on the other
CONNECTOR
page.
NOTATIONS IN FLOWCHARTING
Notation Meaning Notation Meaning
+ Addition = equal
- Subtraction > greater than
* Multiplication < less than
/ Division <> , ≠ not equal to
^ Exponentiation >= greater than or equal
mod modulus / remainder <= less than or equal
div integer div & logical AND
| logical OR
DESIGNING PROGRAMS
Creating a Flowchart
PROBLEM 1: FLOWCHART
Create a Program that will display the sum of
two numbers.
DESIGNING PROGRAMS
Creating a Flowchart
PROBLEM 2: FLOWCHART
Write a program that would tell the grade of a
student if “PASSED” or “FAILED”.
DESIGNING PROGRAMS
Creating a Flowchart
PROBLEM 3: FLOWCHART
Create a flowchart of a program showing the
steps on making a glass of orange juice.
END
ALGORITHM and PROGRAM
ALGORITHM PROGRAM
Method to solve a Implementation of
problem. algorithm.
ALGORITHM vs PSEUDOCODE
ALGORITHM PSEUDOCOD
E
Specific steps or
procedures. Representation of
algorithm which uses
programming-like natural
language.
REFERENCES
Innovative Training Works, Inc. (2017). Computer Programming Volume II. Rex Book
Store, Inc.
Siapno, R., Pineda, J., and Barberan, B., (2019). Programming Using VB.Net
Technology. iBook Publishing, Inc.