1. Home
  2. Explore
  3. Computer Science
  4. Python for Data Science

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Python for Data Science

Transcript

I'm going to talk about the focus of our course mastering Python for beginners in data science. So let me explain what kind of areas in this particular course we are focusing the most. In fact, because this is a course, for beginners, that's a beginner level course, we are not assuming the the course taker to have any experience whatsoever about any computer programming language before, not even not even the problem, problem solving paradigm that lies in computer

science. So, we will, we will focus on problem solving for a bit. And we will actually start from the very beginning what problem solving is, particularly in computer science. The second focus of this particular course, is mainly telling you why we are choosing Python, why Python is so important, particularly for data science problems. The third focus and the main core focus is to learn Python, obviously, once we know what is what what are the techniques

to solve a problem. And once we know that Python might be a very good language to go with, then what is Python, how to learn it? Well, the Python is the main core and main focus of this course, obviously, we will start from the very beginning, very, very beginning, which means we will start from how to install Python for example, we will start from there, and then we will see what are variables, I mean, very, very beginning, and then progressively we will be moving on and on and on to data structures to complex structures, but that transition from 02 onwards, that transition will be very, very smooth. I mean, whatever you know, so far, in the course, that will be helping you to gain more complex structures very, very easily getting the understanding of a lot of structures very, very easily. So in this Python, we will include all concepts of Python in general. And, and one more thing,

after I mean learning, despite on the way we the way we organize this course of learning this Python, you will be having an understanding of other languages as well. I mean, the contents here are explained in so general way all over the Python syntax, but the general but but but the concepts are expressed in so general way, the problems that we picked to solve for practice are so generic that you will after this particular Python course, you will be having understanding of programming languages in general. So data science is one other focus of this course, actually, the whole course is organized in a way that it teaches you about Python, it teaches you problem solving, it teaches you something about overall programming languages and how computer can be used to achieve the solution of different problems. And and using Python, of course, and then we will be introducing the data science packages

that are available in Python, because they are really, really fast, really fundamental, very easy to use, and very, very powerful to handle large amount of data very quickly for data understanding for visualization, for cleaning, processing, and a lot of stuff, what we are not focusing at because that's important. Knowing that what kind of things are are are the things that we are not covering, for example, we are not covering object oriented programming, we are not covering exception handling, we are not doing web development, or any general kind of tasks that are doable in Python, we are not focusing on those things. Everybody solves different problems every day. Some problems are easy to solve, and some are difficult. And yet some are impossible to solve. They are called unsolvable problems. But think about different instances of the same problem one needs to solve again and

again. For example, sorting the sale records. And let's say we are sorting the sale records with respect to the sale value. And we have to do it after every eight hours. If the number of instances if that number is huge, the optimal choice is to automate the solution if the automation is possible, but how how to come up with the automated solution to come up with a general solution that works for every instance of some problem. That is one thing.

But to get that solution running on a computer is yet another thing Problem Solving deals with formalizing a general solution for that works for every instance. And programming languages, like Python deals with the running of that solution on a computer. Python, as, as we will see, makes the transition from problem solving to the running solution much easier and quicker. And that's one big plus of Python. A lot of words, I know a lot

of words. Let me take an example to clarify what I said, Hold on till the end of this video. And I will make everything what I said so far, crystal clear. So let's take an example. Let's dive into an example to see what I just said. Let's say your a, and your friend is B. And your friend B is always willing to help you. Let's say you found such a friend. And then a just said, I want off just for some days. But be said, but what ghobadi enjoy.

He said, someone have to do my job in my absence. And then be said, That's it? Is that your problem? I'm available? As always go buddy, enjoy. Man. He said, great. You're a true friend. Okay, I'm leaving, wow. And be just said, Hey, wait, what do I have to do? What's your job? At the end of the day, I'm going to do your job. What's your job? What do you do? And then he said, after every eight hours, pick the email of the customer when the maximum

sales. So that's what you have to do. He said, Okay. But from there, I mean, I have to pick that email of the customer from where, where are the records? He said, Well, there are sales records. I mean, at the job place, there are sales records. And you have to pick the email of the customer with maximum sales. We said, Oh, okay. But wait, what, what should I do with the email that I just picked? Then he said, oh, there is an other record called

