Algorithms
the name given to 'defined set of steps that can be used to complete a task', step-by-step instructions for the computer to follow. algorithms always include:
-input data (e.g. ask the user a question or collect a value from a sensor)
-the process data (e.g. add two values together or make a decision when a value reaches a certain amount)
-output data (e.g. display some results or play a sound)
algorithms can have variables in them (e.g. if the main ingredients of a sandwich are either jam or cheese the 'main ingredient' variable will be cheese or jam) and before writing an algorithm theres also a pseudo code (plain english) or even simpler, a flow chart version of the code. algorithms always start and finish with start and stop and include code like if, else, get, display, assign, while (instead of input and output) and also in algorithms when you want to set a (changeable-usually an else statement) variable you use an arrow (e.g. instead of 'largest becomes 7' you'd write 'largest<---7') and '=' is used to set a variable (e.g top=bread). Algorithms usually contain loops aswell so that it can be true for many different scenarios and so being a lot more useful for following instructions in the computer.
Example: finding the largest of three numbers:
start
declare variables a, b and c
read variables a, b and c
if a>b
if a>c
display a is the largest number
else
display c is the largest number
else
if b>c
display b is the largest number
else
display c is the largest number
stop
the name given to 'defined set of steps that can be used to complete a task', step-by-step instructions for the computer to follow. algorithms always include:
-input data (e.g. ask the user a question or collect a value from a sensor)
-the process data (e.g. add two values together or make a decision when a value reaches a certain amount)
-output data (e.g. display some results or play a sound)
algorithms can have variables in them (e.g. if the main ingredients of a sandwich are either jam or cheese the 'main ingredient' variable will be cheese or jam) and before writing an algorithm theres also a pseudo code (plain english) or even simpler, a flow chart version of the code. algorithms always start and finish with start and stop and include code like if, else, get, display, assign, while (instead of input and output) and also in algorithms when you want to set a (changeable-usually an else statement) variable you use an arrow (e.g. instead of 'largest becomes 7' you'd write 'largest<---7') and '=' is used to set a variable (e.g top=bread). Algorithms usually contain loops aswell so that it can be true for many different scenarios and so being a lot more useful for following instructions in the computer.
Example: finding the largest of three numbers:
start
declare variables a, b and c
read variables a, b and c
if a>b
if a>c
display a is the largest number
else
display c is the largest number
else
if b>c
display b is the largest number
else
display c is the largest number
stop