video

Lesson video

In progress...

Loading...

Hi, I'm Kashif, your computer science teacher for the algorithms unit.

In this lesson, we're going to be looking at representing algorithms. For this lesson, you will need a pen, some paper and you're going to need to remove any destructions that are going to get in your way of focusing.

Once you've done that, let's begin.

Building Lego, imagine giving these Lego instructions to five different people.

Do you think that everyone's finished product will look the same, why? Write your answers down.

Okay, let's have a look.

So, very clear decomposed solutions to a problem mean that it's much more likely that they can be followed no matter who uses them.

Lego instructions are also visual.

So they're a visual language making them more universal than a written language.

In this lesson, you will describe the difference between algorithms and computer programmes, identify algorithms that are defined as written descriptions, flow charts and code and analyse and create flow charts using flow chart symbols.

Algorithms, an algorithm is a set of precise instructions expressed in some sort of language.

Understanding the language is necessary in order to execute the instructions.

Executing these instructions is meant to solve a problem.

So as you can see on the right-hand side, we've got some instructions.

We're knitting a jumper there and then we're following along with them.

The term algorithms and computer programmes can often overlap but are distinct from one another.

What do you think the difference is between an algorithm and a computer programme? Write down what you think.

Okay, let's have a look.

An algorithm describes the logic of a solution.

A computer programme is an implementation of this solution written in a programming language.

Programmes written in a programming language are precise enough for a machine to translate and then execute.

Representing algorithms, in computer science algorithms can be represented in a number of ways not only in a programming language.

For instance, you can use flow charts or written descriptions to help you to focus on the logic of a solution without worrying about syntax errors.

This can massively speed up the development time of a programme.

Flow charts, a flow chart can be used to visually represent an algorithm or programme.

Arrows are used to signify the flow of the programme.

What does this algorithm do? Have a look, see if you can follow through and let's see what you think.

Okay, so a written description can be used to specify the steps, an algorithm or the steps of an algorithm.

Ask the user for the year they were born, ask the user for the year it currently is, subtract the year born from the current year and then tell the user how old they will be this year.

Once the logic of an algorithm is planned out, you can use it to help with writing programming code such as in a language such as Python.

So there we've got a example of some Python code.

Notice, with our variable names, there's no spaces.

So we're using the underscore or you could use camel case if you're more familiar with that.

So on the left-hand side we've got examples of Python code, on the right-hand side we've got an example of a flow chart.

Creating flow charts.

In the next task you're going to develop a flow chart.

First though, you need to know what the different flow chart symbols are and what they represent.

Start, so that shape there is for a terminator and terminators are used at the start and end of subroutines or programmes.

Arrows, arrows are used to show the direction and flow of the programme.

Subroutines are represented by a rectangle with two lines on either side.

We've not seen the parallelogram.

Here we go.

So the parallelogram is used for input and output and the rectangle is a process and it represents, it shows any instructions or commands.

So in that rectangle there, we've got an example of assignment.

So all the assignment we'll be putting in a rectangle.

The last shape is a diamond.

Now a decision has two brunches, true or false and as you can see from the diamond there on the left-hand side, if it's true, the arrow shows what's going to happen in terms of the flow and if it's false, it's going to go into a different direction.

Written descriptions or written description for coin toss.

The following slides go over a step-by-step breakdown of a flow chart for a coin toss game.

The instructions for the game can be written as, ask the user to guess heads or tails, simulate a coin flip by randomly generating either heads or tails, compare the coin flip with the user's choice.

If the coin flip is the same as the user's choice, tell the user they won.

Otherwise tell the user they lost.

So begin the flow chart with a start terminator.

Ask the user to guess heads or tails, store the response in a variable called Choice.

Simulate a coin toss by randomly generating either heads or tails, store this in a variable called Flip.

Compare the coin flip with the user's choice.

If the coin flip is the same as the user's choice, tell the user they won.

Otherwise, tell the user they lost.

Finish the flow chart with an end terminator.

Task one, dice roll, is it a double? Now it's your turn to create a flow chart for a dice roll simulation.

Pause the video to complete your task.

Task one, dice roll, is it a double? Using the worksheet, complete task one.

Resume once you have finished.

Task one, dice role, is it a double, solution.

So as you can see here, we've got the solution to the problem.

Usually with flow charts, you might have more than one solution or more than one way that you've done it but this is just an example of a solution.

So here, dice one, we've got a random number and we've got that in the rectangle.

Dice two, we're also having dice two another random number and then we're doing some comparing.

So dice, and when we're comparing, we're using the double equals there.

So is dice one equal to dice two? If it is, we're going to output saying, you've rolled a double else, we're outputting saying no double this time.

How did you get on? If you found it a little bit difficult, attempt it again now that you know what the solution is and see if you do better next time.

That's the end of the lesson.

So thank you very much for joining me on this lesson.

If you want to share your work with Oak National, if you'd like to, please ask your parent or carer to share your work on Instagram, Facebook or Twitter tagging @OakNational and #LearnwithOak.

I'd like to see what flow charts you developed and how you got on with the task.

So if you do tag that, I'd be delighted to see the solutions that you've come up with.

Thank you so much for joining me and hopefully I'll see you on the next lesson.

Take care, bye.