priority records, just write that email after eight hours, just write that email in purity records. And then be said, that's it. That's all your job. And he said, after so relaxed, he said, Yes, that's my job. That's all. No, think he leaves and later that day receives a call from B. And B said, I don't really know what to do. Can you tell me step by step? What to do? Focus on again, I'm reading this particular sentence again. Can you tell me

step by step what to do? I have sales records with me having all the records for the last eight hours, what to do, I just messed everything up. I don't know what to do. And then at the call, he just described a procedure to be for his job. That procedure or a general solution, let's see the solution. He said number one, start from the first record, there may be several columns of the record, the customer name, the customer phone number, the customer

email, the customer products that he buys and the total sales. And in the point one said, he said, start from the first record, and focus just on the sales column. Okay, then, then after that, go to each next record one by one, and find the record with a maximum sales. Obviously, once you have focused on the sales column, you're just comparing sales of different records with each other and will eventually come up with a record that have maximum sales. Number three.

If there are more than one records with maximum sales, it is possible that the maximum sales value let's say is 100, whatever the units are, and there may be two or three or maybe five records with the maximum sales 100. Then which one to pick, as described here in Step three, that if there are more than one records with maximum sales, then pick the first one from top to bottom and ignore the rest I mean, whichever is the sole. So let's say you have five records with maximum sale value, which record appears first from top to down, just pick that one and ignore the rest. That might be a policy that might might be a tie breaking policy, but just do that. And then the fourth step is focus on the email column of the record you found in step three. In Step three, you found a column with maximum sales. Step five, see the email address and write that address in the priority records. So that's for the

eight hours, then repeat this process, see the step six, then repeat this procedure, after every eight hours, I'm gonna repeat this procedure, I mean, you'll see the the solution a is communicating to be in in this in these kind of steps. It it gives me It gives a precise idea of what to do. Still, there may be some, there may be some questions to be is maybe asking, for example, B may ask how to find out a maximum, B might be

that person who don't know how to find out the maximum. And third, for example, another question we might may ask is that when when I'm going to write the email address in the priority rock records, where should I write at the very top or at the end or somewhere or, but at the end of the day, a solution a step by step solution is required for communication, this kind of if you see the solution, although it has some it may be explained in there may be more steps that should be added, but if you see the solution, the step by step solution, this is a general solution. This is a general solution, much more general solution for every instance, but every instance I mean, after every eight hours, you will be having some records, and you have to do this procedure on the records for that eight hours. And then after that, that after that eight hours, you will be having more records to work on. So

after every eight hours, you have the same, the problem is the same, but the instance is different, because the records after eight hours are different. But but the but the solution says whatever the instance you are right, right now, whatever the instance is that you're in, just perform these, these steps, a step by step solution, coming up with a step by step solution is is one module of the one module of the problem solving. And there's step by step solution is called algorithm.

algorithm. Obviously, the step by step solution is not always required to be communicated in plain English or in natural language, you may come up with shorthands or shortcuts to explain these step by step solution. So, the the more shortcuts the more precise and unique meaning keywords you use in your step by step solution, the more better communication of your solution takes place. And going from this step by step solution, which is just

in plain English, going from this to a more concise and unique kind of procedure, that that can that kind of work that one step that will take us from there to there, that we will see in the next video will be called a pseudocode. And from that pseudocode there will be few steps that will take us to the second major problem that the problem problem languages will solve the get the solution running on a computer. So I'm just just in

this video i i wanted to explain you that solving a problem may not be that hard, I mean, coming up with a coming with coming up with a solution of a problem may not be that hard, but communicating that solution or, or writing that solution in a form of procedure that can solve every instance of that problem that that requires a step by step treatment of the procedure. And those those steps they should be linked in a sequence

and they should be unambiguous. And if a particular step requires more elaboration, that step might be broken down to further steps. But that step by step solution at the end of the day is called algorithm. Now that algorithm might be in English, but we will see in the later video that there are better ways of expressing algorithms better than English or better than natural languages. So, so, if you have another problem come up with a

