In this video we're going to consider how to produce algorithms using pseudocode and flow diagrams. In the exam you need to be able to create, interpret, correct and refine algorithms using pseudocode flowcharts and python high level language code. Now depending on the paper, whether it's paper one or paper two, you'll probably be having to approach this in a slightly different way. With Paper 1, you'll likely have to do this in a much more theoretical way using for example Pseudocode or flowcharts.
In Paper 2, where you actually will be sitting the exam at a computer, you'll have to provide all your answers in actual Python. This video is mainly going to focus on how to produce algorithms using Pseudocode and flowcharts for Paper 1 exams. We have a separate video focusing on Paper 2 on this topic when you look at Section 6a.
A flow diagram, often referred to as a flow chart, is just one way of representing a sequence of steps in an algorithm. Here we can see that we start at the top. We input a number from the keyboard.
We input a second number from the keyboard. We ask, is number one greater than number two? And if it is, then we follow one branch.
And if it's not, we follow another. Then there's different outputs, depending on the outcome of that decision, before the program comes to a stop. We can represent that algorithm using what's called pseudocode. Pseudocode is like a halfway between English language an actual programming code in a programming language. It looks a little bit like a programming language but doesn't follow any specific syntax for one given language.
Instead, it's more generic code that could easily be applied into any programming language that a programmer wants to use. So in this example we're inputting our two numbers. And we're saying if number one is greater than number two, then print the largest number is number one.
Otherwise, print the largest number is number two and then end. So it's exactly the same algorithm that we saw in the flow chart. It's just represented in a different way.
As well as creating an algorithm from scratch in the exam. You might be presented with one already in the form of a flowchart or pseudocode etc. And then be asked to refine it somehow. So here we see our previous flowchart from an algorithm to output the largest of two numbers entered by the user. And we're being asked to refine it so it will now output the largest of three numbers entered by the user.
You would first need to identify the areas of the existing algorithm which need modifying. Well, we would clearly need to modify this top section to take in an extra input from the user, which you can see we've done here. And we would also need to modify this bottom section. Now this will require a little more thought, so why don't you pause the video and see if you can sketch out with a pen and paper how you would alter the bottom part of this flow diagram.
And here you can see our refinement. So we've still got the is number one greater than number two, but then if the answer is yes or no, we're performing another check and depending on the result of that, we're either outputting number one, two or three is the largest. Of course in the exam you may be presented with this algorithm in a different form and you could be asked to present your answer in pseudocode or your preference of either the OCR exam reference language or a high level program code of your choice. Here's another example of a flow diagram. Now this algorithm calculates how much carbon to dose into a fish tank to keep nitrates at bay.
It starts by asking what the nitrate level is. and says if the nitrate is above 10 then output 3 mL. If not, is nitrates above 2.5 and if they are, output 2 mL. And if they're not, is the nitrate above 1? And if it is, dose 1 mL. And if it's not, dose half a mL before coming to a stop.
We can of course express this algorithm in pseudocode. Here's a comment just to explain the purpose of the program. Next we've got a variable called nitrate which is entered from the keyboard.
We ask if nitrate is greater than 10, then dose 3 mL. Otherwise, if nitrate is greater than 2.5, then dose 2 mL. Otherwise, if nitrate is greater than 1, dose 1 mL.
Otherwise, dose half a mL. It's exactly the same program, just expressed in a different way. So all flow diagrams use a common set of symbols. There are many symbols, but six of the most popular ones that you'll be expected to know for the exams are shown here.
You've got a terminal symbol, and that shape represents the start or end of a process. Then you have a process symbol, and this shape represents something being initialised, processed or calculated. You have a decision symbol, and this shape 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.
Then you've got an input output shape, and this represents the input and output of data to the algorithm. And you have a shape representing a call to a subroutine. A subroutine will have its own flowchart, but when you call it from the main program, you need to express that call using this symbol. Finally, you have a line and the purpose of the line with an arrow represents the control passing between connected shape.
It's the flow of the algorithm.