2. ALGORITHM
a set of instructions or steps to be followed to achieve a certain outcome
3. The Algorithm will contain:
Input
putting data into an algorithm
01
Output
Displaying data from an algorithm to the user
02
Process
an action performed to some data to make
a change
03
Loop
code that is repeated
05
Variable
a space in the memory of a computer,
that has an identifier, where you can
store data. This data can be changed
04
4. 3 points for successful algorithm
Accuracy
it must lead to the expected outcome (e.g.
create a route from Beijing to Shanghai).
01
Consistency
it must produce the same result each time it
is run.
02
Efficiency
it must solve the problem in the shortest possible time, using as few computer resources as possible. In this
example, the mapping software is replacing a manual method. If it were no faster than looking in an atlas, then it
would not be an improvement on the older method. Later in the unit there is a section on algorithms that are used
to sort and search data. Some of these algorithms are more efficient than others and will sort the data far more
quickly.
03
5. What will algorithm contains :
A Input, Enter, Process, Variable, and Loop
B Enter, Output, Process, Variable, and Display
C Input, Output, Process, Variable, and Loop
Input, Output, Process, Predict, and Loop
D
6.
7.
8. a set of symbols put together with commands that are followed to solve a problem
9. Special symbols in a flowchart
Indicates the start or end of an
algorithm
Indicates a process to be carried out
Indicates a decision to be made
Indicates an input or output
Shows the logical flow of the algorithm
11. Exercise 2.1
Create an algorithm that will ask a user
to input the length and width of a
rectangle and will then calculate the
area.
12. Exercise 2.2
If all three are equal, then the
score is the total of the dice.
If two are equal the score is equal
to the sum of the two equal dice
minus the third.
If none are equal, then the score
is zero.
The flowchart beside displays a partly
completed algorithm for a game that
simulates the throwing of three dice to find
the player’s score.
14. Example of Pseudocode
RECEIVE testScore FROM KEYBOARD
IF testScore >= 80 THEN
SEND ‘A’ TO DISPLAY
ELSE
IF testScore >= 70 THEN
SEND ‘B’ TO DISPLAY
ELSE
IF testScore >= 60 THEN
SEND ‘C’ TO DISPLAY
ELSE
IF testScore > 0 THEN
SEND ‘D’ TO DISPLAY
ELSE
SEND ‘FAIL’ TO DISPLAY
END IF
END IF
END IF
END IF