step by step solution of that, though, every instance of that problem should be solved by that step by step solution, which is called algorithm. And in the next video, we will see how to actually how to actually eliminate the need of having English with us and how to incorporate the uniqueness of understanding of these steps or algorithm using using the concepts of pseudocode. And after the pseudocode, we will see it will be very quick to jump

to any programming language and we will see that the Python is very close to what humans generally think, I mean, it's very easy, the transition will be very, very easy. So, hope to see you in the next video and I'll be explaining algorithms in in, in a in a more kind of keyword way. And, and in the same video we'll be focusing on pseudo codes which are basically pre step off of the actual core of any programming language. So, hope to see you in the next

video. Okay, in in the last video, we were talking about the algorithm what an algorithm is and how to express that any any algorithm and we saw that algorithm is just a step by step procedure. But, but how to express an algorithm may vary, I mean, you need not always to have plain English to or any natural language to express algorithm. The reason is that the natural languages are normally so expressive, and each and every sentence they may have

multiple meaning. So, it is it is a good idea to come up with a structured way to express an algorithm such that each and every statement is completely unambiguous. And one such way is is to express algorithms using flowcharts flowcharts are our graphical ways of expressing algorithms. Here we are taking. The problem here we are discussing is is computing PE of different employees of some company. And the procedure of I mean, if there are several

employees, let's employ one employee to employ three and so on. Let's say there are several employees in a company and having each employee has name, phone number, email and all the credentials. And then let's say the pay is computed on hourly basis, and each employee has worked certain hours for example, eight hours and each employee has an hourly rate might be let's say 100 units, whatever the units are

employed to might have worked for example, seven hours, but the hourly rate of this employee might be 200 different employees, they might have worked for different number of hours, and each employee can have a different hourly rate depending upon the capacity of the employee or the or the job nature the employee is doing and so on. So, so, so, if we want to compute pay of all employees, one by one, the procedure of computing pay is stays the same, the instances

they differ for employee one, the value of our is eight the value of Raiders 100 for employee to the procedure will stay the same the values of our end rate they will differ so what should be the procedure, the procedure might be that you take the take the input of let's say employ one or whatever employee you are going to compute salary for take the hours hours value in a in a placeholder call that place or call that placeholder as ours

placeholder or a variable y this is called a variable because for different employers this value will different will be different, ours will take value eight for each one employee one this this variable, this placeholder will take value seven for employee two and so on. Similarly, once whatever employ whatever employ for which you are going to compute the pay, if you have taken the hours from some records from some working records, then take the rate

for the same employer as well. So input this that step one in Purdue that is step two, the steps the sequence of these two steps may change for example, you take the you take the rate value first and ours value later than that, but either way, that's one way of that's one way of expressing this this procedure. And then you compute the pay by this formula. So hours multiplied by rate. So maybe this is confusing writing a star.

Maybe maybe We should write this cross symbol because that is more common in mathematics. Or maybe this whole line can be replaced by, by this particular line, maybe. So pay is equal to multiply hours. And rate. Maybe this is more expressive, but it completely depends, I mean, when you start writing pseudocode, or whatever pseudo codes you're writing, what kind of keywords begin is a keyword and is a key word, what kind of keywords you're using,

and stay with those keywords for example, if the keyword input is to use to take to get the values to to process on then the input should stay everywhere wherever we want to do such kind of operation. If you if you're using for example, the value get rather than input then use get always but come up with some set of keywords that are expressive, as well as concise and then take the sequence of those statements, each and every statement

should be should have a unique meaning, it should not be ambiguous, and the sequence should be in the sequence describe the flow of what is happening, what is going on. So, first we take hours, then we take rate these two values for for for any kind of employee, and then we will just multiply them and after multiplication, whatever the scene we want to make, based on this pay, we will do that, we may we may record this value, display value

at at some other records register, we may we may print that value on a print slip, we may have emailed this value to some other department or whatever to see and we want to make, but the procedure really is still here, then based on pay whatever action we are going to do that that may differ. Similarly if we go this is this is I mean, some kind of structured example of, of the, of the expressiveness of an algorithm which is called pseudocode.

