Lecture 02
Problem Solving with
Algorithms
Prepared by Ban Kar Weng (William)
PDLC
Program Development Life Cycle
What is PDLC ?
1 Analysis • A set of phases that are
used to develop a
program.
2 Design
• Phase 1 - 4 are repeated
until any problems
3 Development encountered during the
development are solved.
4 Testing
5 Documentation
What is PDLC ?
1 Analysis All about the What.
• What the user wants from
the program?
2 Design • What is the input and
output of the program?
3 Development
Tasks Involved
• Gather user requirements
4 Testing
5 Documentation
What is PDLC ?
1 Analysis All about the How.
• How to fulfill what the user
wants?
2 Design • How the program is going
to achieve it?
3 Development
Tasks Involved
• Algorithm Design (using
4 Testing flowchart, pseudocode, or
other design tools.)
5 Documentation
What is PDLC ?
1 Analysis All about Code.
• Implement the algorithm
using programming
2 Design language(s)
Tasks Involved
3 Development
• Translate the algorithm
design into a programming
4 Testing language
5 Documentation
What is PDLC ?
1 Analysis All about Correctness.
• Test if the program does
what the user wants
2 Design correctly.
Tasks Involved
3 Development
• Check program’s output
and debug when needed.
4 Testing • Repeat Phase 1 if
enhancements are
required.
5 Documentation
What is PDLC ?
1 Analysis All about Recall.
• Ensure that programmers
able to recall what the
2 Design codes does in the future.
Tasks Involved
3 Development
• Generate written
documentations.
4 Testing • Improve source code
comments
5 Documentation
Algorithm
Representations
Algorithm Representations
How to represent or express algorithms?
Algorithm
Representation
Pseudocode Flowchart Program
Design Design Development
Pseudocode
Pseudocode
• Informal, high-level description of an algorithm.
• Not executable by computers.
• Allows precise description of algorithm without
worrying about the a programming language’s
syntax
Definition adopted from https://blog.usejournal.com/how-to-write-pseudocode-a-beginners-guide-29956242698 and C++ How to Program (8th Ed.) by Deitel and Deitel
Pseudocode: Examples
Example 1: Write a program that accepts an integer and outputs the
integer
Version 1:
INPUT an integer
OUTPUT the integer
Version 2:
INPUT X
OUTPUT X
Pseudocode: Examples
Example 2: Write a program calculating the sum of two integers
Version 1:
INPUT the first integer
INPUT the second integer
ADD the first integer and second integer, store result.
OUTPUT result
Version 2:
INPUT First
INPUT Second
Sum = First + Second
OUTPUT Sum
Flowchart
Flowchart
What do you understand
from the flowchart on
the right?
In what situation would I
“Watch TV” only once?
What happens if there is
truly no homework?
Flowchart
• A visual representation that shows the flow of the steps in
an algorithm.
• Consists of a flow of interconnected symbols.
• Not directly executable by computers.
• Easy to understand.
• Applied in computing and non-computing domain.
Flowchart
• How flowchart is designed depends on the intended
purpose.
For human, the instructions in the symbols can be general.
For machine, the instructions in each symbols must be convertible
to a programming language.
In the subsequent discussions, we assume that the flowchart
is intended for representing algorithms that will be
implemented in a machine.
Flowchart: Common Symbols (Part
1)
Diagram Name Description
Flow Connects symbols to show the algorithm flow.
Terminal Indicates the program’s start and end.
(i.e. )
start end
Input/Output Used to input data into the system or output data.
Process A process / action to be performed.
(e.g. a calculation or the assignment of a value)
Flowchart: The Input / Output
Symbol
• Input : Obtain data from an input device.
Variabl
e
Get N
• Output : Display data to an output device
Variabl
Value
e
Show “Hello” Show N
NOTE: “Get” or “Show” may be replaced with any word as long as it is unambiguous.
Flowchart: The Process Symbol
Indicates a particular operation.
In computing, this represents a CPU operation. The common ones
include: Variabl
e
• Assignment operation y <- 1 y <- x
• Arithmetic operation y <- x + 1 y <- y * x
Flowchart: Examples
Example 3: Start
Draw a flowchart that
accepts an integer and
outputs the integer To be demonstrated
live
Flowchart: Examples
Example 3: Start
Draw a flowchart that
accepts an integer and
outputs the integer
Flowchart: Examples Start
Example 4:
Draw a flowchart that
calculates the sum of two
To be demonstrated
integers
live
Flowchart: Examples Start
Example 4:
Draw a flowchart that
calculates the sum of two
integers.
Flowchart: Common Symbols (Part
2)
Diagram Name Description
Connector Connects separate flows in the same page.
Decision A yes/no question to be answered.
The program flow will then branch into one of
two paths, depending on the answer.
Flowchart: The Decision Symbol
Indicates a branching point. Lines coming out from the symbol
indicates different possible situations.
In computing, this symbol is often used evaluates Boolean expression,
so there are only two possible outcome: true or false (yes or no). Lines
coming out are connected by the Connector symbol.
Examples:
y=1
Output Output
“One” “Not One”
Start
Flowchart: Examples
Example 5:
Draw a flowchart that
accepts two integers and
To be demonstrated live
outputs the smallest.
Start
Flowchart: Examples
Example 5:
Draw a flowchart that
accepts two integers and
outputs the smallest.
Flowchart: Examples
Example 6:
Draw a flowchart that
accepts an integer.
Show “Zero” if the To be demonstrated live
integer is 0. Otherwise,
show “Positive” or
“Negative”, depending
on the sign of the
integer.
Flowchart: Examples
Example 6:
Draw a flowchart that
accepts an integer.
Show “Zero” if the
integer is 0. Otherwise,
show “Positive” or
“Negative”, depending
on the sign of the
integer.
Flowchart: Examples
Example 7:
Draw a flowchart that
shows “Hello”
infinitely. To be demonstrated live
Flowchart: Examples
Example 7:
Draw a flowchart that
shows “Hello”
infinitely.
Flowchart: Examples
Example 8:
Draw a flowchart that
shows “Hello” 100
times. To be demonstrated live
Flowchart: Examples
Example 8:
Draw a flowchart that
shows “Hello” 100
times.
Q&A
Acknowledgement
• This presentation has been designed using resources from
PoweredTemplate.com