Let us start. So in the last class we have discussed about the first asymptotic notation that is theta notation and what we identified that to establish or to comment that the function for the algorithm in terms of input size fn can be mapped with a known function g of n with respect to some theta notation. So we can say that f n is equivalent to or equal to theta of g of n where g is a known function, where g is a known function and this is a function describing an algorithm, function describing an algorithm. So to establish this, we have to take three positive constants, three positive constants that is C1, C2 and N0, where N0 is the, you can say boundary value beyond which we are confirmed that the behavior of the function will remain throughout and C1 and C2 are two other positive constants to establish C1 G of n less than or equal to fn less than or equal to c2 c2 g of n okay and then we identified that the graph was like this one because this this was this was fn this was c2 gnn c1 g of n and from some here n naught. We identified that this behavior will seem throughout till infinity. Till infinity. Here by the infinity, I mean that when n is very, very large, when n is okay. So, then we can comment that f of n is theta of g of n. And one more interesting aspect we have discussed that this f of n equal to g of n is not a single value basically what we are doing we are identifying one value from set of multiple values values of g of m okay so here when we are saying fn is equal to theta of g of n. So basically this is not, this is the condition that fn is a subset of theta of g of n because there are multiple possibilities. Then one more interesting thing that this theta notation, theta notation is also called as the sandwich notation sandwich notation because we you can see in the graph the fn is bounded by both c1 and c2 and the last thing that theta mostly represents the average case computational complexity. So this is just the gist of what we have discussed in theta notation and then we have solved some of the problems. And for quadratic expression, we had a known formula that we can use. But in general, for determining n0, you have to think about the multiple values and from which the expression becomes a 4-2-1. So these are the groups of function. What is asymptotic analysis? When we are doing the analysis, when n tends to infinity or we can say that n is very, very large. Then these were the mutations, some questions we have. And this is the, you can say the function, we can say if we have the fn that is representing any algorithm in terms of a n square plus bn plus c with the condition that a should be greater than zero because if this is negative then after some time or up for a higher value of n this part becomes negative and that will start dominating so entire behavior will be changed if this is the situation then then c1 will be a by 4, c2 will be 7a by 4 and n0 will be 2 into max of two values that is mod b by a comma root mod c by a. So from these two values, I will pick either this or this whichever is maximum and that will be treated as n naught so this is just the behavior for quadratic expression but for others you have to explicitly determine then our generalization come into the discussion that say that when a function okay of degree d when a function of degree D or a polynomial degree D and sorry, we can say the highest degree, the polynomial of highest degree D and this coefficient A of D for highest degree is positive. Just a minute, so let us continue. So, if we have a polynomial of degree D, okay, if we have a polynomial of degree D, polynomial of degree D means that if I had, let's say, sir, sorry to interrupt you, there are people in the lobby who are joining without IIT, Patna ID, so shall I allow them? Let them in, let them in. Okay, okay, thank you. so if we have polynomial of degree d means that if I have a polynomial like this one okay so this should be what the coefficient of this should be positive then this become a positive polynomial its complexity will be of order n cube okay or x cube you can see if sub if we have x square plus something then we can see that x square so what is the basic here thing is that But if there is a polynomial and its highest degree term, I can write if there is and its highest degree term having positive constant, positive constant, then the order you can say we can simply write theta of n to the power d where n to the body is the highest order for example here x cube or you can say n cube okay don't worry about x and n both are same okay if i have n cube minus 2 n square plus some 7 and so highest degree term is n cube so the theta notation will simply we can write theta of n cube okay so what i want to conclude that irrespective of whatever the value of c1 and c2 and even if we can directly assess the computational complexity of any expression just by looking on to the highest degree term and checking whether the coefficient of that highest degree term is positive. If it is positive then we can easily write it is of order theta of n to the power d that is the highest degree term irrespective of whatever the negative numbers or values that persist in the expression. Now, one of the interesting thing, let us talk about two small aspects. Okay. One, let us say I had multiple papers of my students. These are the multiple copies 1, 2, 3, 4, 5, 6, 7, 8, 9. These are the copies of my student who will secure some marks. Okay. Out of 100, let's say it is 74, it is 73, someone gets 61, someone gets 92, someone gets 95, 88 and so on. Okay. Now these are the copies. Now if I say how to arrange highest to lowest, if there is a task how to arrange highest to lowest marks okay so what I will do I will pick any random copy pick any random copy then what I will do first copy I pick any random copy okay then I will pick another I will pick another copy and check whether it is should we place here or here okay so here it should if the marks is higher than it will go to the left side otherwise it will go to the right side okay now i have place let's say the max was highest okay so this was first copy now this become second okay then again next copy i will pick i will compare from both and then it could be here it could be here or here okay so what basically i am doing every time i pick a new copy i compare with the existing copy and we try to identify its correct position okay so that is there so similarly if we have a deck of cards okay playing cards okay take off playing card and we have to arrange in some order in some order then what we will do we will pick one card then we will pick another card then another and another and every time we will try to place it on its exact position every time we will try to place it on exact position so this resemblance or this thing what we are doing here is the base or is the example for the one of the sorting technique of course we are starting first one that is insertion sort insertion song Actually, what is happening today, this first year, people had their classes. So they are sitting in the lab and the staff of computer center does not aware of the today's class. So there is some mismatch or miscommunication. That is why these calls are coming. But let us continue. So, what basically we have did, we have do a sorting in a manner where we have chosen one thing and then we are comparing with it and we know that the number of comparison is the dominating term. So, that will help in determining the computational complexity of the insertion sort. So, now that example I have discussed, let us consider a simple example of things. some simply the simple comparison based sorting algorithm insertions. This method resembles how teacher typically sort our exam copies. And there is another example that is hand hands-off playing card. So what I will do, I will first explain the technique, then we will see the algo part and other stuff. So let's say we have a number set of numbers 18 5 7 9 14 2 11 16 3 1 and 20 so let's say we have these set of numbers okay so just understand the things then we will see the algorithm and everything will be very easy to do okay if this is array okay now I asked perform sorting on this array and apply the insertion sort so how it will work so first I'm just writing the index number one important thing is that by default I will use the index starting from one okay if there is a specific location where index is zero I will mention but you are free to use either 0 or 1 in your lab company. So that is not an issue. So now we have 11 number starting from 1 to 11 and we have to perform sources. So what I have said that I will randomly choose one index and then choose second other and compare with it. So I have choosing this index as the first element, element as the key you can see from which I will do the comparison. So when I start, so what I will do, I will start from the second. So this first location, first element will be treated as a key and I will start my algorithm from second. Then what I will do? I will compare 18 and 5. And what it says? So I have chosen second element and comparing with first. So what it says? I have to do what? Sorting in ascending order. One important thing is that unless otherwise is stated, the sorting should be preferred in the ascending order. In question, if it is explicitly given to do a sorting in descending order or anything then you can do otherwise you have to assume it is a ascending order so what will happen here we will get five because this will do a swapping 5, 18, 7, 9, 14, 2, 11, 16, 3, 1, 20, 7. Now this is step 1. What we have did? We have compared second element with first element that is a key element and done the swapping because order was not maintained. Okay. Now we can see that first two elements are sorted. first two means that these two locations are sorted then what i will do i will shift to the third position same process i will do but i will compare 7 with 18 then 7 with 5 okay so if you compare 7 with 18 what i identified that they are again violating the sorting property then we will to a swap. Okay. Then 7 will come here and 18 will come here. Then 5 and 7 will be compared. Order is same. Then we will stop. So what we will get after this was step number 1. Then we have step number 2 that is 5, 7, 18, 9, 14, 2, 11, 16, 3, 1, 20, 7. Now these three elements are sorted. Now I will go to the index number 4. Then I will compare with this, this and we will get what five seven nine eighteen then in the next round we will get five seven nine fourteen eighteen then the next round we will and so on and so on we will get five seven nine eleven fourteen eighteen then we will get five seven nine eleven fourteen so there is a six okay six will come here five six seven nine eleven fourteen eighteen and twenty one and so on so what basically we are doing in every step this this pointer is shifted toward this one okay and when i lecture 16 then i will compare with all previous entries all previous entries so this is a simple logic keep start from second index compare with first if there is a mismatch in the requirement then we will do a swapping okay then go to the third location then compare with second and first go to fourth location then compare with third second first go to fifth location then compare fourth fifth fourth third second first and so on okay so if you see with an example so this is the situation we are starting from the second index comparing found that there was a violation then what we have did we have do a swapping then we have reached to the third index we have compared with both and what we have identified now it is sorted two four eight then we reach to the fourth index compare with this So we will find there will be no change. Then we will go to the fifth index, compare and fix to its suitable position. Then we will go to the league sixth and last index, compare and that comes to the solution. So simply from this discussion what we identified that the insertion sort is simple sorting algorithm where what we have to do, we have to keep on shifting a pointer from left to right and keep on comparison from right to left okay so that two strategies are adopted okay okay so i hope you people got the idea of insertion sort okay visibly as well as the conceptually okay so now here you can see the algorithm is written you start with the second element here it is written index one you can assume index two as well okay so that's why i said don't confuse with the index term okay start with the second element index it is unsorted array and assume it is start from the sorted position compare the current element with the one before it if they are wrong wrongly sorted swept them move the current element back through the sorted position of the array until it is at its correct position and move the next element and repeat two and three okay simply it is saying that we will start from the second compare the element with first you will go to third compare the element with second and one go to fourth compare the element with third second one and so on so this is the simple strategy that we could adopt in insertion sort so here the algorithm is written insertion sort. So here you can see I am starting from for j equal to 2 to n second index. Okay. You can use 1 to n minus 1 because you have assumed index i equal to 0. But here I am assuming index j equal to 0 starting and here I am assuming j equal to 1 as starting. So that is not a problem. then what i have to in key value what i have assigned a of j and a of j will be the first value a of j will be the first value okay i'm sorry second value and i we are simply initializing as j minus one because i will go to the first position so we are reducing so while i greater than zero a of t greater than g we have to do what we have to do a swap so this is a swap step a of i plus 1, a of i, i is reduced by i minus 1 and in the last a of i plus 1 equal to k. So this is simple algorithm and here we can visualize that two loops are working one inside another. So of course the computational complexity will touch order of n square, order of n square. okay so simply i am choosing second element reducing i by one then checking whether i is greater than zero if yes and a of i is greater than key that is keep we identified previous index let's say third on third we are there and second we have identified that is having higher value than this so that is the violation of sorting requirement then we will do a swap operation okay just a simple very simple algorithm i guess uh for sorting this is a simplest algorithm though its computational complexity is order of n square but it is simplest and this algorithm is primarily used in the situation where the array is small and the elements are fairly sorted when it is fairly sorted so number of swept will be obviously reduced so two important considerations are required for insertion sort. First, the insertion sort is applicable when the array is fairly means not all but most of the elements are at its correct position, fairly sorted. Second thing is that it is simplest algorithm. Simplest means that easy to implement, easy to understand. okay when the array by is small okay so these are the two conditions when i array is very large okay then we have to go for my sort quick sort okay number of sorting algorithm we will see okay so their computational complexity is of order n of log of n okay and here for insertion sort it is order of n square okay this is insertion so simply how i am saying it is n square that we will separately calculate one from the algorithm okay but in the meanwhile i can just claim that there is a for loop going n times and inside that for loop there is a while look that is also going n times so basically the total number of steps will be order of n square and some other term but this will be the dominating therefore we can conclude that the computational complexity will be of order of n square okay later on we will also determine that fn what is the fn for this insertion sort okay so i hope you people understand the concept okay important part is that in an algorithm course we have to understand the concept okay Okay. Now, I hope you people had got some idea. So, I am giving you one question. Now, we have element 17, 13, 4, 8, 3, 2, 7. again i am repeating 17 13 4 8 3 2 indexes are 1 2 3 4 5 6 7 now you have to identify number of swap required sort in the n okay so just do it everyone if you have pen and paper so you have elements 17 13 4 8 33 2 7 and you have to identify the swap again it should be very clear i'm not asking about the number of comparison here i'm asking about when the actual position of the element was changed okay so just do it and and and we'll we'll again start in five minutes okay so i will also count the swept so those who are not getting this idea okay so do they should don't worry i will let them know okay just solve it identify number of swept then i will also solve the problem i hope some of you have solved this if there is some issue i will try to resolve it okay someone has done properly total swaps are 17. okay thank you thank you for visiting me teacher's day and you all people are teacher or learner learning thing for me so happy teacher's day to you all okay so let us see the problem and then we will try to identify the number of swap required okay then i will take the queries those who have on this insertion sort and then we will see the full variant of the algorithm that is a python implementation and then we will try to estimate the function fn okay so So, we had considered 17, 13, 4, 8, 3, which is 17, 13, 14, 8, 3, 2, 7, 2, 7, this is not putting this is 4. So, this was the array we have and we have to identify the number of swap required to sort this algorithm. This was the algorithm. Now, we have indexes just I am writing down 1, 2, 3, 4, 5, 6 and 7. This 5, this is 5th, 6th and 7th index. Now, I will start with this second. So, in step number 1, the swap will be 1. In step 1, what will be the resultant that is 13, 17, 4, 8, 3, 2 and 7. So, here swap count if you see it is 1. Now, in step number 2, when we are choosing this index that is 4, not 14, it was 4. So, 4 will be compared with 17. swap is required then 4 is compared with 13 swap is required so here we will get 4 13 17 8 3 2 and 7. so number of swap will be swap will be 2 because we have 2 swap twice then in step number 3 it will be 8 now 8 will be compared with 17 swap required 8 will be compared with 13 swap required. So, the resultant will be 4, 8, 13, 17, 3, 2, 7 and here the number of required step was 2. Then in step number 4, we have the element that is 3. So, 3 will be compared with everyone and every time it will be swept 1, 2, 3, 4. So, here we will get 3, 4, 8, 13, 17, 2 and 7. So, total number of swaps here, s will equal to 4. Then in step number 5, the element is 2. So, it will again compare with everyone. So, 1, 2, 3, 4, 5. So, we will get 2, 3, 4, 8, 13, 17 and 7 and number of swaps that we are getting in this step is 5. Then in step number 6, we are having 7 and it will compare with 1, 2, 3. So, 3 swaps then it will fix its position. So, we will get 2, 3, 4, 7, 8, 13, 17. So, here number of swaps that we have did was 3. If you add all these swaps, so what we will get? 1, 3, 5, 9, 14, 3, 17. So, those who have get number of swap as 17 is correct okay so if anyone has any query let me know we will try to resolve and then we will try to identify the fn for this function okay because so you can add one by one enable mic for them and then i will try to resolve the queries okay parambir you can ask your question unmute yourself from bir can you hear me so you have to allow their mic okay because allow my i allowed them yes i allowed yeah sir good morning uh i have uh sir i have posted my query in the chat uh firstly in the previous example in the previous class which we had done on 3n square minus 9n plus 17. We did not take n is equal to 1, 2 or 3 because even though the answer was positive, n component was missing or 0. Is this statement correct? Wait, wait, wait. So, I will write immediately here because number of people are doing chat so I cannot get it. Okay. Yes, please repeat. Yes. We have done this example. 3n square minus 9n plus 17. Okay. Okay. I got your idea. So, you are saying it was positive even for one or any value. Okay. So, why to take a larger value? So, of course, it is correct. So, good question you have asked. So, you can start with n equal to 1 because at n equal to 1, it is positive n equal to 2, it is positive even so. So, your n naught will be 1. So, that that that is totally i agree yeah so because in the previous class you said because in the final answer the n component is missing only 17 is coming therefore we did not take n is equal to yes yes yes but but in in uh what happened um later on i have seen so this was there if you try to make this function positive and when it is positive and it should be positive beyond that value then we can take n0 so there is no mean of taking 17 or n component and otherwise so if it is applicable for n equal to 1 so this is a good question for everyone so if n is it is applicable for n equal to 1 2 3 and so on so we can declare n not as 1 because it is a positive function my next answer also material gets answered that why did we take greater than 3 sir in the present class that you're taking i could not understand why is the complexity n square and not o of n because number of iterations are the number of elements in that array we have to sort each every element one by one so n why is it n square that is my second okay one important so how many steps you are running that is n minus one these are steps one two three four i i guess you are agree this is n minus one and uh how many times this is happening in one step so for first step that's a good question again so for first step i am doing comparison how many time one time for second step i am comparing for two time for third step i am comparing for three time for fourth four time i am not talking about swap i am talking about comparison okay comparison is there if it is not required then we are not swapping but we are comparing okay fifth and so until how many times till n minus one time okay and assuming n is very large or we can say what we will get for here n minus one into n by two so i guess you agree with this expression so are you getting yes please explain how do we get this expression okay so let me go for one more slide. So I guess you are aware of this one, 1 plus 2 plus 3 plus 4 dot dot dot n can be represented as n into n plus 1 by 2. Yes. Yes. So similarly in first step I am doing comparison of 1 and we know that comparison is dominating operation. In second I am doing 2 comparison. In third step I am doing 3 4 dot dot dot till n minus 1. I guess you agree with this number of comparison yes yes yes so i will i can write what n minus 1 into n by 2 yes correct so that will be n square minus n by 2 or we can say that half n square minus half n and this is the the here term is coming what n square and that is simply resembles to order of n square I think so time and complexity will be worst is n square n square and I will also tell about you the Fn that we will soon soon start okay so then you will get the it is also a quadratic expression actually what is happening though though the n steps are running or n minus one steps are running one but in each step we are continuously increasing the number of comparisons so that's why its complexities tending towards order of n square otherwise if there was no comparison in each step then or one comparison in each step then it will be obviously end but we are doing more than one comparison in each step so it is correct it is not a linear comparison it is a recursive at every step therefore the every step we have to from the chosen point we have to reverse back to one reverse back to one so that's why the comparison is keep on increasing thank you thank you so much sir sunil i have enabled your mic you can ask your question sunil kumar yes uh thank you and uh morning sir and i'm happy to just say uh sir uh okay uh this can be a very nice question but then uh what i'm saying is see when we are comparing it from uh from the rightmost position from the index we are there more swamps right so we know that the left side is already already sorted okay so why can't we compare it from zero to n minus one which i've posted in the chat also but i know it's a standard insertion sort algorithm that you do it but can't we optimize the insertion sort itself because just just think that the the left side is already sorted and why are we swap swapping uh from the right side because why are we comparing from the from the suppose n i is the index then why are we comparing i minus one and goes to zero instead of comparing it from zero to i minus one okay okay so you are saying let's say um just i will explain i guess what i am getting key if um from uh one more step i will go ahead so if i have chosen 9 okay and if i compare with 8 and found that no swap was needed so i should stop my comparison that you are saying no no no suppose see we have already uh what i am saying is in the in the previous steps we have already sorted the left side of the array okay okay this is sorted okay this is sorted so now for the already sorted array uh we are comparing 9 with 8 and then 9 with 4 and the 9 with 2 but if suppose we compare 9 with 2 first and then and then find it so there's chances that we might find the exact position earlier i mean with lesser swaps then okay okay now now if you see the algo fine your doubt is too genuine here what i'm saying while i less greater than 0 and a of key greater than key key is the the the index that we have chosen okay second third fourth fifth or sixth so at any time this this loop fail automatically we will not made an entry into this the time the time complexity i am discussing about key we have to swap or we have to compare with all the element till first okay so that is the worst case complexity of order of n square so in this way here it will be automatically stopped okay so likewise if i compare 9 with 8, I found the element is already sorted, so there will be no swap is no swap is required. And now as per your doubt, if I do the comparison from here to this side, so that is also, so that will be a, not a insertion sort, it could be some different variant of insertion sort. So of course, you can do this. So these algorithms are just the base, you can on the top of it, you can do any modification as and when required. yeah okay so but that's what my analysis was that the swaps would be lesser in our case you can do so maybe for one example it could be lesser but other it may be high so that depends upon the question yeah yeah okay sure okay thank you next we have surendra surendra pulsing please ask your question the monitor actually my doubt is about this last explanation where you explain this comparison last slide can you go in the last slide this one so yeah this one so can you explain it again the first step okay so in first step we are comparing second element with first right agree so number of comparison i'm writing two one in second step i'm comparing third with second then second with first so number of comparison is two in fourth step one two three in fifth step one two three four so that i'm keep on writing and this will can can be done for n minus one because for comparison we need two elements so we cannot say it is and it should be n minus one right okay so that's why we are getting this expression okay here the comparison can be zero i believe yes yes yes comparison can be zero but here i am writing for the worst case where every time we have to make comparisons okay okay what's the second line n square minus one okay you have just felt like it okay fine yeah now we have soraab soraab kumar panday good morning sir good morning i should basically you have uh just explained about the worst case complexity to be order of answer just perfectly fine uh my doubt is very something very different from it it is like i'm trying to get the best case complexity in that case uh can you just uh brief me the idea or what would be the mechanism to find out the best case and why will the best case be order of n square still or it would be like something else okay so so that that is a good question so best case is totally user dependent okay for how many comparison we are declaring that this computational this algorithm should so let's say in each step if there is a comparison of one then i can declare what this is a waste case okay so in that case what we will get one plus one plus one plus one okay so it will be and so basically if we take something as an example independent of the number of input basically we think that the input is sorted so in that case it would be like uh constantly we are we are uh we are uh so let's say i had a sorted input three four five six seven eight okay i have taken now when i choose this one so there will be a comparison but no swap okay so number of comparison is one then i choose five there will be first comparison then the while loop will fail the number of comparison is one then i choose six one then i choose seven one then i choose eight one so total number of comparison how much one two three four five and number of elements are how much five so this is n and this is also n so this is best case i said that if i will allow two comparison okay so in each step if there is two comparison then that is best case for me so it will be what one plus two plus two so it could be let's say nine n okay so that is also equivalent to n so that is also the best case so basically sir we can like in terms of input and so we can basically say it is like the best case is order of yes yes yes but um what worst case say that keep maximum it will go to order of n square and anything less than you can say it is an average anything much lesser than that you can say best so means that if you determine the worst case so this is the maximum time your algorithm will take other will be lower than that this one that is that okay so the concerning thing the only thing that concern now is that uh the pseudo code that you have written for the uh insertion sort basically if we have uh inputs uh that are like sorted in this order still it would make order of and square comparison that is what uh no no so in in each step here it will follow like this one if it is sorted then it will like this one in each step one comparison while fail in one comparison while fail one comparison while fail so number of comparison as i have mentioned in the this previous slide how much uh this one one two three four it will not increase it will just remain freeze with one okay array sorted okay sir thank you sir thank you for the application Shrujan, unmute yourself and ask your question, please. Hello? Yes, please. Sir, so in first iteration, we are just swapping one time. And in second time, we are checking for two times. So, in worst case, at last index only, we are comparing the full array. full array so why we are writing o square instead like we can write some formula right like we are comparing full array only for last index right so that i have written here i am saying number of comparison for last arrays n-1 for other it is 1 2 3 4 so the time complexity we are writing o of n squared right like why can't we create like a formula like we are only comparing one element for first uh first uh second just see this one element then two element comparison then three element comparison then four and comparison and then n minus one element comparison so basically if you add everything then you will reach to this situation that is n minus one into n by two that is nothing but half n square minus half n okay hitting so i will tell about the the quadratic expression just after this slide Okay. Jayanth, Jayanth, unmute yourself. Okay. Next we have... Can you hear me? Okay. Yeah. Hello. Hi, sir. So my question is, yeah, we have this n is the number of elements, right? And we have this half n square minus half n. So this would be... Sorry. Yes, this would be the maximum number of swappings that you will get, right? Yes, not swapping, comparison. Swapping is other aspect, comparison, yeah. Comparison. So, I try to substitute that n number of elements, which is, I think, 6 or 7 elements, right? So, I think we are getting, what, 21, not 17. Because it depends upon the elements, right? So, whatever this half n square minus half n is the maximum number of comparisons. Yeah, yeah, that is the worst case. worst it means that that is the maximum time the algorithm will take maximum okay it could be less than that okay less than that yes yes yes okay okay and uh forgive me uh is this uh does this come from the space complexity or time complexity so this is time complexity is space wise because we are performing operation on the same array so the the space requirement will remain uh order of n that is an element so any space is required yeah got it thank you thank you that's yeah yeah uh hello good morning sir good morning so uh this is a little off topic but i wanted to ask what if we use a combination of insertion sort as well as binaries uh as well as binary sort because as we are going through the sorry bubble sort sorry bubbles yeah as well so don't confuse the entire public i will tell you the bubble sort so bubble sort is exactly someone was asking if we should start comparison from the first it is bubble out the shortage element in the last so you can say that is a reciprocal operation of the insertion that but we will discuss separately that verb also okay so we'll discuss okay yeah we are good to go because yes i don't see any rage and okay because most of them they have asked very good questions so i guess entire all of you had been benefited from it i'm just opening next slide where the complexity analysis is given okay now we have uh this uh this is a python implementation of of the insertion sort. Just give me a moment. So, what I will do, so for i in range 1 to length of array. So, we have n elements. Then what I will do, current element as a of i. And what I have did, I have assigned a value i minus 1. So, first value will be 0. First value will be 0 because we are starting with this index now what it is saying that move element array 0 to i minus 1 that are greater than current element one position ahead of the current position so what i will do j greater than 0 same property current element less than the previous element current element less than the if it is so so we will do a swap operation and at last we will do a comparison of arr j plus 1 current element okay because just i'm curious to know is someone wants that i should follow this algorithm and solve a problem in the chat you can check then i will solve a problem strictly following this algo otherwise we will jump to the complexity analysis or if it is clear for everyone then it is very good for me someone has put down the comment that we can do it in lab yeah yeah fine great great yeah so let us discuss about the complexity part okay so now if i just say i will remove this so how many time this for loop will run if i just comment it on it so what i can say it is running for how many time and minus one time because here probably we are using the index 0 we are using the index 0 to and minus 1 and we are starting from the first index so that second element is captured so it will run for n minus one time and fail for one time so obviously this will run for totally end times i hope everyone agrees this for loop will run for end time because it is starting from one going to length of array so we know that in python the last index is omitted okay and here there is assumption that this is the shape of array okay and we are starting from the first so n minus one time it will run and one time it will fail so aggregately it is n now this current element stuff will run also for n minus one time this j minus one run for n minus one time this comment will run for n minus 1 time but will not cost anything okay now coming on to this while loop okay so while loop will run for at least one time okay at least one time that is failed may be the fail case okay so we can say that it could be what it could be a summation thing okay 1 plus 2 plus 3 plus so on and this will be just one less than that. Let us say if it runs for 1 plus n into n minus 1 by 2 times, so they will run for n into n minus 1 by 2 minus 1. This will n into n minus 1 by 2 minus 1 and of course if you see indentation, so this will run for n minus 1 time. So from these, summing this, we will try to determine the function fn for this algorithm. So if you see here, so I am just writing the cost c1, c2 and for the comment part, the cost is what? 0. Although they are running for n minus 1 time, but its cost is 0 because comment does not impose any complexity. Just a minute. So if you see here, this is running for that I have written mistakenly two it is should be one because index is starting with zero. So cost is c1 run for n minus n time that is n minus one it will run and one time it will fail then these two statement will run for n minus one n minus one comments of course n minus one and the this last statement that is if you see indent twice it is with the while loop so it will also run for n minus one time now coming on to this while portion Okay, so this will run for iteration j is written that is first, second, third, fourth and so on. And these will run these two step will run one less than for that iteration one less than for that iteration. So basically, this iteration is nothing but it will start from second index till n. This will also start from second index till n. But this y loop will also hold one fail case. So that is there and they will not having that fail case. So we are reducing by 1, we are reducing by 1. So here this was a formula if you remember I had just applied n into n minus 1 by 2. So if you see here, so total cost is c1 n, c2 n minus 1, c3 n minus 1, c7 n minus 1 and this will be n into n plus 1 by 2 minus 1 and this is n into n minus 1 by 2 and this is n into n minus 1 by 2 so because uh here i am writing n into n plus 1 by 2 minus 1 because every time what we are doing 1 plus 2 plus dot dot till n minus 1 so i am just removing one comparison that has not been made okay similarly these are the internal component that are they are running. So, if you collectively add them, so we will find an expression like 0.5 n square, 0.52 into this, this, this, this, this into n and this. So, what we find that this coefficient is positive and this expression is of order n square. So, we can easily say that the computational complexity is theta of n square from our previous discussion. So, this tn is nothing but the function fn that represents how the algorithm will behave with respect to the input size n. Though it looks quite complicated, but it is of form what a, just a minute, a n square plus b n plus c. So, that is the quadratic expression and for quadratic expression we know that the computational complexity is of order n square. okay so anyone has doubt in this expression then let me know simply i had estimated how many times all the steps will execute it and form a expression and from that expression we have determined that it is basically a representation of quadratic version because i guess the summary yeah there are a couple of hands okay one or two i can take and then i guess others queries will be automatically result right aviram you can ask your question unmute yourself aviram okay uh ujwal hey thank you so much yeah good morning sir happy teacher's day uh sir i have a question i understood how you are um how you came to a conclusion that you know for the for loop and for the current element in minus one is coming i understood but the moment uh you explained for the while loop can you please explain sir once again how are you deriving that it's n into n minus 1 by 2 fine fine so in while loop we let's say we are starting with the second index so i will compare with first okay so that time this will be true okay but one time it will be fail so what will happen number maximum i am talking about not minimum so number of comparison will be what two yeah one one for correct case and one for failed case similarly three will be for next step similarly four will be for next step and so on so till last what we will get we will get n minus one number for successful and one for fail so what we can say that it is 2 plus 3 plus 4 plus dot dot dot n agree yes and if i just add one here and subtract one from here so what we will get n into n plus 1 by 2 minus 1 clear yes sir okay okay and in the internal these two statement will run for how many time 1 plus 2 plus 3 dot dot dot till n minus 1 because they are not suffering from the fail cases. So, for that the expression is n minus 1 into n by 2 and for this n minus 1 into n by 2 and for this it is n into n plus 1 by 2 minus 1. Getting? Yes, sir. Thank you so much. Yeah. Prashant. oh yeah hello sir good morning good morning uh sir can you please explain one more time how to find the cost like c1 c2 c3 please what uh please be louder yeah okay so for uh please explain about how to find the cost like c1 c2 c3 please that is that is uh simply the uh you can say some value that is not you do not need to bother about the c1 c2 c3 okay yes they are the representation okay don't worry about that yeah okay okay thank you sir yeah we just had two hands rich sir okay yeah thank you good morning sir good morning so i have a doubt related to the descending order on this so we do have a different comparison steps right for descending for an unsorted array so why still the worst complexity is um n square so for this particular unsorted array we do have seven steps for the ascending order say 11 steps for the descending order so the comparison steps are getting different so why we know for for descending order for descending order this uh this um you can say the comparison will change basically so then why we are having the same worst complexity of n squared no so you can just check it out you will not get let's say you have seven element and if you have to sort the element in the descending order so you will never get the number of comparison more than 49 that you can check yeah so and for worst case when the seven element you have to sort in ascending so we'll never get the number of compression more than 49 so for both these cases in worst case i am doing saying so in both the cases and the things will be so if the your elements are sorted in descending order and you want to do in ascending in that case this maximum thing will come that is 49 comparison otherwise it will be less than that okay so we are doing a generic thing this is the worst thing and anything less than that will be good okay so thank you yeah yeah good morning sir sir i have a question like you have used the notation o for the for showing the complexity not the theta notation so just assume theta for now okay wherever i write no assume it is theta i will tell about later on you will realize that theta omega o everything is same but but we keep patience for next tomorrow's lecture tomorrow we will talk about this big o so so so there you you mean to say that sir uh between these notations we do not have any uh like uh differences or like uh so this is just a nomenclature thing for worst case i'm saying it is we go for uh average case i'm saying theta for best case i'm saying omega but the order are more or less will be n square for all these things okay maybe this i'm saying order of n square but it may run for not 49 times it may for seven areas it may run for 20 times it may run for five times but um that will not change that order of n square or any expression but this is a just you can say nomenclature perspective we are saying theta big o and big omega but order of algorithm complexity is n square okay okay okay so don't confuse i will conclude all these after completing this um asymptotic notations you will find everything is comparable and and coexist okay okay okay thank you sir sir universe uh sir a small question on this so uh if you look at uh row number four and point of four and point of five right yeah the cost is zero and the times is n and minus one but if you look at this since these are comments so it's does not get executed as a part of runtime so yeah uh is there any you know uh should we consider this n minus one for four and five so but but you are multiplying with zero so it is nullifying ultimately i'm just writing you how many times each step will run so it is nullified here from these okay got it got it we are good to go because okay uh one one more question we have from jain yeah then please unmute yourself uh hi sir um yeah i'm looking at this uh the screen that you have uh the current element is equal to array of i uh the cost is c2 i know you said not to worry about the cost uh but you also put uh c5 c6 c7 uh which are like you know assigning the same numbers to the different uh element uh seven eight cost is equal to zero will it be the same for c2 and c3 as okay no uh so i have just written it it is equivalent to zero because here we are doing only assignments this is also uh thus just an assignment okay this is also just an assignment but this for loop and this while loop having what the dominating operation that is comparison so it can never be equivalent to zero right right okay just making this so c2 and c3 also approximately these are approximately to zero but this c1 and this c4 yes they will impose the stricter cost okay thank you sir we have one more question I think Anuja yeah thank you so much sir for this session it's very informative and very happy teachers day to you sir thank you thank you yes one quick question sir is it direct to the assignments so what we can expect with respect to the assignments as we know there are the labs also going on so are these labs also going to be counted uh as in the labs one thing like okay now now just a good question you have asked i'm about to add assignment questions today only so your assignment question will be primarily objective type question and it will be based upon what we have discussed so far in the lecture so primarily your syllabus for assignment one will be till in certain sort okay whatever we have covered so you may receive 15 to 20 questions of objective type single correct answer okay so that is clear for now lab perspective you should do practice in the last we will discuss how to merge those marks in in your this part in your assignment and semester part if your marks are relatively good so lab marks will be not dominate if you let's say score some less marks then i will talk with the this technical team how we can integrate those marks into this so do lab with whole efficiently understand the problem and marks it if you are getting from this assignments and mid sem or you are getting from lab that is not a big deal i guess so again i am repeating so thanks you have raised this question so the syllabus for assignment number one that probably will be uploaded today so you may see in one or two day uh will be till in search and sort okay and the all the questions will be primarily objective type question and easy questions that is not a problem okay what i have discussed what i have taught will try to make the question from it okay yeah sir this is the very uh thank you sir guiding this yeah shall we have one more question shall we continue or no we have we can take the query and tomorrow i will discuss about the correctness of this instance okay okay okay okay so those who have done can also leave because i am not going to teach anything beyond this because we have limited time and the thing that i will start will take another half an hour yeah please go ahead hello sir good morning sir my doubt is related to assignment that as you mentioned you will be giving the assignment today on the portal and on the academic calendar it is mentioned assignment will be from 11th of september so like can you please clear this regarding date of assignment and what will be the deadline for the assignment and if it is saying okay okay every doubt i will clear in a one go assignment one for you it's 11 for me i have to upload one week before okay so that i will do syllabus will be till insertion sort and type will be objective type only object objective time okay so four choices or maybe sometimes five choices one is correct and i hope those who are attending the classes will secure nearly full or or even full mass okay that is my experience in last two sessions so everyone is doing really good okay so just read this question the straightforward question i will ask in the assignment in mid sim and n sim there will be little bit tricky or logical but in assignments i usually ask very straightforward questions so don't worry about that the objective type one correct answer very simple straightforward questions if you have ppt if you go through the ppt all the questions will be automatically solved okay sir uh sir regarding lab i wanted to ask that the lab faculty is teaching in python so python is compulsory for attending hacker rank or like no no you can do in cc plus plus anywhere you are comfortable that's why we are using hacker rank because um multiple people from multiple different background so i will not assume ki one start studying or learning a special language and though having their organizational task so you can do in whatever you wish sure sir so in the assignment this lab coding questions will also be there or only no no there will be no there will be separate uh lab exam in that we will ask the questions related with the lab okay so that is also a a component for your assessment okay thank you sir like i am done with my doubt okay yes hello yes yes yes yeah i just wanted to ask sir when you upload the assignment how many days we will have to complete so let's say you are getting on 11 so maybe at least three days or maximum seven days so just one hour you have to sit but in a seven day chunk you can do it thank you so for three days minimum three days are there a maximum seven days and for end sam and med sam it could be 15 days even okay thank you sir majid khan yeah hi sir first of all happy teachers day yeah thank you thank you very much so so about assignments i think you have cleared a lot of things but what i'm one thing i'm not clear is uh you said that you know it will take one hour or something right so the window will be open from 11th uh september to 15th september right but is that like once we start assessment we have to complete it yes you have to complete it in an hour otherwise it will be closed yeah yeah okay okay all right all right so in in four days you can sit one hour when you are free in night evening anytime and just submit the assignment but in one go it should be done so so that that assignment will automatically get closed in one hour once let's say i have attempted only seven total questions for 15 one hour over it will be closed and are the questions going to be different for for everyone or it's going to be same for every all the students actually um i will add just one set of questions but usually what happens the choices the questions are suffered that that mechanism i know okay but yeah so that will be primarily done all right okay that's all for me thank you sir thank you thank you so because i guess doubts are done uh we do have few more and okay we'll take one by one and those who have done can leave the class okay okay sainthani patra sorry if i misspelled your name sainthani patra please unmute yourself okay then we have priyanka if your doubt is done so you can down a hand also because because we'll ask one by one then it will be difficult for him also oh good morning sir happy teachers day thank you yes sir will assignment be like an exam like so it will be an objective type question a window will be open you cannot close the window till one hour you have to attempt all the question then you can leave okay just like exam you're saying yes yes yes you cannot minimize the portal number of some constraints are there okay sir okay till insertion sort right sir till insertion sort not beyond this yeah only mcq types mcq only mcq in even in your end same exam also i will try to give you mcq because evaluation is automatically done otherwise i have to check one one by one all all of your copies and then it will be very difficult for handling three four hundred people's okay sir okay yeah thank you sir swamya yes good morning sir good morning sir you said that you will be uh sending this test lab link in the test lab link yes okay so can you elaborate i just forgot it if i guess i think you said in the yes that that you will be sending that test lab link. Okay, okay. All the lab assignments I will share. Yes, lab assignments. Okay, okay. So, by tomorrow, I will ask that you or myself will do that. Okay. Yes, sir. I was searching that only, but I... Yes, yes. No worries. I forgot it. Okay. I will add it. Okay, sir. Om. Om Kumar. Hello. Yes. Happy Teacher's Day, sir. Sir, I have a question. Sir, my laptop camera is not so clear, so can I attend all those assignments through my tab? Not aware of those things, but if your camera is not working properly, so you are in a good situation. Actually, my camera is working, but what I saw, it is not so clear. that is the good thing people will not see you what you are doing i have not comment on that that is totally up to you okay but it is also working in tab as well as in phone also okay okay thank you sir because hi sir good morning hello good morning yes so i have a dot regarding assignment initially my dot is clear i thought that You will upload the assignment and you need to complete and upload it somewhere in a drive. So not upload even a portal link you will get and you have to just go there, attend the assignment and done. So no upload and anything is needed. Yeah, yeah. So my dot is clear. Thank you sir and happy teacher. Thank you. So Bekes, I guess we can close. We'll take those who are raising hand in tomorrow's class. Okay. Thank you Bekes for your help. Thank you. Thank you sir. Happy teacher's day. Thank you, thank you.