And what kind of keywords you're going to use, there are no general keywords, I mean, some people may use get some people may use different kinds of keywords for it, but it is good to come up with a set of keywords to to describe the describe the solution of the solution of the problem in flowchart for example, everything every every statement here, that is here in in pseudocode every statement is described as a shape different

shapes for different kinds of statements. If you want to take input, then you have to describe that action using a parallelogram. If you're going to do some computation, you have to express that using a rectangle the start symbol and end symbol the start and end of any procedure in flowcharts they are described by the ovals For example, this oval in that oval normally the flowchart sequences from top to down, but it is always good to just print the arrows to describe the flow, because in complicated flowcharts there are there are loops there are if conditions there are so many things. So it is good always to describe the flow using using arrows. So, now the question is flowchart or pseudocode because flowchart also looks like a very cool way of writing. expressing an algorithm and pseudocode is also a way of expressing an algorithm. Well, converting flowchart to actual

programming code is somewhat tedious, writing a pseudocode beforehand, which is readable, which is precise, concise, as well as unambiguous then converting that pseudocode to code of any programming language, that is not that hard, that is simple in writing flowcharts for very complicated problems is somewhat tedious, because then it It also requires another transition from flowchart to reactive programming code. That's why writing pseudocode

is more feasible, if the goal eventually is to convert that pseudocode to some core of programming language. So, you can go with flowcharts you can go with pseudocode either one is fine, but more feasible way of expressing algorithms is a pseudocode. That was just a very simple example. I mean computing, computing salary of an employee writing a procedure for that. I mean, this is so simple, nobody make your writing that kind of writing solution.

have this kind of problem as a as an algorithm or as a pseudocode as a flowchart. But the basic idea is, is is is the same, even if you have a complicated problem if even if you have a problem with maybe many more steps, the idea is still the same. In the in the next video, we will we will see a procedure how to how to make tea for example, that might that may look look to you funny, I mean, do we really want do we really want to know the

procedure to make tea? Well, the idea is not to learn how to make tea, the idea is to learn how to express the solution of this problem making tea that's a problem, the solution of this for how to how to express solution of that problem as as a pseudocode. And we will see one more example of flowchart as well. So hope to see you in the next video. Okay. In the last video, we saw flowcharts and pseudocode, we just took an example of

we took a very simple example computing salary or pay of employee of a company given hours and rate. And I also described weatherflow, the the comparison between flowchart and pseudocode. And I said that pseudocode is closer to the core of some programming language, which eventually we need, because eventually we need automation of of a solution of a problem. And for that, we need a code of the digit the code for the solution, the general solution in some programming

language, so flowchart and pseudocode, and then the core of some programming language like Python, it is somehow in sometimes handy to to break the problem or to devise a general solution of any problem for in first step in a flowchart because that is more expressive, and more generic, more general, maybe in a graphical way. And then once the proof of concept is clear, once it is clear that this is indeed a general solution, it has no bugs inside

it has no errors, it will work always, then we can take another step to convert that flowchart to pseudocode. And then pseudocode can be converted to the the code of any the code in some programming language. But writing pseudocode right away, I mean, from the very beginning without flowcharts is also a common practice. Either way, whichever way suits you. In this particular video, I'm going to talk about problem the problem is making tea.

You might be thinking, what are the different instances of this problem I'm in making tea is making tea. What what kind of different instances are there? Well, one person may be liking tea with, for example, 1.5 units of sugar, whatever the units are, and another person may want a tea with, let's say, two units of sugar, one person maybe, maybe needing a D with, for example, point five units of milk, and another one, maybe a different units

of milk, and so on. So the procedure of making tea should stay same. And the instances which means the different people want tea in a different kind of combination that may vary. So let's let's like let's see a procedure first and flowchart. And then in pseudocode, for for making a tea, for making tea. So let's start that that might look like that might look you look to you a kind of funny kind of problem. But that's a genuine problem. For example,

if you want to make tea, what is algorithm for this? So first we start and then the first step we do is we put teabag in a cup, that might be a first step. You can argue should this be a first step should that be the second step and so on the sequence of By the way, solving one problem, you can have multiple algorithms for that. And do different algorithms may just vary because of the sequence of statements even if you have the same statements. So I'm

