AlgorithmDesign
AlgorithmDesign
Bottom Particular
The algorithm
Figure extracted from Computer Science
Illuminated by Dale N. and Lewis J.
Techniques For Laying Out An Algorithm
• Pseudo-code
• Flowcharts
Pseudo-Code
• If-then
• General form:
• if (condition is met) then
• statement(s)
• Example:
• if temperature < 0 then
• wear a jacket
• If-then-else
• General form:
• if (condition is met) then
• statement(s)
• else
• statements(s)
Pseudo-Code: Decision Making (2)
•
• Example:
• if (at work) then
• Dress formally
• else
• Dress casually
Pseudo-Code: Repetition
• repeat-until
• while-do
Pseudo-Code: Repetition (2)
• repeat-until
•
• Repeat at least once (check condition after statement(s))
•
• General form:
• repeat
• statement(s)
• until (condition is met)
• Example:
• repeat
• Go up to buffet table
• until full
•
Pseudo-Code: Repetition (3)
• while-do
•
• Repeat zero or more times (check condition before statement(s))
•
• General form:
• while (condition is met)
• statement(s)
• Example:
• while students ask questions
• Answer questions
•
•
Pseudo-Code: Fast Food Example
• Statement Purpose
Input Output
Off page
Connecto
r
Decision c
Arrow Variables
Flowchart: Fast Food Example