Algorithm Design: by DR Goh Wan Inn

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Algorithm Design

By Dr Goh Wan Inn


Software Engineering vs Problem Solving
• Software Engineering - A branch of Computer
Science & provides techniques to facilitate the
development of computer programs
• Problem Solving - refers to the entire process
of taking the statement of a problem and
developing a computer program that solves
that problem.

Slide 3- 2
The Programming Process
• SE concepts require a rigorous and systematic
approach to software development called
software development life cycle

• Programming process is part of the activities


in the software development life cycle
The Programming Process

This video
Software Development Life Cycle & Code

Building programs
•Edit
•Compile
•Link
•Run
Software Development Life Cycle & Algorithm

Understand the problem:


•Input
•Output
•Process
Develop the solution
(Algorithm):
•Structure chart
•Pseudocode
•Flowchart
Converting design to
computer codes.

e.g:
Flowchart -> C++ program
Algorithm is the steps
to solve problems
Software Development Life Cycle
• Problem Analysis
Identify data objects
Determine Input / Output data
Constraints on the problem
• Design
Decompose into smaller problems
Top-down design
Structured Chart
Develop Algorithm
Pseudocode
Flowchart
Software Development Life Cycle

• Implementation/coding/programming
Converting the algorithm into programming language
• Testing
Verify the program meets requirements
System and Unit test
• Maintenance
All programs undergo change over time
Input, Processing, and Output
Three steps that a program typically performs:
1) Gather input data:
• from keyboard
• from files on disk drives
2) Process the input data
3) Display the results as output:
• send it to the screen
• write to a file
Problem solving methods in this Class

• 2 problem solving methods will be


discussed in this class are:
Develop Algorithms
❖ Flowchart
❖ Pseudo code
Algorithms
• Algorithm - a sequence of a finite number of
steps arranged in a specific logical order to
produce the solution for a problem.
• Algorithms requirements:
i. Must have input
ii. Must produce output
iii. Unambiguous ( jelas)
iv. Generality(keluasan)
v. Correctness
vi. Finiteness ( measureable)
vii. Efficiency
Pseudo code

• Pseudo code is a semiformal, English-like language with


limited vocabulary that can be used to design &
describe algorithms.
• Purpose- to define the procedural logic of an algorithm
in a simple, easy-to-understand for its readers.
• Free of syntactical complications of programming
language.
Pseudo code
• Execution sequence follow the steps flow.
Example: Algorithm for
multiplying two numbers
1. Start
2. Get A
3. Get B Execution
4. Calculate result sequence
C=A*B
5. Display result C
6. End
Hands on Example!
Write your Pseudo code.
Example:
Calculte Area,Ix and Iy of Rectangle
1. Start
2. Get B
3. Get H
4. Calculate result

5. Display result Area, Ix and Iy


6. End
Flowchart
• Flowchart – a graph of geometrical shapes that
are connected by lines.

• 2 important element in flow chart:


1. geometrical shapes – represent type of
statements in the algorithm
2. Flow line – show the order in which the
statements of an algorithm are executed.
Flowchart
• Flowchart - Represents an Start

algorithm in graphical symbols


Get A
Get B

Example: Algorithm for


multiplying two numbers Calculate Resut
C=A*B

• Desk Check/Trace the algorithm!!!


Display the
Result C

Stop
Flowchart Symbol
Terminal: Used to indicates the start and end of a flowchart. Single flowline. Only one “Start”
and “Stop” terminal for each program. The end terminal for function/subroutine must use
“Return” instead of “Stop”.

Process: Used whenever data is being manipulated. One flowline enters and one flowline exits.

Input/Output: Used whenever data is entered (input) or displayed (output). One flowline enters
and one flowline exits.
Decision: Used to represent operations in which there are two possible selections. One flowline
enters and two flowlines (labelled as “Yes” and “No”) exit.

Function / Subroutine: Used to identify an operation in a separate flowchart segment (module).


One flowline enters and one flowline exits.

On-page Connector: Used to connect remote flowchart portion on the same page. One flowline
enters and one flowline exits.
Off-page Connector: Used to connect remote flowchart portion on different pages. One flowline
enters and one flowline exits.

Comment: Used to add descriptions or clarification.

Flowline: Used to indicate the direction of flow of control.


The Flowchart Explanation
Start Terminal.
Start Program start
here

Read A Input.
Read B Enter values for
A and B

Calculate Resut
C=A*B Process

Display the
Result C Output

Stop Terminal
Stop Program end
here
Example: Use of
comments/description
Start

Read N, N = The number of students


M M = The number of subjects

Yes

No

Stop
Example: Use of connectors on the same page.

Start

1 2

1- connection on the same


flowchart portion

2- connection on the different


Stop flowchart portion
1

2
Example: Use of connectors on the different page.

Page 1 Page 2

Start

2
1

Yes 1

No
Stop

2
The details (how the function works)
Example: Function-call example. we put in another flowchart.
This also known as
Note: Module = function = subroutine Function-Definition

Page 1 Start terminal for a


Function is different.
Page 2
Start Do not use “Start”
AVRG ( result,n1, n2,n3)

Read
n1, n2 , n3

sum = n1+ n2+n3

Body of a function is
AVRG (result, n1, n2,n3) the same with
normal flowchart

result = sum/3
At this part,
we only know what
we want to do. But we Print
result
don’t know how to do it

This part also known as Return


Function-Call

Stop
End terminal
must be “Return”
So now?

• Convert your pseudocode


to flow chart
Flowchart
Start

Read A
Read
ReadB &BH

Calculate Resut
C=A*B
Area, Ix & Iy

Display
Display the
Result
Area, Ix &CIy

Stop

You might also like