  correlate ఱేడా వియ్జత�ations consistency will depend on the రపింపిబట్న నీఞని ంమరగంvio దథ పేసింగాద పాగ్సి 30 మేసొడింటకకరిలి ఏం. పృరసి 29 Moreover rebate ఘ్పెసాన్ పిస��는 ofнос theme � Is this of statements, so effectively I have a block of statement to be repeatedly executed. Now whenever I have to repeatedly execute any set of statements, I must first of all enter that block with certain conditions. When I enter this block here, I will start executing these statements, but sometime or the other I must exit this block. I cannot keep on repeating infinitely, so there will be an exit path here. Now it is possible in C++ to set up an iteration in variety of ways because the condition to exit might be written such that it is examined at the beginning or it is examined at the end. So what it means is that when I am entering the block, just before entering the block I may say click check whether I want to do anything at all in that repetitive block. If I don't have anything to do, I should just get out. But if I have something to do, I should enter the block. I may examine whether I am wanting to get out of the repetition or I want to continue the repeat. On the other hand, I may not have this examination here. I may simply have a loop going back and again examining the condition at the top. So to revisit that, let me just write the instructions of the type. You are familiar with this statement of C++? So in the diagram that I have shown, if this is my block which is to be executed repeatedly and this is the entry point, this is the exit point, tell me where the loop would be and where the condition would be checked. Why statement checks the condition before entering the block? If this condition is true, what is done? If this condition is false, what is done? So this is the checking. If there is a block to be repeated, I either enter the block or I exit. I enter the block if the condition is true. But why statement does something more? Which is it forces the control to go back after the completion of the execution of the block to this point again. And this is the most important part or meaning of the wise statement that it executes a repeated execution of the block. So while we will force you to first examine the condition, if it is true, I get into the block, I go back. Again examine the condition, if it is true, I execute the block and go back. Please note that I will keep on going back as long as the condition is true and I will not enter the block even once if the condition is not. Now obviously if I do not want an infinite iteration, what must I ensure within the block? I must ensure that this condition will change. If it does not change, then the vile block is a very funny iterative loop. If this condition, say for example, the condition is a less than b. This is the condition. Now if a is less than b at the beginning, I will enter the block. Now if nothing in a or b changes, when I go back, a will still be less than b. I will again execute the block. a will still be less than b. I will again execute the block. That means I will keep on doing it infinite. That is never the intention of setting up an iterative solution. The morale of this on the other hand, imagine a is not less than b. Then the first time itself when I come here, I will exit. In short, I will be setting up a meaningless iterative loop which will either not execute even once or will execute infinitely. The only way to correctly execute an iterative loop or desired number of times is to ensure that something in this condition changes during every execution of the block or during some execution of the block. Either a must change or b must change or both must change such that a less than b does not remain true after the few desired number of iterates. If a condition does not change in the body, a high loop is a meaningless loop. Let us examine how we could set up a loop. For example, so effectively what it means is, I am given some arbitrary positive integers 25, 4015, let us say 415398176 and then I give 0. So I can keep giving numbers one after another and when I give 0, my input has ended. I want to find out the sum of all the numbers up to 0. The number of numbers that I am going to input is not specified. I can input 100 numbers, 5000 numbers, 2 numbers. Can I input no number at all? Yes, I just type in 0 as the first number. If I type 0 as the first number, there is no number to be added. Now my program must intelligently figure out how many numbers are being given to be added and add them. Very obviously if I represent the number by a variable num and the total by the variable sum, then the block that I have to repeatedly execute will look something like sum is equal to... So if I execute this block repeatedly, I will keep on adding the value of num to sum. Of course it is stupid to add the same value of num to sum. I have to make sure that num is one of the new numbers that has been given to me as input. So what should be the value of num? It should be a new number red. It means I should say somewhere here input... If I input num and add it to sum, every time I will get a new number, I will add it to sum. If I want to put this under vile condition, what should I write here? Please note the moment I put this brass, this will return back and will examine the condition again. What should be the condition? We have said that if the value of num becomes 0, I should stop. So vile num is not equal to 0. I want to keep doing this thing. I have a small problem here. I am reading the value of num inside the loop because I need to change it every time. But I am examining it. Of course every time I add this I examine it is alright. But I am also examining it before entering the iteration itself. What is the value of num at that time? Nothing, it's not known. Can I set the initial value of num to 0? If I do, I will come out. Must I not set initial value of sum to 0? I must, otherwise the addition will have no meaning. So I may say something like sum equal to 0. But I still have a problem with num. So what can I do? I should read the value of num here. I am deliberately writing such thing because this is how many of you would approach solving of this problem. It is one thing to look at a readymade solution. It is different thing to synthesize a program. And when you write a program, funny things may happen. What is the funny thing that is happening in this program? I am starting with sum equal to 0. I am inputting a value of num. Hopefully a meaningful value like 25. While num is not equal to 0, 25 is not equal to 0. So I get in. But wait, what am I doing here? I am reading another value. So now the num will have a value 4153. What has happened to 25? God, it has been overwritten by the new number that has been. What it means is that if at all I am going to use the wild statement, then this is not the best way to organize my iteration. The best way to organize my iteration is to first read a number outside the loop, the first number. Get into the iteration, add it to sum and read the next number after addition in preparation to the next iteration. So for example, if I were to do something like this, do you think this program will work correctly? Notice the changes I have made. I start with sum equal to 0. I read the first number myself outside the iteration. See in num. I examine if this number is non-zero, in which case I have to add it. So I get into the iteration body. Inside the iteration body, I upgrade the sum. Sum plus num is assigned to sum. Now before going to the next iteration, which will be forced because of the wild statement, I will read a new number here. See in num. When I go back, this number, the new number will be examined whether it is zero. If it is non-zero, obviously I have to add it. I will add it here and go back and keep on doing this. Keep on doing this. Till such time that I get a number zero in which case this will end. Do you think this program will work? This program will work but it is working because of a peculiar self-imposed condition. Namely the last number is zero. Suppose I had said that the terminating number will be minus five. Then I will check num not equal to zero. I will check for what? Num not equal to minus five. But if I execute the same iteration, will it find the sum correctly? Somebody said this will not work correctly. I have changed the terminating number arbitrarily to minus five. All other numbers still minus five should be added according to me. Now since I have changed the terminating number to minus five, I am examining whether the number that I am looking at instead of being zero, whether it is equal to minus five. If it is not equal to minus five, I have to keep adding and keep repeating. The moment it is minus five, I should quit. Why will this program not work? It will not add minus five. Of course, it is not supposed to add minus five. Please remember, find some of positive integers given as input. That is the problem statement. Value zero terminates input. This is an arbitrary decision given by the specifier of the problem because you will naturally ask me either tell me how many numbers you will give or tell me when your number is n so that I can stop my program. To that, my answer is all right. I will type in a zero at the end. So take zero as the terminating value. Now I am changing my statement to say instead of zero, I will give minus five as the terminating. Please note the problem still says find the sum of positive integers given as input. Is there any other way of doing this? The other way is to use a do-while loop. How does do-while loop get written? Are you familiar with this construct? In the do-while statement, if I have a block to be repeated, the condition of termination is examined at the end. In one case, you will come back here. In the other case, you will get out. So this is my block. So if I have to synthesize a repetitive loop using do-while statement, I can do it like this. I initialize the value of sum to zero appropriately. I say do, see in greater greater num, sum is equal to sum plus num, while num is not zero. So keep doing this. Please note that this do-while iteration forces the iteration to be executed at least once because there is no exit check at the beginning. The control will fall into the body automatically every time control comes here. When it falls into the body, the first statement reads a number and the second statement adds it to sum. After coming out of the block, it will examine the condition. If number is not equal to zero, it will go back an end. In short, as long as number is equal to zero, it will keep on going back, going back, going back. The moment it is found that the number which was just read in and was added to sum is equal to zero, you will get out. This program will work. It will work if the terminator is a zero value and the reason it will work is that even that zero value is added, the value of the sum is not different from what it would have been when it was summed up only the positive end. Will it work if my terminator value is minus five? It will not work because before examining the value, I am actually adding it to sum. Now this is exactly what you have to keep in mind when you construct loops using while or do while. That in do while, the block executes at least once always. As long as you remember this, you will be able to correctly construct this state. Imagine if I said I want you to use do while only but my terminating value is minus five. If you want to cheat me by saying the input terminating value is minus five, then I will do that. I will examine minus five here but after I come out, I will say sum plus equal to five. So you cheat, I cheat. Unfortunately this program requires two changes to be made if the terminator value is changed. Ideally if one specification of the problem statement changes, you should be able to make a change only at one place. So if the terminator is minus seventeen for example, your program will conk out if I merely replace this as minus seven. The point being made is that it is better to write the correct logic independent of what the terminator value is so that the loop terminates and the summation is not taking into account the terminator number. Can I rewrite using do while loop such that that is beautiful. I was waiting all this time. You know last forty years I have been teaching see a sonoma. There is always a dog in attendance sometime or the other. This time I was missing him. Hello. No notebook and does not have a roll number but that's okay. So how can you write do while statement but ensure that it correctly runs even if you have a negative number or some other number as well. Anyway, I will leave that problem to you to think but please understand that an iterative solution where you do not know in advance how many times you have to execute the iteration then you should preferably use while or do while whichever is most appropriate for the problem state. However, there are a large number of instances when you have to handle you have to handle the situation by setting up an iteration which executes a fixed number of times not necessarily fixed in advance like five times twenty times thirty times but fixed in terms of another value given to you this happens typically when you are dealing with for example an array you have an array of marks scored by students in a quiz and I want to input those marks inside this array now while writing the program I do not know how many students will take that quiz the teacher has told me that there can be at most 600 students in a course of more but at any given point in time in one quiz there may be some number of students less than 600 in fact the total registered students may be less than 600 so I will need an additional variable n which will define the number of students then obviously even to collect the marks from the user I will have to set up something like this once I read the value of n I know that I will be given n marks marks for n students which I should read in successive elements of the array marks in this particular situation and in all similar situations where you have to set up an iteration a definite number of times to be executed we use the four construct are you all familiar with the four construct the four construct has three components one is called the initializer component the second is called the condition check component and the third is called the increment component there could be variations in each of these three components but what I have shown is the most frequently used manner of the four statement the iteration control here works like this it is extremely important that all of you completely by heart this structure of the iterative control because this is exactly what a four statement does four statement first executes an initialization part in this particular example it is merely i equal to zero it could have been a sequence of assignments as you have already seen i equal to zero comma j equal to something comma k equal to something whatever you want to do is the initialization part once the initialization part is done the four statement examines the condition for continuation of the iteration in this particular case the condition is whether i is less than n if i is indeed less than n then i am permitted to enter the block if i is not less than n i will exit the block and go to the next state if i is indeed less than n i will go inside execute my block at the end of this block i will not automatically go back to repeat the block again but first i will execute the increment part specifications in the four statement the initialization part the condition part and the increment part please note that we call it an increment part but it need not increment anything it is the post execution of the block part and i can again do a series of assignments there or whatever i wish to do after that i will go back again and check this condition in short the four statement has three components i will call it part one condition part three this is how the four statement is written so there is one part of specification then there is a condition and there is a third part of the specification it so happens that if i want to use the four statement to construct an iteration which will execute a fixed number of times say n times then i ensure that when i write my part one and part three it is written such that in part one i set an initial value to some counter and in part three i increment that counter by one that is the easiest way of setting up a counter which will ensure that a loop is executed n times this was the example of doing so where part one simply initialized a variable i to zero and part three incremented it by one so the value of this counter variable i will change from zero one two three four five the last value will be n minus one with which this statement will be executed when i come out here i will be incremented please note i is incremented here i come back i would have become equal to n and i would have quit please note that i could set up this iteration if i want to execute an iteration n times i could have started with i equal to one and carried on upto i was less than equal to n i could have started with i equal to ten and i could have continued till n plus nine so the starting value of the counter last value of the counter is entirely in my hand i could have started with five incremented it in steps of two and ensured that the condition is properly written such that i execute the loop n time these are various creative manifestations of my specifying the initial value the final value and the condition however it is always a great common sense that if i want to execute a loop n times i count from either one to n or zero to n minus one in particular if i am going to deal with an array where there are going to be n elements in the array and i want to either scan all n elements or input all n elements or add all n elements or do something with each of those n elements the best way to set up an iteration using for loop is always to start with zero because that is the index of the first element of the array and always end with n minus one because that is the index of the last element is that clear so this is common sense you can be creative here but if you want a clean programming if you are handling an array if you are doing something with n elements this is the best way to set up an iteration for example to read all n elements a few things about this since i do not know what is the value of n i have to read it however i should do some validation here what will happen if value of n is seven hundred yeah what will happen c plus plus will shout at me what will happen if n is equal to seven hundred six hundred nobody says c plus plus will shout at you in fact c plus plus cannot shout at you because while compiling it has no clue what is the value of n it is just a variable if any shouting has to happen it is the operating system and the c plus plus run time system should shout at you when your program is compiled and then executed during execution time you are going to get the value of n happens to be seven hundred my question was what will the operating system or the run time c plus plus will do to you one answer was that it will read only the first six hundred value what it will do with the remaining hundred values i am giving them as input after six hundred it will give you a run time error every self respecting c plus plus compiler should actually introduce an automatic check if the array bounds are being exceeded by an index here that is if i goes beyond five ninety nine compiler should have introduced some check saying baba please hold on you have declared only an array of six hundred size and five ninety nine element is the last element no new element can be done unfortunately c plus plus compilers are not known to be very self respecting in this particular context so what c plus plus does it it has allocated memory to these six hundred elements sequentially in its memory location zero th element first second five ninety nine if you are index become six hundred it merely and happily goes to the next location and stores this value there six hundred and one next location six hundred and two next seven hundred next location those next locations might have been allocated by the same compiler for some other variables in your program program will continue those variables will suddenly acquire new values and very funny things may happen moral of the story unfortunately most c plus plus compilers do not do such decent things and therefore it is entirely your responsibility as programmers to ensure that no matter what no matter what bad input people give you will never access elements of the array which are below zero and above zero i can ask you the same question if somebody gives me n as minus ten what will happen against an input value of minus ten it is not the c plus plus compiler but it is the for loop which is protecting you for loop will start with i equal to zero is i less than n no zero is not less than minus five minus ten so i will exit the iteration before executing it even once so it is your for statement which is protecting you not c plus plus if quite independently i wrote somewhere i is equal to minus five and marks i equal to something what will the compiler do can you guess it will go backwards before the zero th element it will treat the previous one as minus one th element minus two th minus three th minus four th minus there is an element now that might have been a location for anything including n itself everything will get chewed up the person responsible is the programmer not the compiler because compiler makes it explicitly clear that array bounds are to be checked by last question suppose everything is nice n is four hundred five hundred or five seventy five as the current class string this since i know that the number of students are only five seventy five in this particular execution why should i make c plus plus compiler waste memory locations to allocate to my array elements when i know those elements i am not going to use why not then say marks n i am telling the compiler that my array will contain n elements i will give the value of n when the program executes logical now this is something which i think the last benches are you paying attention can you tell me whether this statement is correct or wrong if it is correct how it is correct if it is wrong why it is wrong yes sorry n n plus one oh so you are saying that if i say in marks n plus one it is alright i am learning some new concepts in c plus plus very useful i think you are not paying attention to the entire discussion that happened first of all when i say there are n elements there is nothing like n plus one n elements automatically imply that the first element is 0th element and the last element is n minus 1th element it is implied but you are suggesting that i can make such a declaration so you agree that there is no sense of plus one is n in marks n right it is wrong please pay attention to these these things very very carefully you cannot declare an array whose size is not explicitly stated as a fixed number because the array locations have to be allocated by c plus plus during compilation and during compilation the value of n is not known let us give an equivalent similarly program says design a house with n bedrooms where i will tell you n after you have constructed the house you understand that is exactly what it means saying marks n where i will tell you n later architect cannot construct a house compiler cannot compile this program please understand this it has to be a size it has to be an absolute size whatever it is 6000 if you are not sure how many students so you imagine okay how many students join iit or how many students exist in iit at any point in time 1005 all of them might take a course not cs1 on obviously but something so then declare an array with 10000 element use only 5 of them it is okay of course it is wasteful and to prevent this wasteful allocation of memory c plus plus provides something else it is called dynamic memory allocation operating dynamic memory allocation in subsequent classes after the mid-sem where you can actually figure out that i require only 575 element and you can actually tell the compiler generate a code don't fix the size of this array when you are executing i will tell you what is the size at that point in time go to the operating system and grab more locations and allocate them to my dynamic memory allocation is possible is permitted but there is a separate mechanism to do so normal array declarations require you to have fixed size of array is that clear i don't want people to make a mistake you would have easily lost marks on some simple question where i would say this and you will say oh that is fine so please read the or view the lectures very carefully i mean stated time and again that the array has to be declared with a fixed size some question he has a smarter question so let us put his question he is saying i defined the variable before int n somewhere i read the value of n later in my program i say int marks n now what is the problem logically i know the value of n when i come here is this correct many people are not very sure it is correct or wrong all those who say it is correct say correct wrong it is not correct the reason it is not correct is that the compiler when it is compiling it is not executing the compiler reads the entire program where the exercise that we did with dumbo read all instructions first and then execute and the instruction says execute only the last instruction do only that while executing c++ compiler will read all instructions first and will collect together all declarations no matter where they have been made the only requirement is you must make a declaration it is used so for you it is all right to say int marks n and do something with the marks later but as far as compiler is concerned it has to allocate storage for every variable and array that you have declared anywhere in your program even before the translation is completed forget the execution so no matter whether physically your input statement is ahead of this declaration this input statement has no significance whatsoever the array declaration will be considered first by the compiler allocation will be made to the marks array this is wrong i will ask you another question suppose i see that what fatak says is all right because value of n is not known suppose instead of this i write n is equal to 100 now my c++ compiler should not have a problem it knows n is equal to 100 so when i say int marks n it should set aside 100 locations logical yes ok how many i say correct correct wrong see exactly these are small things which as professors you must be perfectly aware of this statement n is equal to 100 is an assignment statement it will be executed only when the compiled program is executed at that time the variable n will get the value 100 not while compiling while compiling the compiler will store this constant 100 in some other location it will allocate some space for n and it will generate a statement an instruction in binary code which will say when this instruction is executed pick up this value 100 and assign it to the location for n and that instruction will be executed only when the compiled program is executed not earlier so just because you have written n is equal to 100 and then try to say int marks n compiler has no clue what the value of n is at this juncture please understand that compiler is not executing your code compiler is only translating your code is that clear ok he says he tried it out and it works actually it will work even if you don't have n equal to 100 and that is because some c++ compilers are capable of implementing the dynamic allocation that I mentioned to you even in ordinary circumstances but that is not the c++ language specification and that is also not common sense a compiler compiles does not execute the logic of using this based on the assumption that n is equal to 100 is known to the compiler is incorrect that logic is incorrect if this works it works because a peculiar implementation of c++ compiler which actually will do a memory allocation dynamic but not other way so please remember as far as we are concerned as far as our c++ standard definition is concerned not I am not talking about a particular compiler as far as language standard is concerned I must define arrays with fixed sizes is that clear sorry if you write constant it's a moot question whether the constant a constant is actually assigned a value during compilation if you write constant you should be able to do in fact you can also define parameters as environment variables which are defined at the beginning even before the main program we shall see all of these later these are extremely valuable when we write large projects where there are multiple students multiple partners developing different components and putting them together it will be hazardous if one partner defines an array with 700 elements another partner defines it with 600 elements and chaos results so we would like to give some kind of a parameterization to declare array sizes but not in this manner not in the manner of declaring them as variables in the program and using them as size all if you say int n equal to 100 it is equivalent of saying initialize the value of n 200 the initialization instruction however may be done at the compile time or may be done at the execution time so let us put it this way instead of wondering in which particular way I can make the compiler understand marks n properly instead of wondering and trying to be creative about it we follow a simple instruction all array sizes must be declared as specific values period why how we can subvert it there can be n number of other arguments the only way in which there need not be a size but something else here that something else cannot be a variable of your program that something else has to be defined at the compile time not at the execution time that is the rule now as you observed correctly some c++ compilers are intelligent enough to handle it differently but that is not the language specifically programming language requires that you follow it it is also important to understand it from other point of view this is not a course on c++ programming this is a course on programming there are 600 programming languages after you pass out of this place if ever you have to do serious programming even you do not know which programming language you will be using there may be a deep programming language or e programming language and within 5 years it will become so popular that all of you might have to program using that language so while programming languages may change while syntax may change some basic programming concepts remain across programming language and it is better to use those concepts which are definitely going to be valid across all programming languages and write programs in that fashion that will ensure that no matter what programming paradigm I choose my programs will always work correctly so here is another suggestion instead of wondering how to make this compiler accept this and work why not say I will not do such a silly thing at all I will always declare my arrays with values which are known at compile time or I will use dynamic allocation of memory in my program if I follow this principle for all my programming no matter which programming language tomorrow I use my programming habits will be such that I will end up writing correctly so the important fact that I am perhaps not mentioned explicitly earlier this course is not about C++ program this course is about programming all the concepts that we have learnt sequential execution conditional execution iterative execution arrays functions these are fundamental to programming and no matter which programming language you use you will be able to use the same concepts more or less in a very similar fashion and that is why it is important to abstract the concepts and understand and incorporate them in our programming habits all continuing with marks if I want to calculate the average and the standard deviation of all marks stored by students how will I do that average is simple I calculate the sum divided by n I will get the average can I in the same loop calculate the standard deviation actually yes there is a very creative and a complicated process to do that but ordinarily we won't attempt even our idea will be simply to say how you can shorten the instructions in C++ you don't have to write the block with brushes because there is exactly one instruction in the block namely add the next value of mark to the running sum I can do that very simply by saying sum plus is equal to marks this is nothing but a statement sum is equal to sum plus ith value of marks written inside the big block the entire iteration is governed by a simple counting control no frills no multiple j k this that i equal to 0 something something something defining int i here would have meant that this i is isolated from any other i that you might have defined elsewhere now there are two schools of thought while programming one programming practice says that you should declare all your variables only at the beginning and use them another school of thought says that you declare all your major variables in arrays at the beginning but whenever you are doing some local counting and such things define those variables locally for the limited scope there was some discussion on scope of the variable names you should remember what that scope means if i declare int i here then this i will not be confused with any other i that i might have used earlier or later because this int i here creates a new variable i whose definition remains valid only for this block of form in order to calculate the standard deviation i need to start again so i will first calculate the average as equal to sum by n how do i calculate the standard deviation i will have to reset sum equal to 0 again how is standard deviation defined have all of you heard about standard deviation so how is it defined is that correct n should be inside the square root where here sigma mi minus a whole square by n square root of the entire thing so this is actually the average squared error as you referred you can do this computation of sigma very easily by setting up another iteration you know the average you know the individual marks the average deviation from 0 to n minus 1 because that is the index of this array subtract it multiplied by itself you get a square divide by n so you got this sigma done problem is how do you find the square root you find the square root by writing by using a library function by including the library called c-math and then include the library function to find out the square root suppose the library does not exist I want you to write a function which will find the square root of a floating point value x and it will return a floating point value do you know how to write such function this used to be my favorite quiz or mid-sem problem you have to write a program full program you generally get about 15 minutes to solve a problem in a quiz or a test of this kind you have exactly 15 minutes how many of you are confident of writing a correct program to find out the square root of x how many of you are familiar with the numerical method typically used to find the square root of x many I am happy that 4 or 5 of you are there and so you have already done this kind of programming earlier or you just know how to find the square root or even if you get me up to 2 decimal places is alright I will give you just a hint try to construct a program to do this there are readymade solutions also available basically you are trying to solve an equation y is equal to f of x which is equal to x square so the equation is y minus x square is equal to 0 y is equal to x square how does that look like suppose x is 1 what is the value of x square x is 2 what is the value of x square 4 if x is 3 what is the value of x square 9 so what will be the graph of x square look something like this and if it is on the other side negative values again look something like this now you know if this is y which is given then this is x given this equation this kind of graph can you iteratively find out value of x if y is given alright I will give you another example simpler this type say the function is such that it crosses 0 somewhere the point at which the function crosses 0 that means y is equal to 0 that is considered the root of a function at x equal to some value y is equal to 0 I want to find out what this value is you have all done binary search ok consider that I am able to locate beforehand for any given function a point which I call low and a point which I call high high is one value of x at which I know that the function value is positive low is another value of x at which I know the function value is negative and if I further stipulate that it is a monodonus function which does not have multiple 0 crossings in between these two then should I not be able to use the logic of binary search which I used for searching an element in an array to get close to my root for example I can add high and low divided by 2 I get a midpoint this midpoint is somewhere here this is my mid I evaluate the function at this midpoint is it 0 no if it is midpoint is my square root or I mean the root of them if it is not 0 if it is negative then I have to search this side if it is positive I have to search this side exactly binary search so what will I do if midpoint is here and the value is negative I will shift this low to this point I have a new low same high I find the midpoint again that may be somewhere here then I will shift the high to that point and I will keep shifting low and high low and high there is no single element that I am finding but I am finding what is the value of the function it will be negative positive negative positive but initially it will be minus 5 2 plus 1 minus 0.9 plus 0.8 minus 0.005 plus 0.005 and the moment the difference between these two is less than some delta I will say boss this midpoint is my root do you get this as easy as doing binary search so try to write this as an exercise at your own home since the only time I am asking you to solve a problem at home ordinarily we would have solved it here you can make variety of by the way the entire field of numerical analysis which does variety of other things including solving simultaneous not just linear equations but differential equations partial differential equations and so on but solving simple equations to find a root is also an important problem and there are books on numerical analysis which do this with maximum precision being located correctly located for the root and so on but this is a simple exercise by the way if you write a computer program in C++ the program will not more than 10 or 15 lines of code because binary search you know is not a very long program is the logic that you have to understand you have a low, you have a high and you have a midpoint and either low shifts to midpoint or high shifts to midpoint and keep doing this again and again you need to evaluate the function value at midpoint only in fact if that function value is close to zero you can assume that mid is itself close to the root alright we will stop this discussion here thank you