not talking about that the algorithm or the general solution is unique. You can have multiple different general solutions or procedures. So for example, putting a teabag in a cup that might be first step, or the first step might be the boil, boil the water and pour the water and pour the water in the cup and then put the tea back. Both are fine, I mean this way or that way. So let's start with putting a tea bag in a cup. So that's an that's an input. We take the tea bag from somewhere. That's our input last time, I do You that input is taken as parallelograms put a teabag in a cup and then forget about that cup and boil the water somewhere there is a water I mean take the water from somewhere and boil it and see if after let's say five or six or seven time units whatever the time units are, see if the water is boiled or not assume that there is a test that tells you that the

water is boiled or not. So, there is a test available to you. So, you apply that test and check that the water is boiled or not if it is not oil then keep on boiling. So boil it again. And assume there is a procedure of boiling of water in in in normal case, boiling water is just happened by I mean keeping the temperature high or putting that thing putting the pot of water on fire or something like so, but that that itself is a procedure. So,

while the water again and boil the water again check if the water is boiled if no then boil it again. If not boil again then check if no then boil it again this is called a loop this is called a loop or repetition you are doing the same kind of stuff again and again. Until there is a particular condition that is that is met. So in this case, the condition is when while the water is not boil, keep on doing the same procedure again and again.

This is called repetition or loop. So you boil the water again, check the condition if the condition is true, for example, the water boil Yes, then come out. Then you're then you can exit this loop and come out. Then pour the water pour the water in in the cup. Here we should hear we should describe that is that the same cup or a different cup? Well, this see you pick up here is acting as as a placeholder where this tea bag and

the water is going in. So we have a cup, we put teabag in it, then we put the boil water in it, but before pouring the boiled water in it. We just boiled the water. Okay, and then after we have water in a cup and a tea bag in a cup, what should we do next? We actually we actually first test one sugar or need more sugar? If yes, then then add sugar. So let's apply some arrows. If yes, add them add sugar. And then again ask do you need do you need

more sugar? Or one sugar now? Yes, add sugar. One sugar. Yes, add sugar that is again a loop that is again a loop while while the while you want sugar. I mean you test that the sugar is okay or not. Here you test that the sugar is okay or not or whatever sugar you need. If Is that okay or not? Until that condition is not met, you keep on adding the sugar, add a teaspoon again, then test out a teaspoon that is again a loop or repetition.

Once the condition is met once you know then exit this loop and ask what milk because some people just take tea without milk. Maybe somebody wants a milk maybe somebody don't. So want milk? Yes. So add milk. So that's that's a mistake this this loop should go there. There right there. And this line shouldn't be there. That's that's wrong. Add milk and then ask what milk? Yes, admin, that's again a loop. Once you exit the loop, then you ask need

to steer. Yes, steer, then ask again. This line again shouldn't be there. So that that's another loop. Once you exit this loop, then the T is ready, you serve that D finish you're done with the procedure. Now let's see the same procedure in pseudocode program is the keyword and that's what program name is program make D what is a keyword put teabag in a cup while water not while while is a key word, while this is not while this condition is

not satisfied, keep on doing this. Whatever written in while and while is is the body of this repetition are called loop. So while water is not boil, boil water. Then again check water boiler not know what again. I'm in keep on boiling. So this is repetition. Once the water is boiled, which means this condition is becomes false what not oil becomes false so water boil, then you exit this loop, you pour that water in cup, that's again a

key word, you in a cup, and then you ask, okay, need sugar? Yes, add sugar, need sugar, yes, add sugar. So you keep on doing this until you don't need sugar anymore. So, that's again a loop. So, so, you might be thinking that why we are writing this add sugar and this boil water to writer to this this why we are really indenting this that style of pseudocode to just display that this is inside this this is this particular statement or

set of statements are called the body of the loop and this end Oil should be here in this alignment here in this line and so, there is a there is a bug in this slide this should be here okay once this condition is false sugar needed no then you can exit this loop and you go here while milk needed yes add milk, check again milk needed yes add milk milk needed yes add milk. Once this condition becomes false milk needed no then you can exit this

