0% found this document useful (0 votes)
11 views10 pages

Lesson 3 Presenting Algorithms

Uploaded by

kelemnisi12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

Lesson 3 Presenting Algorithms

Uploaded by

kelemnisi12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Solution development – Presenting

algorithms - Flowcharts and Pseudo code

1
Pre-knowledge: analyse the flowchart
by asking questions about it
 Algorithm A STAR
T
Algorithm B
STAR
T Observe traffic

Is there
CROSS
any
ROAD ON WAIT
approachi
ng Ycar
STO
E
P
S
Cross road
now

STOP
2
How to use pseudo code to
present an Algorithm
Pseudo code :
START
Task: Cross the road
Begin Observe
traffic
Observe traffic
While traffic approaching do
Is there any
Wait
ON
approaching WAIT
car
Observe traffic Y
E
Endwhile S

Cross the road Cross road


now
end
STOP
3
The decision block in a
flowchart
 The decision block has START
been added to test a
specific condition Observe
traffic
 Repetition takes place
when the answer to the Is there any ON
question in this particular approaching WAIT
car
decision block is “Yes” Y
E
 When the answer is “no”, S

Cross road
the condition has been met now

STOP
4
Algorithms -
activity 1

 Write down a step by step


solution to solve the following:
 Write an algorithm to determine the
largest of three values and
display the largest value. Use a
flowchart to present the Algorithm

5
Characteristics of a good
Algorithm
 One activity per step.
 Clear instructions.
 The Algorithm should have a clear beginning and end.
 Completeness – all the steps should be formulated as
part of the solution.
 The steps should be in the correct order.
 All the steps should be related to the task to be
completed – no unnecessary steps or information
 The Algorithm should be efficient. Make use of
decisions and repetition to make the algorithm as
short as possible
6
Algorithms -
activity 1 - solution Largest
STAR Number
2> Yes =
T
largest Number
N 2
Get the value o
Largest =
of number1
number1
Get the
Number Largest
value of
3> =
number2 Yes
largest Number
Get the N 3
value of o
number3 Largest =
number1
Largest =
number1 Display the
value: Largest

7
STOP
Algorithms -
activity 2

 Write an Algorithm to determine


the cost to do the tiling of a
rectangular room. Cost of the
tiles is R55 per m2 .Try to make it
more abstract by using variables
instead of values. Write down the
single steps, using Pseudo code
8
Algorithms -
activity 2 - solution
 Pseudo code: Calculate the cost to tile a room
 BEGIN
 Ask the length of the room
 Get length
 Ask width of room
 Get width
 Area = length x width
 Cost = Area x 55
 vat = cost x 0.14
 Total = cost + vat
 Display “ The Total is “ , Total
 end.
9
Algorithms -
activity 2 – Pseudo code?

 Pseudo code is a structured language- based way of


presenting an algorithm, similar to the methods of recipes in a
cookbook – short and clear step by step instructions.
 Guidelines to compile pseudo code:
 Use short, clear instructions
 Clearly indicate the start and end
 Use variable names to indicate input, processing and output
 Use keywords to indicate decision making and repetition
e.g.:
 While ...Do...EndDo If...EndIf Repeat...Until
 When a decision or repetition is made, all the instructions in
the “branch” must be indented.
10

You might also like