algorithms 10 ist – topic 6. what is an algorithm? a series of detailed instructions or steps that...

20
Algorithms 10 IST – Topic 6

Upload: ezra-weatherall

Post on 29-Mar-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Algorithms

10 IST – Topic 6

Page 2: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

What is an algorithm?

“a series of detailed instructions or steps that will solve a problem in a set amount of time”

Page 3: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Common examples of algorithms

Appliance Instructions

a logical set of steps to operate an appliance

Page 4: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Common examples of algorithms

Recipes

a logical set of steps to cook an item

Page 5: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Common examples of algorithms

Directions

a logical set of steps to arrive at a location

Page 6: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Common examples of algorithms

Repair Manual

a logical set of steps to repair an item

Page 7: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 8: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Representing algorithms

Pseudocodeprecise form of English that uses keywords and rules of structure

Flowchartsa pictorial method of describing algorithms using a set of symbols, connecting lines and arrows.

Page 9: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Pseudocode

Keyword Meaning

BEGINEND

to start a programto finish a program

INITIALISATIONEND INITIALISATION

to set any values at the start of a programto end the values section

BEGIN SUBPROGRAMEND SUBPROGRAM

to start a subprogramto finish a subprogram

IF <condition> THEN ELSEENDIF

to allow selection or choicefor another choice (may not be needed)to end the choice

CASEWHERE <condition> OTHERWISEENDCASE

to allow for many choicesto end the choices

WHILE <condition>ENDWHILE

to begin a loop at the start of a sequence

REPEATUNTIL <condition>

to begin a loop at the end of a sequence

Page 10: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 11: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Flowcharts

Page 12: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 13: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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)

Page 14: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

Sequencing

most common

each step is carried out in order of its position

each step is done only once.

Page 15: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 16: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 17: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 18: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 19: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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

Page 20: Algorithms 10 IST – Topic 6. What is an algorithm? a series of detailed instructions or steps that will solve a problem in a set amount of time

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