loop, you can just go to here. While latest here need to steer steer D need to steer yes sturdy he was there yesterday, once this condition is false get out and your tea is ready Do whatever you want to do. This example was so simple, but it expresses a very powerful tool in in the pseudocode as well as in flowcharts. And that tool is sometimes called loop which is there to repeat a particular procedure whatever procedure you want to repeat again

and again to until there is a particular condition that is met that is loop loop is there. So, the The purpose of this slide is was just to just to make you make you convinced and make you comfortable with the pseudocode and flowchart we will not be talking about flowcharts any further from here on we will we will be just talking about pseudocode in just one or two more videos. And then we will be directly going towards from we will be we will be comfortable

enough with pseudocode for solving certain kinds of problems that we will then eventually be moving from pseudocode to actual Python code. And and I bet you I'm going to tell you that the pseudocode in the next video I'm going to explain that will be very, very easily will be converted to the actual exact Python code. So in the next video, we are going to actually solve a problem of finding out minimum value from a list of values, sometimes

called the searching problem, we're going to solve it by first using pseudocode. And then in a later video, we will see how to write the actual Python code for that problem. So hope to see you in the next video. Okay, let's dive into real problem. Let's say you're given, you're given a list of numbers, let's say, let's say l is some list. with numbers, let's say we define list by these, these square brackets, let's say the list contains 23.

Let's say that's a value minus four, that value is zero, that's a value 73. That's a value, and maybe maybe minus 10. That's a value, maybe 13. That's a value. So let's just take an example that we have 123456 values in a list. So and that list is basically we took the list here as L and we just describe that let's say the list is declared by or expressed by the square brackets, and the elements of the list, they are separated by

comma. That is just our convention for this kind of problem for this problem just for this code. And And I'm not talking about any particular programming language yet. This is just a list of numbers. And let's say we want a procedure that finds out the minimum value of any list. Well, first of all, why this problem has multiple instances. Well, we need to come up with a solution that works for any list for example, if the list is if

the list has these six values, then the procedure should find out the minimum In this list, the minimum value in this list out of all the values is minus 10. Because minus 10 is smaller than every other value. 23 is bigger minus four is smaller than 23. Zero is bigger than minus four, because the, the value with negative sign, it is smaller with the value of a positive sign. But if you have two values with negative signs, the

value with a bigger number, in terms of magnitude is actually smaller in negative sense. So if you compare minus four and minus 10 minus 10 is smaller. In minus in minus domain, in positive domain, the result is different. So I was talking about why this problem has multiple instances, why you need a general solution for that, that's less just go and find out the minimum that is minus 10. Go home happy? Well, we need a solution that works for another list. Another list with different numbers. And maybe different number of numbers. Maybe in this list, we have six numbers, another list may have 74 numbers, another list may have 1 trillion numbers, we want to come up with a procedure that always finds out the minimum value in that list. Obviously, the minimum value may repeat, I mean, the minimum value may occur more than once in a list. So what is a minimum value

rather than knowing how many times that occur, what is the minimum value, that's a problem finding out a minimum value, and we want to find out, we want to come up with a procedure that finds out the minimum value, regardless of the list, whatever the list is, this procedure should actually return or end up finding out the minimum value. So, in this particular case, again, for this particular example, the minimum value is minus 10. And we will take example of this list, and we will see how to code a procedure for that. So but but before starting this procedure, what kind of things we really need to to, to write a pseudocode. For this kind of problem, we may start by writing that program, like in the previous video, program name as search. And then we take input or input list, then we take input, the number of values in the list the total number of values, and then we move

on as as we want to move on. But writing out a procedure in terms of pseudocode, it is always good to to avoid these input statements inside the pseudocode. And always supply whatever whatever needed, always supply the instance, from outside and assume that the instance is supplied and then just work on that instance. Rather than reading the instance. Rather than taking the values of instance, a particular instance from inside the code, it is always a good practice to, to, to supply the instance from outside, so supply the list from somewhere, and this n is really the size of the list. In this particular case, let's say if this is the list, then that list will be there, supplied from somewhere, but we'll see how to supply that. And this n value here, in this particular case, the N value is six the total number of values in the list 12345, and six, these are six values. So it is a

