Transcript for:
Understanding Algorithm Design and Problem Solving

hello everyone so welcome back to this channel so in this video we are going to look into the second part of the igcse computer science syllabus which is the practical part in which we will learn about algorithms programming databases and logic gigs but in this video alone we're just going to focus on chapter 7 algorithm design and problem solving which hopefully will serve as a really good foundation for you when you learn about programming so let's look into the first subtopic of this chapter which is the program development life cycle so it is basically a process that developers follow when creating a new program such as um for all the apps that you look into app stores they might not be using exactly the same cycle but the essence of it is that they all go through this similar process so the first step is always the analysis part and followed by how they design it and after all the planning has been done the programmers will start coding the applications differ different functions and after all the coding stuff they have been done they'll proceed to the test link and eventually they will launch it so here i have some applications here such as the powerpoint app that i'm using to present my teaching the zoom application ai from adobe and also the game that you play such as fortnite they are all part of software all right so in this syllabus you'll be required to do a unseen scenario question and your paper to exam so this is just one example of what you have to do at the end of um this syllabus so they will throw you a question and you have to code it out using either pseudocode or any programming language that your teacher has taught you let's not move too far so let's look at each of go into each of this stage and see what they actually mean before we start looking into the more practical stuff such as the flowchart and the pseudocode because by knowing this process you have a good big picture on how software is being developed and after that you will have a better understanding when learning the individual components of designing a software all right so the first step of the pdlc is analysis first of foremost before you start coding anything designing anything you need to understand what is the requirement specification which means otherwise they talk about what does this program aims to achieve all right so problem needs to be clearly defined and set out so anyone working on a solution understand what is needed so for instance for all the application that i show here facebook google zoom the the founder start to code all of this software out they need to have a brief idea on what this app is going to achieve for instance the facebook application i believe that mark zuckerberg had the idea in the beginning that this app is going to be able to connect different people around the world so he will need to include features such as the chatting function the posting function the ability to like a post by your friends so but before he codes all these things out you need to understand what this apps is about and what problem it is going to solve and they are another example is the google app search engine what do they plan to achieve they plan to achieve that everyone when they use the app they can ask any questions and get the answers and the third example is the zoom application it's pretty obvious everyone use it nowaday is that they want to create a video conferencing apps so having the requirements set up is extremely important i would say it's more important than coding the program because if you don't know what problem you are trying to solve then you will be pretty clueless when you are coding the program out all right so there are two steps of analysis basically the two steps that programmers they carried out they don't always call these as decomposition but they do it um maybe without knowing the name or they know it so these are the two steps of analysis that help programmers to understand better what they are they want to build all right so the first step is decomposition decomposition breaks down a complex problem into a smaller parts which can be divided into even smaller parts that can be solved easily so one real life example of decomposition is that let's say you want to organize a hangout with your friends then instead of just um saying okay we want to do a hangout you will need to plan a few things right a few tasks such as who you need a confirmation of who is going and after conf the fact has been confirmed you need to find a place to hang out and arranging transports so these are all little problems that connected to your objective to organize a hangout right so similarly in programming an app you will need to figure out what are the smaller part of the program so for instance when you're using the facebook app there are multiple parts of the program such as the marketplace which allows buyers and sellers to do transaction there's also the personal feed where you can see some more personal stuff from your friends and family and these are just the different components an app might constitute so the second part of analysis is the abstraction phase so let's just read out the definition it keeps the element requires for the solution to the problem and discard any unnecessary details and information that is not required so an example again using the same example of extraction is that before you when you organize a hangout the first most important task to confirm is that you need to know who who is going to the hangout before you actually find a place because you want to know who will be going before you decide where to go because the place that you decide might not be for everyone okay so before knowing if anyone is going the details of where to hang out and be temporarily abstracted you just have a brief idea of where to go all right i know this idea sounds pretty abstract so i provide another example here so for instance when i teach this lesson i need to do some planning in the beginning of this video i just said that we're gonna do program development life cycle without giving you any many details on what this cycle is all about and as the video proceeds i started to explain that there are four steps of the analysis process first steps of the pa dlc process sorry and analysis design coding and iterative testing and as i explain each section to unveil more details that i haven't talked about such as what is the requirement specification means what is abstraction what is decomposition so this is one way i abstract this lesson so instead of showing you all these details in the beginning i abstracted them so that i can explain my subject in a better way and this is how it works abstraction we keep the details that are unnecessary temporarily and review it side by side so for abstraction in web development you for instance when you are developing an app you don't want to care too much about the details first you just want to have the skeleton the break picture so this is how abstraction is useful in software development okay so the second part of pdlc is the designed part in this stage developers of the program will continue the decomposition phase from analysis and begin to drop visual of the end products so this is where the programmers start doing some work before coding it there are three methods that we learned to design our program in this syllabus and which i will talk about them in the later part of this video first of all is structure diagram they basically help us to visualize how the big how the angles of the app is like what are some of the parts of the app and followed by flowchart and pseudo code so we're going to talk about about that in chapter 7.2 and after the design part has been done the programmers will proceed to coding by using the stuff that we designed previously like they will be coding using the pseudocode that i written and even also the flowchart and would so this is the part where the programmers work on the design module such as the input output and processes and right code to make each part of the program functional i know this sounds pretty abstract for now but please be patient with me i'll go through each step one by one so eventually you can code your own program so for coding um there are many parts in in the program there are a lot of parts that need to be code coded it's not that you write just 1000 codes of lines and then all these things will come up because let's look at this example called from from the sharpie website which is a very famous e-commerce website in malaysia so there even in this small snapshot there are multiple functions for this application so first of all the programmers need to write a program that update the so count automatically so whenever a user purchases a product here the program will need to update this from 4 to 5 automatically so that's one thing the programmer need to program and followed by the login and sign up page if you were to click this button you'll be brought to another page and that's another software to be written and even the notification center so the search bar how to help the user to select the most valuable product using that searches and an established app like amazon facebook any ad that you think they are established enough they usually have millions and millions of lines of code to just do the different part small part of this program all right but however we would just we only do coding in chapter eight so feel free to comment in the bottom if you want to learn about it so i will make some videos to explain all right in chapter eight so after the auto coding have been done the programmers will proceed to testing their programs so the test strategy is that the system will be divided into smaller section to be tested for input output and validation rule so test data is used for all those tests to be carried out we'll be talking more about testing in chapter 7.6 just remember at this phase of the video i'm just trying to give you the big picture of what this chapter is about and there are two types of testing unit testing in which we touch each part of the code individually so for instance in the pro example that we see there are many parts of the program the programmers will test out one by one and as for integration testing all code is combined to form a program and then the program is tested as a whole so an example is that we test that when an item is still the count is indeed increased by one instead of indeed increased by two and this is how the programming programmers test out their programs all right so before i end this small sub-chapter just to note here is that if you look at the full name of pdlc as programming program development life cycle this means that this cycle is not a linear process so from one end to the other end instead is a cycle which means that the programmers might start off from the analysis phase and move on to design test coding and testing so let me just redraw it to clarify first step second third fourth and after the testing is done the app is launched it doesn't mean that this is the end of the job right we know that all the apps they have software updates nowaday which means that after the testing phase the programmers will need to go back to the analysis phase again to figure out what are some of the new features that can be added and then they will repeat the process design the new feature code out the new feature and test new feature and go back to analysis again and this is how all the apps ensures that they can keep evolving keep improving um as as an app all right so that's the annual programming development life cycle so in the next part of our videos we're going to talk about how system is divided into subsystem if you remember in the analysis phase of the pdrc process we need to decompose our problem a software problem into smaller one because a software can contain millions of lines we don't just want we we want a better way to code all this smaller part of the program out so let's look at the definition of computer system they are made up of software data hardware communication and people and each computer system every computer system every app can be set divided up into a set of subsystems and these subsystem can be divided into smaller subsystem and so on let me give you an example from one of the app that i believe teenagers use often is the instagram app and how instagram is actually a computer system so first of all it is made up of software data hardware communication and people so the software would be the code that is written in different programming language to code the app and data would be the user preference just a fun fact here is that all the social media apps nowadays they keep tracks of what you like what you have commented and how long do you watch something to determine what you like so that they can recommend content that you are most likely to watch so that's the data part of the instagram app so the hardware would be a server to store all the data and communication and people would be the instagrams employees so that's um first part and second part each computer system can be divided into a set of sub system if you use the instagram app you'll notice that the app has different functionalities so they have the post functionality they also for the story functionality which is copy from snapchat and also the view functionality which is un implemented recently it's also copied from the apptiq talk all right so if you look at this app they can actually be divided into multiple subsystem and each subsystem can then be further divided into subsystems and so on so um in the instagram story function you can choose to share your stories to either your normal followers or if you prefer to have some privacy you can also share only to your close friend so that's another subsystem involved in this application so um there are other examples of a computer system like the alarm clock app weather app games so to aspiring programmer here before you want to build something it's better that you all figure out what to build first because if you look at every app there there are they usually consist of many different functions and if you don't try to lay out all this function before you build when you code this program out you you are going to be pretty clueless so these are the components of a computer system which are already talking talk about so if you were to create a system a software today so you need to think about the following problem how do you divide your system into subsystem so that it works so that the workload is manageable and the second question is that how do i start developing a subsystem using an appropriate programming language so the tools that we will learn that will help you to do that is the for the first question we use a structural diagram and for the second question we use the flow chart or the pseudo code in which we start learning it from now on so let's look at structure diagram structure diagram they show top-down design in the diagrammatic form so if you look here they basically show how a solution can be subdivided into a subsystem which each level giving a more detailed breakdown so just imagine this problem here is a huge problem let's say i want to have a social media app and that's a pretty big idea right but to make the task more manageable you want to split it down decompose it into smaller part so let's say um this is the story this is the pose this is the real let's use the instagram example and this is how app developers they break down a big problem into smaller ones in other words we call this a top-down design in which we show a big problem and then a general one without giving too much details and as we dive deeper and deeper we review more problems or we discover more details that we want to add to our program so that's let me show you an example of how to draw a structural diagram because you need to learn how to draw it so let's say we have uh we want to create an alarm clock specification i mean how hard can an alarm clock be right oh you might need to think twice after looking at the answer so for the alarm clock this is the way we breaked it down we split the functionality of the app into three parts the inputs the processes and the outputs so for the input of an alarm clock would be how you're gonna set the alarm how you set the timer how you press the stop clock right and the processes will be how an alarm clock checks whether the current time meet the set alarm time and the output would be how the alarm would rank and how it would send notification and so on so this is the answer uh not not the exact answer it can be broken down further but just an example here for input you will have to set time turn alarm clock on and off all right and the process is that you want to check whether the time has reached and after the time is confirmed you will need to output do the appropriate output such as sounding the alignment or turn off the alarm so let's do one more question to help you have a better idea on how to do the structure diagram so we have a question here okay let me look at this so we have a question here a security system on a door allows a user to type a code into a key to enter the room and if an incorrect code is input and every message is shown and a short alarm sound is played so we can break down this problem into three parts okay so i will use another app to do this okay so first of all what we want is a security system a security system and we are going to break it down into three parts the input the process and also the output so according to the project requirement the input of it is that we need a keypad to allow the user to enter to enter the key the password a keypad and this keypad should allow the user to enter enter code enter code so the process would be to check whether the code entered by the user is the one set by the owner to check the code to check the code whether they are correct and the output would be to sound in long so can you see in this just small program there are multiple parts of the system and by using the input process output method we can better decompose the problem into some manageable one all right so what if uh let's say if i were to add an additional requirement it's the security system allow facial recognition then i would i can draw another part here which says another form of input is facial recognition so by drawing this diagram we can visualize what are some of the things that we need to build here all right so if you want a security system you first need to do a install keypad and then if you want it to be visually recognized recognizable you need some other app and the process you know what to code and eventually what to um output right so by drawing a structural diagram you will be able to better manage your tasks you can assign this task to one person another to another person third person and fourth person so basically helps you to split a big problem better into smaller ones so let's go back to um this question we have already driven it um drawn the structure diagram so in short structural diagram is a way for you to decompose a problem in other words to break down a big problem into smaller ones and the way we do this is to classify into the input process and output branch and you'll be able to there so let's look into another way that we can design our program so which is to use the flowchart but before we learn how to use the flowchart we need to understand what an algorithm is because the flowchart is basically just a two for us to model the algorithm all right the algorithm is a set of instructions for solving a problem or accomplishing a task and the way i like to think about it is it is a series of steps that needs to be done in order to achieve a task so for instance driving a car in real life um before you drive your car you first need to walk to the parking space you need to open the door turn on the engine and put on your seatbelt before you can say let's go so that's the algorithm of driving a car and as in a software perspective it would look something it would look like this so for every second um the alarm clock app will check if the time matches the one set by the user all right and for after that it will check whether the day matches so don't wake me up at six o'clock on in the weekend right and if both scenario matches only then the alarm will ring so can you see the algorithm is a step-by-step process and this is exactly how the computer work they work step by step but we as a programmer we need to define what is the correct algorithms for them so flowcharts and pseudo code which we will learn in later are effective in communicating how the algorithm that makes up a system or assist subsystem work because it shows the algorithm in a diagrammatic manner right so just look at this flowchart here all right can you kind of guess what it does so we have start and it will get time and we'll check whether the time is equal to the alarm time if yes they will sound the alarm if not they will just wait for 30 seconds so that's how we explain our app better by using a flowchart so before we learn how to draw one ourselves i just want to show you some of the components of the flowchart so that we can use them more effectively when solving a problem first of all we have the terminal symbol which is used at the beginning and the nfh flowchart they are a rounded rounded rectangle rounded rectangle so the second one is the process they represent an instruction that needs to be done you can also treat it as a step in the algorithm do remember that the shape here is extremely important so if you look at the terminal symbol it's a rounded rectangle but if you look at the process symbol it is a rectangle it's it's not rounded so make sure you use the correct shape for the correct component the third one is the input and output in which we state that this step we require the user to give us some input and it is represented by a parallelogram all right look at the shape here and followed by the subroutine subroutine is a complicated concept they basically represent a smaller procedure running within the large program so when you look at this get time subroutine here under who this it could be a bunch of code running it that means it could be another flow chart there to to do stuff but at this time we just abstract it we don't we don't want to know how get time work in alarm we just want to know that this is a get time step so this is abstraction in action abstraction in action sub 14. you will definitely get to learn the benefit of subroutine when we learn about programming because it shows you how we can abstract stuff better so just keep the idea in mind for now and last but not least it's a flow line denoted by an arrow to show the direction of the flow so let's try to solve one problem with with a flow chart right so one note here is that when we are learning about the flow chart or even the pseudocode it is extremely important for you to practice more because memorizing all these components wouldn't help you a lot if you don't know how to use them so just try to do it whenever i explain an example try to do it yourself first by pausing the video so that you can cross-check with my answers after i have done it okay so let's solve this problem a computer program allows the user to input two numbers and it multiplies the numbers together and if the answer is larger than 100 it outputs the message greater than 100. if it doesn't then it does nothing and the program loops until the user does not want to input any more numbers draw a flowchart that represents an algorithm for the computer program so just like how we do the structure program when before we start drawing anything let's first split the problem into the three part which is inputs outputs and also process the input here is that we we want two numbers from the users we want two numbers from the users and the output is that well we want to get send a message saying whether the numbers the sum of the numbers no the product of the number is greater than 100 and the process would be you need to multiply the two numbers so i have decomposed it here to just save your time and that's how the input output and process work so let's try to solve this problem i'll open another app to show you how so first of all always remember when we're drawing a flow chart just start off with the terminal symbol which denote the start and end all right so we're going to start it look at how i draw the rounded rectangle it's not a rectangle so what does the program want first and foremost they want the user to input two values right so at this time we need to use the input symbol which is a parallelogram okay a parallelogram so look at how i draw this you will need to write something inside the parallelogram just write down an input the input keyword followed by what name you want to give the input so i'm going to give it a name of n1 so what this does is that what this parallelogram does is that it asks the user for a number and then store it inside this left rectangle here is that let's say the user input a value of 5 this value will be stored inside this variable we call it variable called n1 alright so when we want to refer to the input by the user we can just write the text n1 okay so i will show you how it works exactly don't worry if you feel confused now let's just move on so we also need another number so let's do the same diagram again so we put the input followed by the n2 the n2 variable by the way you can name it anything you want i just put it as n one to just make it short so just treat our n2 as another box here that stores a value that the starter value input by the user so here's the interesting part after having gotten um a numbers two numbers from the user we want to multiply before we check whether they are greater than one hundred so we're going to draw a rectangle which represents a process a process and we're gonna create a new variable here called the product is equal to n1 multiplied by n2 sorry i use the wrong symbol n1 multiplied by n2 so what this process does is that it creates another variable called the product here that stores the product of n1 and n2 so imagine that my n2 has a value of 3 now so the user input the value 5 and 3. and what this process does is that it takes whatever that is inside n1 and n2 put it in and multiply them as you can see from this process so the product variable here will store the value 15 all right so that's how it works having done the process part now we want to check whether this product is greater than 100 so how can we do this so i'll just make it smaller to save space so we need something called the decision variable all right i think i missed this out when i explain this so i'm going to go back so what the decision variable does here as you can see from the slide is that at this decision variable point it will ask a question whether so for the alarm clock app is that they will ask whether time is equal to alarm clock if and there will be two arrows coming out from this decision variable from this diamond and depending on the result yes or no they will do different things so i'm going to show this in this example here so we want to check whether product is greater than 100 so first of all i'm going to draw a diamond here okay a diamond here and i'm going to ask the question is product greater than 100 so this is the point where the flow chart gets a little bit complicated so let's withdraw two line two errors out of this decision variable so it's either a yes or no question according to the specification we should output the message greater than 100 if the product is greater than 100. so from this variable here product greater than 100 if it is greater than 100 what we want to do is that we want to output a message 100. so i'm going to draw the output symbol which is again a parallelogram and then write out the output keyword okay let me write it the output keyword and followed by the message i want to tell the user which is greater than 100. 100 and that's that's the end of it we have done it but if the product is not more than 100 what do we do so let's look the program say the program will loop until the user does not want to input any more number it doesn't give instruction on what we should do if product is less than 100 which means we do nothing so we after we do nothing we want to ask the user again whether they want to continue the program so i'm going to create another input variable here as let's give it a variable called continuum continue basically store let's create it continue continue variable basically stored the answers of whether the user user want to continue or not so if the user key in the value y es yes i want to continue then we just continue if not we do we just terminate the program and let me show you how to do this so so we will from this diagram here the output i'll go back to here because after we can output a message we want to do ask the user again whether they want to continue so we give an input here and we want to check the continue variable whether it is equal to yes so if the user type yes this yes variable will be value will be stored into the continuum variable and now we are actually matching this to this referring to this value let's check whether continue is equal to yes so let me again resize it to make it more manageable so again we have another decision to make if the user said i want to continue the program that means he wants to do it all over again what we do just draw an arrow back this is basically called loop to the beginning of the algorithm so that the user can key in the value n1n2 again whereas if the user type so let's put a yes here if the user said respond is not a yes which means he wants to terminate the program we'll just draw a terminal diagram here which basically say the val oh it's automatic let me draw a rounded rectangle that's very important we just type in a value stop here so that's the end of the algorithm we have drawn the full flow chart of how this algorithm works if you look at the beginning first of all we asked the user were to input two numbers and one and two by using the input output symbol the parallelogram and the user's input will be stored into the n1 and then two variables okay whatever they type in will be stored here and after we got the numbers we multiply them and store the result into a product variable all right again you can name this variables any names that you want and we'll check whether this product is greater than 100 if it's greater than 100 will output a message using the output component if not we'll ask them hey do you want to continue and depending on the result they gave us we go draw an arrow to the different parts of the program eventually we terminate it if the program user doesn't want to continue so that's flowchart one flowchart so let's try to solve another problem to give you a better understanding so let's go back to our slide here so another problem here is that tickets are sold for a concert at 20 each and if ten tickets are bought then the discount is ten percent twenty tickets then the discount is twenty percent no more than twenty five tickets can be bought in a single transaction so you're asked to design a program that can automatically calculate the cost of the purchase draw a flowchart so again if you want to try this out using whatever you have learned so far just try to do it and instead of waiting for my answers um if not you can just watch how i do it again let's just break this problem down into input output and process so the input is that we want the number of tickets that the user wants and the limit is 25 and the output will be the total cost need to be paid by the user and the process is that if the user buy 10 tickets we're going to give 10 percent 20 tickets just 20 so let's go to this app here to to draw the program again in the beginning we usually draw this symbol called the terminal symbol start we just draw a star program here and now we want to ask the user for a value which is how many tickets do you want to buy so we need the input components we input components and let's name it as number of tickets know of tickets so i'm going to create i've created a no of ticket variables here this is just for illustration so followed by okay now here is the point uh here's the key thing we need to ask which is is the value entered by the user the one that is required by the program if you look at the program requirement they said no 25 no more than 25 tickets can be bought which means if the user were to key in the value 26 we are going to ask here him or she he or she to keen again so here we need a decision variable so let's draw a diamond here is that we need we want to ask whether number of ticket here is greater than 25 it's greater than 25 and if you want to be more detailed you want to include more details you can also add another one is that oh oh the number of ticket is less than zero less than one which means the user cannot key in any value like negative five or zero it just doesn't make sense what are you trying to do right so you can use the all keyword here is that either one of this if the condition is met we're gonna do the yes path so again we have a yes and no path so if the condition here is yes the user has entered an invalid input we'll just draw an arrow back to ask the user to input again so we don't allow them to proceed to the the other part of the program and if it's not which means the user has key in a valid value we are going to write a note here so we can the user can continue to do what it's doing so let's say let's continue the no part here which means the user has key in the value between 1 to 25 so now we need to check whether the user is eligible for a discount and the specification here is that if 10 tickets are bought more than 10 tickets is 10 off if he got 20 tickets more he's going to get 20 off so we need a decision variable to check whether the number of tickets met a condition here so this is going to get a bit complicated better with me so first of all we need to check whether the number of tickets here is greater than 10. it's greater than 10. because it's only when the number of tickets greater than 10 that he or she is going to get a discount so if it's greater than 10 yes here and no here let's do the no part here if it's not greater than 10 it's maybe it's from zero to one to nine so we'll set the discount let's create another new variable d as zero the day stands for discount let's give it a value of zero if the number of tickets is great not greater than 10. whereas if the number of tickets greater than 10 we have some stuff to do we need to do some more decision variable is that even if the number of tickets greater than 10 we need to check whether it's greater than 20. so let's do another check is the number of tickets here greater than 20. again this is important because number greater than 10 and 20 have different discovery so if it's not greater than 20 we know that it's from the margin 10 to 19. so the user will get a discount of 10 let's put 0.1 i will show you what how we use this values later whereas if the user key in the number of 20 more than 20 the discount is going to be d equal to 0.2 all right so again i need to resize it so try to absorb whatever i'm saying now so having calculated like what is the discount we are going to use this discount value to calculate the total ticket price so we know that okay so we know that the price for one ticket is 20 and we need to calculate how much exactly does the user need to pay so let's create another variable here called price so we're going to write price is equal to 20 multiply sorry is the number of ticket how much how many tickets the user have bought multiplied by 20 which is basic calculation number of tickets multiplied by price and followed by how much discount we want to give it to him so i'm going to write 1 minus d which means that if the d here is equal to zero which means no discount the price will be multiplied by one whereas if the discount is equal to 0.1 it's going to be 1 minus 0.10.9 which will give you the price for the ticket after a 10 discount this is the same for d equal to 0.2 so let's link this back to okay we can do it here just to ensure the continuity of the program all right so by using this process variable we have calculated the total price for tickets so after that we will we can output this output this price for our user and that's the end the entire flowchart for this question i know this is a little bit hard it requires some problem solving skill so make sure if you still want to understand try to do it yourself first and then rewatch this part of the video to understand how i use the different components of flowchart to solve the problem all right let's move on to another way we can uh design a program which is algorithm and pseudo code so let's define pseudo code the word pseudo means fake and pretentious so think of pseudocode as kind of fake codes they are not like programming languages that require syntax but they are just a way for us to write down the algorithm of a program so let's say um i have an example here this entire pseudo code you don't have to understand what it means now basically talk about how we can sort an array of numbers so pseudocode is the standard method of showing an algorithm computer scientists love to use this it uses english keywords to that are very similar to those used in high-level programming language this is important so that after the user written this pseudo code they can translate this pseudocode pretty easily into any programming language they want it's like a framework that you need when you are writing an essay like that and it's not bounded by the straight syntax rule of programming language and the person reading the serial code does not need to have knowledge in a programming language so you don't have to know python or java to understand this code so this is the reason why it's used in various computer science research people because different computer scientists they learn different programming language so by using pseudocode this information become universally understandable so to understand how to write pseudocode like this we first need to learn the different elements of the pseudo code you'll find things that are very similar to the flowchart so let's start off with assignment statement so a value is assigned to items or variable so this value will usually be assigned to variable if you remember the question that we do in flowchart we kind of assign this variable n1 to whatever the user has key in so think of the word variable as a box here that stores a value that we can refer to it whenever we want to all right and the value on the right here it can have one value or multiple value let me show you how to do this let's say you want to give the variable x a value of 5 you can write in this way which the 5 is pointed to the x which means it's stored inside the variable a box here called x similarly with the name atom and if you would you can also assign a variable with multiple values by using something called the operator by the way this is the multiply operator so by doing x equal to 5 times 6 the x variable here will contain the value 30. all right the name here will contain the variable hello atom and so on and so forth so here are some of these the operator that you might find useful whenever you want to assign uh create a variable so the benefits of having a variable is that instead of doing whatever that is on the left hand side let's say i want to output all this value many many times instead of copying and pasting this value one by one i can assign this value this random string here to a variable called name and whenever i want to refer to this name instead of outputting the entire string again and again i can just say i want to output name and then the computer program will find out whatever that is stored inside the name variable and output accordingly so let's try to do some exercise to explain this entire pseudo code things i know it sounds pretty abstract but let's try to do this so your task is that so let's say i have a variable called cos again picture it as a box here that has a variable five and this the name that we give this box is called cost and by using this variable you need to create the following variable using a different operator so let's try to solve it my working space so i want to create a price variable it says this price variable should have twice the value of cost well one common mistake is that people would just write okay 10 well this is not what we want to do because cost can be any value we want it to be dynamic which means whatever cost is i want the price variable to have double the value of it so what i'm going to do is that i'm going to write cos price is equal to cos multiplied by 2. you can always refer to this mathematical operators to find out the symbol for a different operation all right multiply here is a star so i'm going to write price equal to cost multiplied by 2. and the second part text is equal to 12 of the total price so let's create a text variable that stores the tax value is equal to 12 of the total price so what i can do is that can you surprise it multiply by 0.12 so that's the way we calculate a portion of the value and followed by another value selling price and it's calculated using price plus tax so let's do this price plus text and the fourth variable they want us to do the gender variable that contain the value m so i will write gender here assign it to have a value of m and another valuable chosen variable assign it to a value of false so this is how we can assign variables either using just one value here or multiple value by using mathematical operators so you might not find it so this is the answer so another stuff before besides um and one value we can also assign multiple values to one variable this is what we call an array we can assign an array to a variable so what an array is think of it as a container that can store multiple items a container that can store multiple items what we have done so far is that let's x equal to five let's say we create this variable we are saying that this x variable has one value called five but what the array variable does is that it creates for one thing for one variable name let's say my class i assign it a value of an array of values a list of values here to this one variable so for instance in the my class variable you can store a list of names of your classmates of your or your students into just one variable so and this is how we the pseudo code the syntax that we use to declare an array in pseudocode first of all we use the declared keyword followed by the name that we give to the variable and the array keyword 1 to 10 here means that we are creating an array of size 10 which means this variable can store 10 values of string string is a data type basically means um like name here an alternative could be an integer integer all right which store number so you need when you assign create an array variable you will need to first declare what this array stores what data type is stores so enough a way to access one particular value in the array so sometimes we just want to access let's say the third third item in the array we can do this we can just draw a square bracket all right followed by a number let's say i want to do my class i want to assign a value of my name james into this array variable what i can do is that i use the variable name my class followed by a square bracket with a number inside denoting the position and then put in my vowel and this james will be stored inside this array variable so this is how we can access a particular element in an array so here we have a question here your task is to create an array variable called map list the array is size is 20 and it stores the integer data type how to access the 12 elements so um i will just draw it here i have not prepared a space what we can do is that we can write declare let's declare a variable called mac list basically store a list of marks obtained by a student mark list and we write down the array keyword so the array size is 20 so i'm going to write 120 of string because it's storing marks i'm going to write integer data type integer and how do we access the 12 elements it's easy we can just do mark list let's say i want to output the 12th element i'll just put output mark list followed by a square bracket number 12 and it will show me the 12 elements of the array so that's um just some understanding okay so let's move on to the next elements of pseudocode which is the input and output input keyword is used to ask the user for an input and the output keyword is to use to display information on the screen so it's again very similar to what we learned in flowchart so i have an application here that i want to show which i have written the program in python because one thing i realized when people learn pseudocode is that they can't picture what is actually happening in the program so i will move on to this application here called repo um let me uncomment this so this is a platform where you can write down your code to to just show how the program is working so remember the program that we does we create a bunch of variables for cost tax and price so in when we write it all this code in programming language this is how it works so let me run the program it will prompt me to enter the course so this is the input component of the serial code or the flowchart so i can just enter any numbers so let's say my cost is ten dollars and what this program does is that it will calculate for me the selling price which which is which like you can got it by multiply the cost by two and then and sum it up with the text variable so we have this since this class is now about programming we'll do more in chapter eight but i just i'm just showing it here so that you know what this pseudo code will do when they are being translated into a programming language like python all right so this is how it works as you can see again i want to emphasize the benefit of using variable here is that it can be dynamic let's say i were to run it again and i were to type in the value 1000 and depending on the cost value different output will be produced so this is the power of programming and the power of input and output code here and variable all right so let's go back to this code first of all what this code does is that it asks the user for an input so when we write the keyword input course the program actually does two things first of all it asks the user for a number for a input and after that the second part of this line is that whatever the user key in it will be stored inside a cost variable a cost variable all right so let's say i change the value 1000 the cost variable will contain will now contain the value 1 000. so if you look at the second line of code price is calculated using cost multiplied by 2. so what this programmer does is that we'll look into the cost variable and see all right what is inside the cost variable and then multiply it by two so in this case the price variable will have two thousand and the followed by all these lines of codes and last but not least we learned the new thing is the output variable not the variable the output keyword it will output whatever the program has calculated just like what i have shown you in my program so that's the input and output part of the application so let's move on to conditionals which is an element of the serial code that allow the algorithm to do different things depending on different input and scenario again you can relate this back to what we learned in flowchart the decision variable element the keyword that we use is if then else and case of otherwise n keys i'm going to explain it one by one by first showing you the code followed by a proper dissect of how this keyword works so just try to read this code here we have this bunch of code and as you can see it's pretty similar to what we do what we read in english so you can roughly get the idea of what this is doing it basically first asks the user hey what is your name what is your age and if the user age is less than 18 then it will output something called a child if not the statement under the else element will be output you know we say yes and you are an adult you are a child if then else and if so if we were to properly dissect it let me explain we first if you look at those words that are highlighted in red color these are the key words which means you have to include them every time you write a conditionals if then i was and if all right so the key the word after the word if is we call them a condition a condition will produce a value of either true or false if you look at our example here if h is less than 18. so in this case it can either be a true or false scenario either you are younger than 18 or you are older than 18. so we have a true and false value here and followed by the then keyword which means the condition is met if h is less than 18 then we output the char name so this is the part so let me use another color the code that is encapsulated by this rectangle is the code that will be run if the condition is true but if the condition is false this will be the code that will be run all right and after the we will the end if statement has ended we'll just use an and if statement to signify the end of the algorithm all right so this is how we use the if then else statement so to to use this statement better you will need the comparison operator like the greater than less than equal to to basically creates the condition here the condition here you need to use the comparison operator so again uh let's try out a question so using what you learned try to do a two days before i explain the answer you can pause the video because ultimately there's no use remember all the syntax if you can't use them to solve a problem all right so let's try to solve this problem our pro our question is that we need to write a program in pseudocode that asks the user to input his height or and weight and if the height is greater than 170 and weight is lighter than 85 will output the message you meet the requirement otherwise you need to be taller and lighter so let's try to write it out first of all we need to ask the user to input his height and weight so i'll just write an input keyword again remember a weight so this does two thing it asks the user for his weight and then store this number into the bait variable okay we have a weight variable here and then let's input another variable called the height so this is the point where we want to make a decision we want to use an if statement so we do this if let's use another color for condition the condition for um the question is that the height is greater than 170 so just write height is greater than 170 but that's not the only condition that needs to be met um the other condition needs to be met too we'll use the n keyword to state that these two conditions need to be true in order for the whole condition to be true and weight is lighter than 85 if that is so let's use we'll have the then keyword if this condition is true according to the question what we need to do is that we need to output the message output you meet the requirement you meet the requirement if not we are going to output a message else you need to be taller you need to be taller i'll just skip this to save time and follow by the end if statement and that's it that is how we use an if statement to write a program that makes decisions based on what the user key in so this is the answer hopefully you got it right too if not you can just do it again so let's move on to another way we can do conditions the another way program can make a decision is to use the case of otherwise an nk statement so here we have a code here again you can read it too and see whether you understand it before you dislike and how this work is that we have three different keywords here first of all we have case off basically look into the variable so first of all this program asks the user what food do you want to buy and it store the result into this variable called food to buy and if you look at these two lines here these are the options that the user can key in so if the user will key in the word milo we would do this line of code the blue color block boxes this line of statement will be executed and if the user were to key in the word biscuit this is the word that will be output the code will be run instead all right what if the user doesn't key in any of these two values let's say you can um i want ice cream in this case or every other input will be full will fall into this otherwise condition in which you need to output the canteen does not have this but and followed by the keyword and case all right so again let's do an example to show you how this works a program's problem statement here is that we need to ask the user to input his or her grades and if the grade enter is a we output the message excellent b not bad huh c fair and d why do you sleep in my class for all the other values we output invalid input so how can we do around this again let's start off with the input we can write something like the input great let's give it a name of great and we are going to use the keyword of case of case of followed by the variable that we want to look into when solving this uh by making a decision and the in the variable that we care is the variable grade and we have different conditions here right so if the condition is a oh i've used the wrong pen the condition is a we are going to follow by a colon this is these are all the syntax that you need to remember colon output we'll do output excellent and if the grade is b write output not bad huh so these are all the options c and you do fair and i believe you can see this is pretty easy and not very hard quite straightforward and d will write something like why you sleep in my class i'm gonna skip that to save time and here's the interesting point we need another keyword called the otherwise keywords in which if the user enter a value like besides a b c or d we are going to do the otherwise point i'm going to output invalid input input so last but not least we can end the statement with an nk statement so that's the end of this question and how we do this so this is the answer you can check it out so having done the condition conditional pseudocode part let's move on to the iterative statement in which it is one component of pseudocode that is super super useful and which they allow the algorithms to repeat certain actions without writing it over and over again so let me explain we have three different types of statement here i'm going to explain it one by one so the first statement that we will be using is the 4-2 net statement it basically it is basically used when a set numbers of repetitions are requirement that means we know how many times we want to repeat how many times to repeat so i have a code here i'm going to dissect it and i'm going to show you in python code the power of this so we have a few key words here is that first one is 4 2 and next all right so what this does is that for counter equal to 1 what we are doing is that this okay let me um just clear all the marking or use a blue colored pen so what this counter one does is that hey we talk we are telling our program hey i want to create a variable called counter and store a value of 1 here all right to to just initialize the stuff my counter value is equal to 1 and let's look at the first line of code for counter equal to 1 to 10 what they are saying here is that i want the program to run continuously repeatedly until the counter value reaches 10. so this line of code the second line of code will be run repeatedly repeatedly until the counter value reached 10 reaches 10. all right so and followed by the third line we're going to implement that counter by one so how it works is that let me clear everything it's at the beginning the counter value has a value of one and you're going to run this code so the device will output the value one here and then we'll move on to the next line where i say next counter so this line of code basically increment the counter value by one so if you look at this counter valuable we can increase it from one to two so now counter have two and instead of moving down the code what this program does is that it will go back up to this first line of code it will check now my counter value is 2. it will check whether this counter value is equal to 10. so since my counter value is 2 it's not equal to 10 it's not going to do anything it will continue to the second line of code it will output the value 2. so i'll put that value too and then you'll go back to the line of code where we call next counter then the counter value will go to 3 4 5 6 7 8 where it will be output continuously and until a point where the counter value is incremented until 10 so let's look at the first line of code for counter 1 to 10 at this point the counter value is already 10 and instead of executing the second line of code what this program does if the counter is 10 it will go it will skip the code here and instead do whatever code that is here and this is how a for loop works so i'm going to show you how it works in python um let me delete the first part of the code to show you how so i have written this for loop codes in python form and if i were to run this code auto is only two line of code you can see that the value from one to nine is being output which means this in line find the keyword print counter is being executed over and over again until the counter value is equal to 10 and if i were to increase it to let's say 100 okay right i'll just if you were to replace this 10 here into 15 you're gonna get 1 to 15. of course there is some syntax um here if you write 10 is the python is really going to run until the word night we definitely look more into how you can write this codes and python in chapter 8. so stay tuned for that so this is uh one iteration which is the fall to next iteration um we already discussed this so um here we have a code here so try to read this and see whether you can grasp what it is doing so i have for counter from 1 to 10 which means i have a counter value of initial value of 1 and the 10 is the ending value and for each iteration i'm going to output hey please enter the name of the student i'll put keyword i'm going to say another thing hey input anything and then store it into this student name counter as you can see we have a square bracket here this means that this is an array so what this code actually does is that it asks the user for 10 names iteratively and then place each name into the array so if you can see the initial counter value is one so let's go through the code output enter name of student let's say i enter a name called abc input and whatever i keep in here will be stored into student name square bracket counter so a b since my counter value is equal to 1 here so i'm actually inputting my counter into student name one remember this is how we refer to a variable so my abc will be inputted into this array and when they click next counter it will increment the counter value by one so my counter value is equal to two and if you were to input then your value again let's say um you put def sorry i'm not very creative and df will be entered into this the second element of the array until the counter value reaches 10. and basically this code populates the entire array with all the values so this is one just one method of how you can use iteration and let's proceed to another form of iteration iterative statement that you can use in which in this case the number of repeats is not known but this statement is completed at least one so we have two keywords the repeat keywords until it's pretty uh intuitive what it says that basically we repeat whatever code that is written here until the keyword here until option is equal to negative one option is a variable so um let's go through this program first of all the programmer output hey hello and then it will ask us for an input and the input that we give will be stored inside this variable called the option variable and if we were to t in let's say a key in the value five okay receive and we'll move on to the next line we'll check whether option is equal to negative one if it's not again this line of code will go back to the repeat here and until i key in it will say hello again until i key in the value of negative one option including negative one if the condition again this is a condition here if this condition is negative one yeah then i won't go the code won't go back to the repeat statement again it will just move on to whatever code that is beneath it so that's the end of it let's repeat until so um here we have a question what does the code below do pause the video and see whether you can get it all right so what this does is that in each iteration we ask the user for a mark so if you can see this code this chunk of code is being repeated and we we just keep asking the user for a mark and then we sum it up with uh in in the total variable and the program will stop when the user key a value negative one as shown by the condition here so one special thing about this statement is that this code will run at least one time because the repeat statement is here and let me erase this this code will run one time regardless of what the user key in in the beginning all right because the condition will only be checked here all right if i were to create a variable called mach equal to negative two it will still this chunk of code part a here will still run despite the condition not being met sorry because the condition is not checked until this chunk of code is run so this is one thing repeat until we run at least one time regardless of the condition so there's another type of iterative statement the third type is that where the number of repeat is not known is that it will it might never get completed even for one which is the wow do and while loop the same program here we ask the user from mac until and sum it all up until the user key name the value negative one so you can see here we have three keywords the wow keyword do keyword and and while keywords so it reads pretty intuitively what i say here is that while mark this is the non-equal sign while mark is not equal to negative 1 i'm going to run this chunk of code i'm going to sum up the total mark i'm going to ask you to input your mark again but if the mark statement is equal to negative one i am going to jump straight to the n while statement so this is the breakdown this is the condition where which determines whether the loop continues and this is the chunk of code that will be run if the condition is met and this is the end wall keyword that signifies the end of the key key loop the while loop so um we have another question here that says we are going to ask the user for a number iteratively all right then the square of the number will need to be stored in an array which means if i were to key in a value of 3 the square of the value 3 which is 9 will be stored into the array the program shall halt when the user enters the value 0. so to do this we need to first declare an array so which is shown here so if you notice um we have a different kind of array here so if you don't remember this is the keyword this is the name of the array and this is the keyword again if you look at this array it doesn't have the n value this means that this is a dynamic array which means we don't know how many how big the array should be so we just create an array that can be of unlimited size which is doable in python nowadays and of integers which means we want to store an integer value so you can see here i've placed an illustration here to show you what is being created an array of unfixed size so i'll create a variable called counter one as my counter and then i'll ask the user for an input hey can you give me a number again remember the specification is that we square the number store into array and then we just do this code while the number is n equal to zero we'll do this so and let's say that the user first key in the value five so what the code does is that it will check is the number what while the number is not equal to zero is it not equal to zero yeah we got the phi so what it would do is that it would do run this chunk of code point a here and it will assign the value number power of two this is the word for power basically we're doing this power of two which is 25. we are going to assign it to this square num array in the counter variable all right so this counter we know that the value is one so in other words this value 25 is going to be stored in the first position of this array okay and after this step we are going to increment the counter by 1 because in the next iteration we don't want to put that value into this position one again we want to put it into position two all right so again we'll ask the user to input a number after uh the first step so let me first erase this i'm gonna put 25 here so let's say the user key in another value let's say 10. again this algorithm will check is the number what is the number not equal to zero yeah 10 is not equal to zero i'm going to run this code again number power of 2 i got 10 to the power of 2 which is 100 will be stored assigned into this array in element counter so remember just now we just incremented the counter so counter value is now two so i'm storing this 100 into the second value second position of this array and again i can increment the counter by one and then i'll ask the user again for a value again i need to erase this so now let's say the user don't want to doesn't want to enter a value again he'll just enter value zero again this loop will check is the number not equal to 0 no it is equal to 0. so what this does is that instead of running this chunk of code this code will go straight to the end while statement here so the program will terminate and the program won't be running again so this is the the way we use iterative statements and conditionals and i understand that in the beginning it might be very hard difficult to digest it to even solve the problem but just like mathematics for programming and writing codes you need a lot of practice to know when to use the right syntax so my advice for you is that just try to pause my video whenever i do exercise and try to do it yourself and cross check with my answer to check whether you got the correct answer or not all right so that's the basic part of pseudocode we'll definitely go through more of it in chapter eight um when we can write it in python where you can see the real effect but before we go to chapter eight let's move on to the next part in this chapter call the standard methods of solutions so what what are they so when you are doing programming there are sometimes many operations that need to be done in a regular basis so computer scientists um as maybe the author of this syllabus has classified it into multiple operations that we need to do in a regular basis so first of all is the totaling method totaling means keeping a total that values are added to so here we have an example keeping a running total of the marks awarded to each student in the class let's say you have an array here called student mark you have an array here and you want to write a program that calculate the sum of all these marks okay so what we can do here is that uh you can use an iterative statement to go through to go through this element one by one you can create a total variable that's not a total and then just create an iterative statement to go through these values one by one and sum them all up store it into variable and boom you get the result you get the total and this is exactly what this code is showing us first of all we create a total variable which has the value of zero and the class size to for our follow-up to know when to stop our loop and by just doing this follow we increment the value that is stored inside the student mark array one by one and then store the sum into this total variable all right and then after you teach your written iteration we increment the counter so this is total we total everything that is being stored in an array so another very similar operation is counting so imagine the same array and you want to calculate how many of the students here pass their exam given that the pass mark is 50. so this is what the code will do uh you will create a variable called passcon which stores uh the record of how many students pass and you just go through the array one by one and if you find a mark that is above 50 let's say you will do this you then increment the past count by one so in other words you are creating a counter program that calculates how many elements inside your array that meets a certain condition in our case how many students pass the exam so if you can see here this is how they increment it if one fact is that notice there's no else statement this is because um we simply don't want anything to be done if the condition doesn't matter that's that's why we dismiss the else statement here and this is the counting operation so we have um a question here write an algorithm to find the total number of students whose name is ali i know it's kind of weird but we can write it so let's just create a variable called ali count that stores the value of zero and we are going to go through this array check one by one whether uh anyone here is for ali so i'm going to create a follow for counter let's give it a value of zero one two let's say my array size is six i'm going to write six for counter one to six i'm going to check whether if the student name in this position okay student name is an array so when i write a square bracket i'm assessing one element inside the array if the element is equal to ali then i'm going to increment my ali count by one ali khan equal to the existing ali count plus one and then i'm going to write our next counter which increment the counter value so that i can check another value so this is how we solve it and this is the solution again try to solve it if you don't know how to do it um the way we we can you can use multiple methods to solve it and this is basically counting and another common mechanism operations that need to be done is the maximum and minimum operation in which we write code to find what is the maximum value in an array so how we can do this i'll just explain it in simple form instead of just show you the code what we can do is again we go through this array the element in the array one by one and we keep we create a variable called max and then whenever we find a value that is the biggest among all will store these values into this max variable so imagine um i'm just going to clear this and type so let's start with the first value so i'll just create a variable variable called max and min um let's say the max i give it a value of 100 mean i give it a value of zero all right all right sorry i used the wrong thing max i give it a value of zero i mean it's equal to 100 um the reason i'm doing this is because i want any values to be that is bigger than zero to to have the max value first so let me show you imagine i'm going this first element which is value 70 i'm looking at it if it is greater than max i'm going to put it as max so since 7t is greater than zero i'm going to update my max to have the value 17 and if it's less than with a minimum i'm gonna get give it a value of 70 again i know it's a bit confusing bear with me and let's move on to the second element 75 so now you should notice that 75 is greater than 70. so we can write our algorithm in a way using conditionals if 75 is greater than 70 i'm going to update this max to store the latest maximum value so if 75 equal to 70 yes i'm going to update this to store 75 and at the same time i'll check whether 75 is less than 70 is it the minimum which not so i'm going to skip this not going to do anything so move on to the third element 80 is 80 greater than 75 yes it is the maximum now i'm gonna update this is it a minimum no and i'm going to just go through this algorithm again and again until the last element and eventually my max element oops my max element here will show me the greatest value in memory greatest value and my minimum will show the smallest smallest value and this is the algorithm i'm not going to go through one by line one because it's pretty confusing there are two methods first of all you just set the maximum to zero minimum to 100 so that um the first value is always the maximum and minimum or you can do a most straightforward approach you set the minimum and max to be the first element in the array so another operation that is often need to be done is to find the average which is used frequently in an excel file so this is the code for every error reading basically it's just we first total something and then we divide the result by the class size so if you look at this element here we just find the sum of this everything and divide by how many one two three four five six the ten elements here so average is just totally divided by the number of students in the array or items in array so linear search this is a type of search this is interesting in which this operation what it does is it searches the array for a particular item requested by the user so i have a bunch of student name here all right so let's say i want to write a program to search for a student name called lyn and how this um how we can write this code is that we can just go through each element in the array one by one and check whether the existing element is equal to what we want so first of all we just go through decay first element is it equal to lym if it's not i'm going to go to the next array next element in the array and check whether it matches our existing requirement so if it found the item it would just exit the program and tell the user i have found so this is the essence of linear search it searches the program linear in a linearly fashion until it finds the item or it if it doesn't find it will just tell the user i don't find the item so this is a useful algorithm so this is the code for lineage search again i'm not going to go through that one by one just to give you an idea of linear search all right so another the last operation that is very common is bubble sort and think about it when we are using an array we want sometimes we want them to be sorted either alphabetically or in numbers so for instance if you have a list of numbers you want to sort it to from big to small small debate and so on or if you have names you want to sort it in alphabetical orders if you look at all the apps that we have now they usually have this function so um to explain how bubble thought work i have this video here which i believe that if you watch this video it's going to be more effective than me explaining here because the author of this video has created animation to show you how numbers are being rearranged during the algorithm to to achieve the final form the sorted form so i'll put down the video link and the video description so that you can check it out all right so that's the end of this um subtopic we'll move on to validation and verification which so in order for computer system to only accept data inputs that are reasonable and accurate so for instance if you want to request for the user and for an email you want them to really type in an email instead of a number so instead when we want a specific input to be um given we need to examine them before we accept them into our system before you use them to calculate anything so we have two ways for um validation no we have two ways to check the inputs which is validation and verification let's start off with validation which ensures that only data that is reasonable is acceptable and there are multiple ways of validation okay it's checking if the data is reasonable and if the data is rejected the message should be output to tell the user hey you are not giving me the correct input so the first type of validation is range check is they basically check the value of a number is between an upper or lower value so for instance when you're writing a program for um an exam molecule you don't want the user to key in a value of negative five because no one can have negative five in the exam it would be pretty set so you want to limit them to enter the value from 0 to 100 so this is what you can do you can write code um the iterated statement that we have learned and that we keep asking them for a student mark for a mark until they give us a value that is reasonable means we don't let them to proceed to the next part of the program unless they give us the correct value and these are the quotes that you can write to check that i'm not going to go through that range check basically check the range of number then another type of check is the length check operation um they are usually check use and when we want to check whether users enter let's say a password we want them to enter a specific length not too short not too long so here we have an example here this input will be accepted this will not this will not we can by this way we can limit what are the types of information that's being entered by the user so here is the code of how to do it if you notice we have used something called the subroutine here um i will talk more about it in chapter eight but what this does is that it will take in the password value and return the length of the password so in this case the code here is that um please continue to input a value here and if not if you look here if the user doesn't key in a proper value let's say if the length of the password is greater than 20 or less than 2 the program will output a message telling the user this is what is wrong your message is too long or too short and but if the user has cleaned the correct length if it in other words it means this condition all right and the program will then continue instead of we keep asking the user to enter the value so this is length check followed by the next type of check is type track so sometimes we want the user to enter a numbers instead of alphabet we can do that too so say for example they only accept an integer so we only want a whole number instead of you know 3.2 or 3 in alphabetical order so again this is how we can write it in code so notice that i don't go through a lot of the code very well because i think the point here is just to give you an idea of what types of check we can impose on the user all right so um a special notes code here they basically said input the number of males so obviously we want the whole number instead of a value like abc would it make sense so what this code here highlighted in yellow does is that this will return whether the variable is a whole number all right so this is the essence of it we learn more about the div function uh basically taking a value to see the division but it is also it can also be used to check whether a number is a whole number so that's type check and presence check so a present check ensures that some data has been entered and that value has not been left blank so for example when you sign up for an online uh online website when they request for you for a website they will track whether you have the word at gmail.com or whether you have actually entered anything we'll check the presence of something and this is it if the email address enter is an empty string we call it empty string it does nothing there's nothing else we'll ask them to output something else input something else so followed by format check check that the character enter confined to a predefined pattern let's say we want to a program that only accept a text code and text code you should have start with tc all right so you want them to enter it in this format so you can check whether okay this will be accepted second one will also be accepted but if they use it key in ac it won't be accepted all right we want them to confine to a predefined format so last but not least is the check digit operation um it is used in barcode we also learned it is in chapter 2. what it does is that the final digit of the code will be used to check whether there's any data entry arrow in the first 12 digits so feel free to refer to my chapter 2 video where i explain this in depth but this is also a type of validation track so here we i have some questions please feel free to pause it to see whether you know for each bullet point do you know which validation check you should be using so i'm gonna pause it so the answer for this first one entering a telephone number we can do a line length check um so for instance one two three the one two three cannot be a telephone number we want to check the length type whether it's a number from it whether it um matches the format set by order used by all the mobile phones in your country enter a pupil's name again type check we want it to be alphabet and also a part number in the form something like that it will be a format check because it needs to match this format so this is testing okay how we can ensure the user enter values that we we want on the format that we set the length that we required and another way we can do um check on the user input is through verification it it's a lot simpler than validation there's no code required for verification it is used to verify whether a user has entered the correct data and the first method is very simple double entry it is used in almost all the website when you keen password is that you key in your password two times so that you know you don't have any typo when keying in your password and the second thing is even i feel it's a bit nonsensical but it's included in the syllabus it's called screen and visual check basically just after you enter your data you check whether the data entered is the one that you intend to enter by just looking at it so that's screen and visual track all right so that's um that's how we check the in the input data we use validation or verification so let's move on to testing which is the fourth step of our pdlc remember after coding we test the data so just some information here a program needs to be tested terribly to ensure that it is working as intended because sometimes programmers could make mistake we could um have tasks so we need to do some testing before we launch the program to the whole to everyone so before each a whole system is tested each subsystem is tested separately just like what we said a software program can be separated into multiple small parts so we test them one by one so in order to test the solution throughout it may needs to be worked several times with different types of test data so we need different types of test data for testing so here are the four types of data that we can use to test our program so imagine that you are writing a program for to calculate the average mark for all the marks in an array all right the normal data that is entered again mark the value should be from 0 to 100 so normal data will be valued in this slide here every value here is within uh one two hundred so we get correct average score if we were to calculate the average mark and as for second type of data is called the abnormal data in regards to your problem data that a program should reject so for instance here we reject the value negative 5 because well no one can get negative value for the exam so but if we our program were to allow this program to go through without checking we'll get an incorrect average market because the negative 5 value will lower down the average mark for the class so there's in other words there's a buck in the program so this is abnormal data extreme data the type of data which is the largest and smallest value that normal data can take so in our case here since max is 0 to 100 the extreme data very extreme at 2n is the value 0 to 100. all right last but not least we have the boundary data this is a bit tricky this one at each boundary two values are required one is accepted and the others is rejected so scenario we have scenario here let's say your program only accept the value from 1 to 10 and we know that the extreme data that we learned just now is 1 and 10. so the boundary data is the data just one place outside our extreme data so here i have in my slide the extreme data is 10. therefore the boundary data just beside the extreme data will be 11. all right another extreme data is one therefore our boundary data another value for boundary is zero so as you can see in a program there are two two different extreme data here okay two extreme data we also have two boundary data so let's have another example let's say a program only accept value from 4 to 15 we know that the extreme data here will be 4 and 15. that's the biggest and smallest value the program can take so the rejected data at the boundary data first one should be one place below four which is three and one place after the maximum which is 16. so we can check it yes this is the boundary there so what this chapter is basically says is that for testing to be done to ensure that our program is running well we need to ensure that the program is being tested with all this type of data so that we can expect the unexpected all right we can know okay if the user entered this abnormal data what should we react so on and so forth so that's all about testing and let's move on to a very useful testing mechanism we know we have learned that testing data can be used to test the program and now we'll see how they can be used different types of data to test the program which is the trace table is a tariff structure approach is required to find out the purpose of an algorithm so this is the purpose of trace table and this involves recording and studying the results from each step in the algorithm and requires the use of data i don't think reading the definition helps so let's move on directly into how we can solve the problem so here we have a flowchart imagine that you want to test whether this algorithm is correct what we can do is that we can use something called a trace table alongside with some test data all right so let's try to do this this trace table basically recalls the value of each variable at each stage and usually in the exam you'll be given the test data so let's start the algorithm so first of all we'll start the program we know that the initial value for these three variables a b and c is 0 0 100. so what we can do is that we will put all this value into our trace table in their respective column all right since x is not defined yet i'm not going to write it and there's no nothing to be output i'm also going to leave it blank and after the variable has been initialized we'll move on to the input x again what does input x do it asks the user for a value and store the value into the variable called x but at this point you ask where does the input come from is our testing data here look at it our test data the first one is 9 which means the first input is nine so our x value here will be equal to nine okay look at um notice i write in the second row to just separate them so let's proceed with our algorithm here that's it if we have a decision variable x greater than five so x greater than b sorry is is it so we see that x is has a value of nine b has the value of zero yes so we'll move on to the yes path so what they want us to do here is that assign the value of x to b so originally b has the value of zero now b has the value of x which is nine so i just fill in the blank so let's proceed with our algorithm no so again another question here is is x less than c so again is 9 less than 100 yes we got the answer what do we do c will be assigned the value of x 9. all right and we'll move on in the algorithm a is it will update the value from a to a plus one so our value of a is zero so now it has the value of one so in this algorithm as i said is another decision variable is a less than 4 is our a less than 4 it's not it's 1 currently if it's not yes it's less than 4 i'm going to go back again we will do it all over again so i won't draw ever again so our next input is 7 i'll put 7 into x x is greater than b which is not 7 is not greater than 9 so i'm not going to do anything my b will remain the same second question is x less than c yes 7 is less than 9. so i'm going to update c to have the value of 7. increment a by 1. okay another condition is a less than 4 now it's not yet so i'm going to go back our next test data is 3 is x greater than b is 3 greater than 9 here no it's not so 9 will remain the same and i'm going to update c because x is less than c so c is great increment a followed by next input input update and four and until a is equal to four a is no longer less than four so we move on to the node path and we'll output b and c so what is inside of b and c is nine and one so i'm gonna do this 9 1. all right so that's the entire program for it by by looking at the trace table we can construct this trace table by looking at the flowchart we can construct this trace table pretty easily so another way we can construct trace table is by using pseudocode it's the same program as our last question here is the same program they did with the same thing it's just that it's written in pseudocode so again i'll just go through this very quickly you can try it out yourself yeah pause the video and let's first write down the initial value zero 100 and output enter 10 values so we have enter 10 values here what is being output your tens values blah blah blah and i'm going to repeat this statement so input x our input data is 13 is 13 greater than b it is then b equal to x is x 13 less than 100 yes it is increment a and we just do it repeatedly using what we have on the left hand side to update so which is not so i'm going to increase that 21 21 i'm just skimming it true because it's not very hard and last but not least 11 is x greater than b no it's not so i'm going to remain this is x less than c yes so c will have the value of 11. and last but not least i'll put the value b and c which is 21 11. so this is how we construct a trace table let me know in the description comment if you want me to do more positive paper questions to help you practice and i'll try to make them for you so in our next last subsection of the uh video it has it has been two hours which is um writing and amending algorithm so how do we know if an algorithm is wrong right how do we and ensure that these actually do what we do the first way we can identify the arrow is to use a tab trace table which is what we just learned so i'm going to do this trace table again and the description of this algorithm what they say is that this algorithm will output not out output the maximum and minimum value but we want to know whether this work we want to know whether this program is legit so one way to do this is that we're going to complete this trace level so i'll just do the initial value and input x our test data here first test data is 400. we'll ask is x greater than b yes so i'm going to assign it to 400 is x less than c um no it's not so c will remain 100 and a incremented next input 101 and i'm going to increase that to is 101 greater than b it's not and i'm going gonna go on see is it 1 is 101 less than c no it's not um i hopefully you can see some problems here the algorithm doesn't really find the minimum value all right so followed by 200 it's not it's remain so i'm going to speed this up 700 is greater than b we're going to update it and 4. and ultimately the program will output 700 and 100. so this will be the maximum and minimum maximum and minimum but if you look at the output does the program do well does the program meets its requirement it does not because looking at all this test data here the maximum yeah it is 700 however the minimum here should be 101 and not 100. 100 is just the the first value that's being defined so we can say that hey this algorithm doesn't do what it's intended to do and the reason this algorithm failed is that by declaring c to 100 at the beginning if you look at our algorithm we are declaring our c into 100 here this means that if the entire test data the minimum is greater than 100 the algorithm is algorithm is not going to detect it this is why all the test data cannot be classified as the minimum data because we initialize the c value to 100 in the beginning all right it still cannot be detected the same thing can be done here if our test data is all negative all right i'm going to do this again all right feel free to skip this to the end so our first theta is 7 negative 7 is negative 7 greater than b notice that my b here is initialized to 0. so it's not negative 7 is not 0 5. so but it's smaller yes it will be able to find the minimum it will remain the same until yes it will just remain the same because negative 7 is the minimum among everything negative 6 negative seven zero and four and it will output zero and negative seven again this program can find the minimum value is correct but the maximum value here among the test data should be negative three so it is outputting zero this means that this algorithm has done something wrong so max min is not correct again by declaring b to zero we can only detect a maximum value that is above zero since our test data nothing is above zero the maximum cannot be detected so of course we can have a quick face here yeah we can assign the b to have a very low value and c to be have a maximum value like 1 million but this program will still fail if we were to input we have a test data of one million and one and negative one million and one so the best way to do this the ultimate solution here let's review it is to let the first number to be the maximum and minimum so that we don't give a benchmark like that we let this to be the first element all right so this is one way we as from this example you should be able to see that now we can use a trace table to find out what's wrong with an algorithm the second way to identify the error of an algorithm is use self-generated test data so here we have a problem here you can read it basically we are used we use this to calculate ticket price we've done it in our flowchart example so this is the code for calculating the ticket price we first ask the user for an input which has to be again in the limit otherwise we'll just repeat the operation and then we'll do stuff so well how we can know whether this code is correct is that we create some test data to check the correctness of an algorithm so let's see i want to check whether this program calculate the ticket price correctly what i can do is that i can create a test data test data let's say my test data is that i want to have 15 tickets so if i have 15 tickets i should have this count should be 10 so what i would do is that will calculate manually just what is the price 15 multiplied by 20 and since it's 10 i'm going to multiply by 0.9 and i'll have the value of 270 buck so this is the correct value for the price so now we gotten the answer we know that it's 20 270 for 15 tickets we can just go through the algorithm by hand to try to go to check whether they are correct so let's say my input is 15 i already got the correct input i'll just go through this algorithm is number of tickets is less than 10 is it less than 10 it's not it's 15. so i'll just move on to this else statement this code will be implemented is it less than 520 yes it is then this count will be 0.1 and now n if and if so when they calculate the cost they will use number of tickets which is 15 multiply by 20 multiplied by 1 minus 0.1 so i got 0.9 and i can just calculate this to see whether this result matches the test data that i have given so by using this method by creating test data you'll be able to identify the errors in your algorithm so that's the end of this chapter it's been two hours hopefully you have learned a lot let me know in the comment section um on which topic you still need further clarification so that i can delve deeper into that and create videos for you to consume and thank you for watching that's the end of it see you soon