Algorithms, Pseudocodes and Flowcharts
October 13, 2022
Partido State University
1
Table of Contents
Problem Solving
2
Table of Contents
Problem Solving
3
A computer cannot think in the way we associate with humans.
When using the computer to solve a problem, you must specify the
needed initial data, the operations which need to be performed (in
order of performance) and what results you want for output. If any
of these instructions are missing, you will get either no results or
invalid results. In either case, your problem has not yet been
solved. Therefore, several steps need to be considered before
writing a program. These steps may free you from hours of finding
and removing errors in your program (a process called debugging).
It should also make the act of problem solving with a computer a
much simpler task.
4
The following steps are suggested to facilitate the problem solving
process:
1. Define the problem.
2. Formulate a mathematical model.
3. Develop an Algorithm
4. Coding
5. Testing and Debugging
5
Define the problem
It is important to give a clear, concise problem statement. The
problem definition should clearly specify the desired input and
output. This step demands that you have full knowledge of the
background of the problem you are attempting to solve
6
Formulate a mathematical model
Most technical problems can be modeled mathematically. An
existing model must be chosen or a new one developed if no
standard mathematical model exists. This step also requires full
knowledge of the problem and its underlying mathematical
concepts.
Examples
x1 + x2 + x3
Average =
3
N! = N(N − 1)(N − 2) · · · 1
7
Develop an algorithm
Algorithm
An algorithm is a set of well-defined instructions to solve a
particular problem. An algorithm takes a set of input(s) and
produces the desired output.
An algorithm may be expressed in either the following:
1. Human Language
2. Pseudocode
3. Flowchart
8
Pseudocode
Pseudocode
Pseudocode is an artificial and informal language that helps
programmers develop algorithms.
Pseudocode is very similar to everyday English.
Pseudocode is one method of designing or planning a program.
Pseudo means false, thus pseudocode means false code.
9
Example
Write a pseudocode that computes the area of square, given the
length of its side.
Pseudocode
1: Input length of side x
2: Area = x ∗ x
3: Print Area
10
Example
Write an algorithm to determine a student’s final grade and
indicate whether it is passing or failing.
11
Pseudocode
1: Input 4 grades x1 , x2 , x3 , x4
2: Calculate the average by adding the inputs and dividing by 4
3: If Average is less than 75
4: Print ”Fail”
5: Else
6: Print ”Pass”
12
Flowchart
A flowchart is a type of diagram that represents an algorithm,
workflow or process. It is also a diagrammatic representation
illustrates a solution model to a given problem.
13
Flowcharting Symbols
14
Flowcharting Symbols
15
Example
16
Example
Draw a flowchart that computes the area of square, given the
length of its side
17
18
Example
Draw a flowchart to input two numbers from the user and display
the largest of two numbers
19
20
Example
Draw a flowchart for computing the factorial of N.
Recall: The factorial of a number N is given by
N! = N(N − 1)(N − 2) · · · 1
21
22
Coding
Using the algorithm as a basis, the source code can now be written
using the chosen programming language.
Below is a sample code in Python.
23
Testing and Debugging
Make sure your program works as desired.
Run your program several times using different data sets.
Make sure it works correctly for every situation provided for in the
algorithm.
Rewrite source codes to eliminate errors, glitches or something
that causes the program to perform differently than expected.
24