good practice to rather than writing program and then this, just write the name of the problem you're going to solve in this particular case the name is search minimum from list. And then this particular we are talking about this list l with total number of elements as n whatever the values inside the L is we do not know and and this n may take different values, l can be different, this n can be different for different instances. But it

is not a good practice to take input from inside here. Then, one more convention is that, let's say list of two represents the second element in the list. In this particular case, L of two is basically L of two is basically the second element in the list, which is minus four, L of let's say three is the third element in this list, which is a zero, and so on. So let's let's take a convention, that whenever we want to access the elements of the lists,

whatever whenever you want to read the elements from the list, we will read the element number by giving the element number here let's say whatever the if we write L of AI, that means it means the ayat element of the list. So, first we take a variable, we are assuming here that the list is supplied to us the total number of elements in the list is supplied to us. So we first take the minimum value, we, which we really want to compute the minimum value we want to compute, but any list can

be supplied in this procedure. So what's the procedure, the minimum value that we want to compute, we just consider the very first value of the list in this case, the very first value is 23, we consider that is the minimum value. Obviously, that is wrong, this is not minimum value, minimum value may be somewhere else, or maybe this one may be somewhere else, but we are not sure that the first value in the list is the minimum value. But let, let's just hold on for a moment and move on. Let's say the minimum value is this here, this is called the assignment assignment. This min value is a placeholder or a variable, and I have assigned this value l one to it. Now, from here onwards, the min value will be will be will be having a value which is 23. In this particular case, okay, so min value is this, which is 23. Now, let's declare, let's declare another variable, which is called

counter, we may need this counter. And let's declare this with two, why we are declaring this with two it will become clear later on. So now we so min Valley right now, for this particular list, the min value takes the value 23. So and counter takes the value two, these are two things for these two variables. Now, we apply a loop while counter is smaller than n smaller equal to n. Remember the value of n for this particular example is six, and

counter here is two. So because counter has value two, while two is less than or equal to six, first check whether this condition is true or false, because if this condition is true, then you will go to the body of the loop, then this whole box will execute. If this condition becomes false, then you will exit the loop and we'll go out. So now counter is to the so two is smaller or equal to six. true false. That is true. So the condition

is to two is indeed smaller than or equal to six, that is true. So we will go inside to the box and see what happens. Then what we will do, we will pick and pick a value from at the index counter. Right now the counter has value to L off counter means pick the value, because the counter has value to pick the second value, which is minus four and pick that value minus four from the list, pick that value and copy that value or assign

that value to a variable v. That's a new variable we maybe needed somewhere okay. Previously the min value which is a variable, it was containing the very first value which is 23. Now we have picked the second value the counter value is two. So we have picked the second value from the list, which is minus four. Now we compare if the value now which is minus four is that value smaller than our minimum value. So far, the minimum value so far is

is 23. So minus four is smaller than 23. Yes, the condition is true, if the condition is true, we will go into this block, otherwise we will go into this block. So right now the condition is true. So we will go in this block and minimum value will just be replaced by the new value. And the new value right now is minus four. So because a minus four is smaller than 23, so we are here in this body, the if condition becomes true, you're in this

body, and the minimum value becomes whatever the value is in V and right for this example, the value in V is minus four. Okay? So if if if you go into the if condition, then you're not going into the else part, either you're going to F part or in the else part one of them. Okay, so then we move back Oh, there's a bug here we need to add the counter. We need to increment the counter here after after this. Before this. There is another statement

increment the counter. increment counter. That's another statement increment counter. So Now increment the counter after this if part increment the counter, and the counter will become three. Now, we will repeat the procedure and check three is smaller than six, yes, we will go inside, and we will pick now the counter value is three, we will go and pick the third entry. And now the third entry will be in V, the V will now contain

zero. Previously it contained minus four now it will contain zero min value is containing minus four now, so zero is smaller than minus four, no, if zero is smaller than minus four, then do this. But zero is not smaller than minus four, then go to the else part. And as far as just saying just go on do nothing, I mean don't do anything. So when you're here don't do anything except if condition increment the counter again. Now, you increment the

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent