Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithms 10 IST – Topic 6.

Similar presentations


Presentation on theme: "Algorithms 10 IST – Topic 6."— Presentation transcript:

1 Algorithms 10 IST – Topic 6

2 What is an algorithm? “a series of detailed instructions or steps that will solve a problem in a set amount of time”

3 Common examples of algorithms
Appliance Instructions a logical set of steps to operate an appliance

4 Common examples of algorithms
Recipes a logical set of steps to cook an item

5 Common examples of algorithms
Directions a logical set of steps to arrive at a location

6 Common examples of algorithms
Repair Manual a logical set of steps to repair an item

7 Advantages of using algorithms
solve problems in a logical step-by-step process avoiding vague “blundering-in-the-darkness” finite – always has an end methods are standardised language is standardised problems are described in the same way terminology is uniform

8 Representing algorithms
Pseudocode precise form of English that uses keywords and rules of structure Flowcharts a pictorial method of describing algorithms using a set of symbols, connecting lines and arrows.

9 Pseudocode Keyword Meaning BEGIN END to start a program
to finish a program INITIALISATION END INITIALISATION to set any values at the start of a program to end the values section BEGIN SUBPROGRAM END SUBPROGRAM to start a subprogram to finish a subprogram IF <condition> THEN ELSE ENDIF to allow selection or choice for another choice (may not be needed) to end the choice CASEWHERE <condition> OTHERWISE ENDCASE to allow for many choices to end the choices WHILE <condition> ENDWHILE to begin a loop at the start of a sequence REPEAT UNTIL <condition> to begin a loop at the end of a sequence

10 Pseudocode Rules Keywords are written in CAPITALS
Basic keywords come in pairs … for every BEGIN there is an END Indenting is used to show structure Names of subprograms are underlined

11 Flowcharts

12 Flowchart Rules There is only ever ONE WAY into a flowchart structure and ONE WAY out. A single flowchart should fit on one page If larger than one page … use subprograms

13 Control Structures there are 3 basic control structures to show the order in which statements are carried out: sequencing (or steps) selection (or choice) repetition (or loops)

14 Sequencing most common
each step is carried out in order of its position each step is done only once.

15 Selection Binary selection allows the choice between 2 possible paths
if one condition is met then one path is taken, otherwise the other path is taken

16 Selection Case or Multi-way selection
allows the choice between 3 or more possible paths if the condition is met (TRUE) then one path is taken, otherwise one of the other paths is taken

17 Repetition carries out a particular action any number of times until a condition is met a loop is created to return the program to a point where the repetition starts and continues until the condition is met the loop must have a terminating (ending) condition that is… tested at some time during each repetition updated during each repetition

18 Repetition Pre-test Repetition (While Loop / Guarded Loop)
the condition is tested at the start of the loop if the condition is false the first time the processes will NEVER be carried out. Pre-test loops end when the condition is false. Uses WHILE … ENDWHILE

19 Repetition Post-test Repetition (Repeat-Until Loop / Unguarded Loop)
the condition is tested at the end of the loop after the loop has been run through Post-test loops end when the condition is true Uses REPEAT … UNTIL

20 Repetition For-Next Repetition
The body of the loop is executed a set number of times. A counter variable is given a starting value which is incremented each time the loop is executed until a given final value is reached


Download ppt "Algorithms 10 IST – Topic 6."

Similar presentations


Ads by Google