Algorithms 2.1 Flowcharts, Pseudocode, structure diagrams Flashcards
Define flowchart
A flowchart is a method of representing the sequences of steps in an algorithm in the form of a diagram
State the different symbols that make up a flowchart and draw what they look like
Terminal
Process
Decision
Input/Output
Sub routine
Line
What does the Terminal symbol in a flowchart represent
Terminal symbol – represents the start of end of a process
What does the Process symbol in a flowchart represent
Process symbol – represents something being initialized, processed or calculated.
What does the Decision symbol in a flowchart represent
Decision symbol – represents the decision. It will have a yes or no, true or false outcomes which will be represented by two separate lines or paths exiting the shape.
What does the Input/Output symbol in a flowchart represent
Input/Output symbol – represents the input and output of data to the algorithm
What does the Sub routing symbol in a flowchart represent
Sub routing symbol – representing a call to a sub routine. A sub routine will have its own flowchart, but when you call it from the main program, you need to express that call using this symbol
What does the Line symbol in a flowchart represent
Line (with an arrow) - represents the control passing between connected shapes. It is the flow of the algorithm
Define pseudocode
Pseudocode is an alternative, text-based way of representing the sequence of steps in an algorithm
What does the prefix, pseudo mean
The prefix ‘pseudo’ means false or not genuine
State an advantage of pseudocode
Pseudocode allows us to lay down the logic of a problem in an almost-like-real-code way without worrying about the actual rules and syntax of a particular language
Create a flowchart asking the user to input two numbers, and display to the screen the larger number
file:///C:/Users/44748/Documents/flowcharts%20and%20pseudocode.pdf
Create an algorithm in pseudocode, equivalent to the flowchart
file:///C:/Users/44748/Documents/flowcharts%20and%20pseudocode.pdf
number1 = INPUT ()
number2 = INPUT ()
if number 1 > number 2 then
print(“The largest number is” + number1)
else
print(“The largest number is” + number2)
endif
When refining an algorithm what do you need to do
Step 1) Identify the areas of existing algorithm which need modifying
QUESTION: Refine this algorithm to output the largest of the three numbers entered by the user.
file:///C:/Users/44748/Documents/flowcharts%20and%20pseudocode.pdf
file:///C:/Users/44748/Documents/flowcharts%20and%20pseudocode.pdf
Create a flowchart which calculates how much carbon to dose into a fish tank to keep nitrate levels safe. If the nitrate level is above 10 dose 3ml of carbon. If the nitrate level is above 2.5 and smaller than 10 dose 2ml, if the nitrate level is above 1 but smaller than 2.5 dose 1ml is the nitrate level is below 1, dose 0.5ml
file:///C:/Users/44748/Documents/flowcharts%20and%20pseudocode.pdf
Create an algorithm in pseudocode, equivalent to the flowchart
file:///C:/Users/44748/Documents/flowcharts%20and%20pseudocode.pdf
Describe the pseudocode/flow char fish algorithm
file:///C:/Users/44748/Documents/flowcharts%20and%20pseudocode.pdf
This is a comment to explain the purpose of the program
The user is asked to enter the nitrate level, this value is stored in the variable:nitrate
If nitrate is greater than 10 then Then does 3ml
Otherwise if nitrate is greater than 2.5, Dose 2ml
Otherwise if nitrate is greater than 1 Dose 1ml
Otherwise dose 0.5ml
What does 6 MOD 2 mean
6/2 = 3, there is no remainder, therefore the modulus of 6 MOD 2 would equal 0
What does 7 DIV 2 mean
DIV – Quotient (integer division) e.g. 7 DIV 2 = 3. It disregards any decimal places that are a result of the division.
What is the method, Structure diagrams are produced by called?
Structure diagrams are produced using a method known as step-wise refinement
Describe step-wise refinement
We break the problem down using decomposition into smaller and smaller components
Some areas of the program will need breaking down more than others
The lowest level nodes should achieve a single task
These can be then be coded as a single module or sub-program
What do structure diagrams look like
file:///C:/Users/44748/Documents/structure%20diagram.pdf