1
Algorithm Development:
Pseudocodes and Flowcharts
ES-CFPL
CES 1102L
IES 2201L
© 2019
2
Algorithm
Algorithm (after Al Kho-war-iz-mi a 9th century Persian mathematician) is
an ordered sequence of unambiguous and well-defined instructions that
performs some task and halts in finite time
▪ an ordered sequence means that you can number the steps (it's socks then shoes!)
▪ unambiguous and well-defined instructions means that each instruction is clear,
do-able, and can be done without difficulty
▪ performs some task
▪ halts in finite time (algorithms terminate!)
3
Algorithm Presentation
▪ Use natural languages
▪ too verbose
▪ too "context-sensitive"- relies on experience of reader
▪ Use formal programming languages
▪ too low level
▪ requires us to deal with complicated syntax of programming language
▪ Pseudo-Code
▪ natural language constructs modeled to look like statements available in many
programming languages
▪ Use flowchart
4
Pseudo-Code
▪ is an English-like representation of the logical steps it takes to
solve a problem.
▪ Pseudo is a prefix that means false, and to code a program
means to put it in a programming language;
▪ pseudocode simply means false code, or sentences that
appear to have been written in a computer programming
language but do not necessarily follow all the syntax rules of
any specific language.
5
Pseudo-Code
▪ Simply a numbered list of instructions to perform some task
▪ three standards for good pseudo code
▪ Number each instruction. This is to enforce the notion of an ordered sequence of ...
operations.
▪ Each instruction should be unambiguous (that is the computing agent, in this case
the reader, is capable of carrying out the instruction) and effectively computable
(do-able).
▪ Completeness. Nothing is left out.
▪ KEYWORD statement, variable/expression/equations
6
Example
▪ The process in going to school from home: Write a pseudo-code
for your routine from home going to school.
7
Example ALGORITHM RULES
1. Performs some task?
2. An ordered sequence?
BEGIN 3. Well-defined instructions?
1 GET jeepney route 4. Halts in finite time?
2 WAIT for the jeepney to arrive
3 CHECK IF the jeepney arrived is the same route you are taking
3.1 CHECK IF there’s a space
3.1.1 IF yes, you take the ride
3.1.2 IF no, go back to step 2
4 WAIT for your destination
5 CHECK IF the destination is the school
5.1 IF yes, you signal the driver to stop
5.2 IF no, go back to step 5
6 GET out of the jeepney
END
Flowchart Definition and Shapes
▪ A flowchart is a graphical or symbolic representation of an algorithm
showing the steps as boxes of various kinds, and their order by connecting
these with arrows.
9
Terminator
▪ It tells where the flowchart begins and ends.
▪ It shows the entry and exit points of the flowchart.
▪ It indicates the start and stop of a code block
▪ The text it contains is one of the ff:
▪ The name of the module it starts
▪ The keyword “End”, w/c is used
only once in a program
▪ The keyword “Return”, used at the
end of modules to transfer control
back to the calling module
10
Data Input / Output
▪ A parallelogram is used to show input or output.
▪ Examples of input are receiving a report, getting an e-mail, getting an
order, receiving data in some format, etc.
▪ Examples of output are generating a report, sending an e-mail, faxing a
message, etc.
11
Process
▪ It is used to show a process, task, action, or operation.
▪ The text in the rectangle almost always includes a verb
(action to be taken).
▪ Used to represent a process or a single step in an algorithm
▪ It contains the name or the description of a simple process
▪ Used only for simple processes
12
Decision
▪ This symbol represents a true/false question that controls the flow of the
program logic.
▪ It contains the condition that it represents.
▪ The top vertex represents the entry point.
▪ Only two lines should be exiting the
symbol that represent the logic paths
to be followed for the true or false
states as appropriate.
▪ Always used in selection or
repetition structures.
13
Flowlines
▪ You read a flowchart by following the lines
with arrows from shape to shape.
▪ They connect the other symbols to show
the flow of logic control from one part
of the solution to another.
14
On-Page Connector
▪ If you need to connect to another section of the chart,
and can't draw a line.
▪ You draw the line to the circle and label the circle with a letter. Then you
place a copy of the circle where you want the flow to continue.
AD BC
AD AD
Connected Not Connected
15
Off-Page Connector
▪ This shape means the flow continues on another page.
▪ A letter or page number in the shape tells you where to go.
▪ It is an alternative to using a circle.
AB
AB
Page X Page Y
16
Predefined Process
▪ Used to represent a subroutine or a pre-defined process.
▪ It always contains the name or description of the subroutine or process it
represents. This process must be described separately.
17
Preparation
▪ As the names states, any process step
that is a preparation process flow step,
such as a set-up operation.
18
Basic Flowchart Control Structures
❑Sequential
❑Branching
❑Loops & Counters
19
Basic Control Structures
SEQUENTIAL
Process 1
Process 2
20
Basic Control Structures
SEQUENTIAL EXAMPLE
▪ Write a pseudocode and draw a flowchart to
compute the corresponding area of the circle from
the given radius. Print out the value of the radius and
the area.
21
Basic Control Structures
SEQUENTIAL EXAMPLE
START
1. INITIALIZE pi, pi = 3.14159
2. READ radius of a circle, r
3. COMPUTE for the area of the circle, area = pi*r2
4. WRITE the radius and area of the circle, r and area
END
22
START BEGIN
Basic Control Structures
SEQUENTIAL EXAMPLE INITIALIZE pi, SETUP pi,
pi = 3.14159 pi = 3.14159
READ GET
radius of a circle radius of a circle
COMPUTE for area of the circle CALCULATE for area of the circle
area = pi * r * r area = pi * r * r
WRITE the radius and DISPLAY the radius
area of the circle; and area of the circle;
r and area r and area
END END
23
BEGIN
Basic Control Structures
SEQUENTIAL EXAMPLE SETUP pi,
pi = 3.14159
BEGIN
GET
radius of a circle
SETUP pi,
pi = 3.14159
CALCULATE for area of the circle
area = pi * r * r
GET
END
radius of a circle
DISPLAY the radius
and area of the circle;
DISPLAY the radius r and area
CALCULATE for area of the circle
and area of the circle;
area = pi * r * r
r and area
END
24
Basic Control Structures
SEQUENTIAL EXAMPLE
BEGIN
DISPLAY the radius
and area of the circle;
SETUP pi, r and area
pi = 3.14159
END
GET
radius of a circle
CALCULATE for area of the circle
area = pi * r * r
25
Basic Control Structures
BRANCHING
Conditional YES
▪ This structure is called a decision,
NO
"If Then.. Else" or a conditional.
▪ A question is asked in the decision shape.
Depending on the answer the control
follows either of two paths.
▪ Paths are usually labeled with words
"Yes" and "No" or "True" and "False“.
26
Basic Control Structures
BRANCHING
Case / Selection
▪ if there are several outputs, then Case A Case B Case C Case Else
using multiple decisions makes
the chart too busy.
▪ Since the case structure can be
constructed using the decision
structure, it is superfluous, but useful.
▪ It helps make a flowchart more
readable and saves space on the
paper.
27
Basic Control Structures
LOOPS AND COUNTER
Looping
▪ Used when it is desired to make the same calculation of
more than one set of data. It consists of repeating a
program, or a section of program and substituting new
data for each repetition.
Counter
▪ Is a setup in a program loop to keep track of a number
of times the program segment is repeated. The
program can then be terminated after the completion
of a predetermined number of passes.
28
Basic Control Structures
LOOPS AND COUNTER
Steps in Loop Control
▪ Initialization
▪ The value of counter is initially set equal to zero or one.
▪ Test for limit condition
▪ Before the logic flow gets out of a loop, a loop terminating
condition must first be satisfied.
▪ Incrementation
▪ Often each loop is executed, 1 is added to the counter. Thus
counter reflects the number of times the operation has been
performed.
29
Example: Computing a Quiz Average
Write a pseudo-code and flowchart for a routine to calculate your
quiz average.
▪ variables: number of quizzes, sum ,count, quiz grade, average
30
Example: Computing a Quiz Average
START Steps in Loop Control
1. GET number of quizzes, n
2. INITIALIZE sum, sum = 0 1. Initialization
3. INITIALIZE count, count = 0 2. Test for limit condition
4. WHILE count < number of quizzes
3. Incrementation
4.1 GET quiz grade, qGrade
4.2 COMPUTE sum, sum = sum + qGrade
4.3 INCREMENT count, count = count + 1
5. COMPUTE for average, ave = sum / n
6. DISPLAY average, ave
END
31
Steps in Loop Control
1. Initialization
2. Test for limit condition
Example: Computing a Quiz Average 3. Incrementation
START A B
GET number of
quizzes, nQuiz GET quiz grade, COMPUTE quiz average,
qGrade Ave = sum / nQuiz
INITIALIZE sum,
sum = 0 COMPUTE sum, DISPLAY average,
sum = sum + qGrade Ave
INITIALIZE count,
INCREMENT count, END
count = 0
count = count + 1
Lp
TRUE FALSE
count < nQuiz? Lp
A B
32
Seatwork: Sequential Flow Algorithms
Algorithm
▪ Pseudocode
▪ Flowcharting
33
Questions?
You can leave the questions via Google Meet
Chat box or Canvas Inbox Messaging Tool
34
35