My question is regarding the assignment one. So, in the lab, as I mentioned, there are total four assignments and assignment one marking will be from there. So, my confusion is like, will we also be having a separate assignment, like this kind of assignment also, or the only one to four lab will be counted in our assignment one? so there will be separate assignment for lab okay and the things which we are doing in the lab is totally for practice basis but in the last if some marks is demanded from my side what you have do the assessment in the lab then i will show that marks so that they can add okay otherwise we will have a separate quiz yeah those those questions are only for practice it will not be be counted in assignments so that is a lab kind of thing is of evaluation what i'm making so at last sometime they ask you uh share me your assessment see so they take it and and may be added in your marks okay whatever is beneficial if you do well in quiz then that marks is not added if you not do well then that marks are added oh okay okay thank you so much jivan i guess we can start yes sir you can go ahead thank you thank you thank you okay so uh let us begin this class so in uh yesterday's lecture we were covering the topic primarily the binary search binary search and just finish a merge sort and the last we have seen quick sort okay so in most sort we identified that it is a recursive division a recursive division of a large problem okay division of a large problem and one more thing we identified that it required additional space for storing result as well and we calculated the computational complexity to be n of log of n for all three cases of the best worst and average case okay Bandly search is also following the recursive division and comparison with the middle element. And here we form the computational complexity of order log of n with a condition that the array should be always sorted. Array should be sorted. Then we have quick sort. We have started and what we found that for average and best case, the computational complexity was as equivalent to the merge sort forward, worst case the complexity reaches to the n square where the thing is every time the pivot is selected as the extreme element. pivot is the smallest or largest element in each iteration okay so then it becomes the worst case then we identified that quick start mechanism is uh simple just identify a pivot and fix its position okay so what is the rule that by what should be greater than left and should be less than right so what algorithm did it initially start and go from left to right that is left equal to left plus one at any instance if it found this condition is not fulfilling then it again change its direction so simple thing is that I will start from left then go to right and if a condition fail then I will change my direction towards left okay so this discontinue till left index is less than or equal to right index okay if this condition fail then we will out of the loop and our algorithm will terminate Then we discuss one more important thing that is selection of the pi-watt, okay. So there was a question called selection of pi-watt, so what we find we can go for first element, we can do with the last element, we can go with the median element, okay. And fourth one that we can do with a random selection. So all these cases may lead to worst case, may lead to, not exactly, I am saying 100%, may lead to worst case scenario. So, to mitigate the worst case formation or we can say that to reach out to the recurrence relation of form Tn equal to 2t n by 2 plus order of n means that we are getting what? if the problem is exercise 10 so we should get 5 and 5 okay so this is the place of pivot okay so this is the recurrence relation for quick shot okay but it is not applicable in case of worst case because in worst case what is the situation t n equal to t n minus 1 plus some 1 okay and order of n then t then what basically happening t and yesterday we have seen t n minus 1 plus 1 then it is equal to t n minus 2 plus 1 plus 2 then it is equal to t n minus 3 and so on so what basically happening extreme cases okay So, to mitigate all such difficulty, there was a mechanism introduced that is called as the median of 3. Median of 3. The algorithm is called as the median of 3. So, let us explore a little bit about that. Then we will start one of the interesting problem in divide and conager. That is called as the maximum sum error. Maximum sum error. okay so we'll see this burst this median of three then we will start maximum sub and so before going for that discussion here it is written what about the small array a small array means that let's say we are going to see the size is 5 or 10 and we are applying quick sort so what will basically happen you will never witness a reduction in clock time it is maybe in few milliseconds okay two three milliseconds there will be difference because we are dealing with a small area but we have to perform multiple operations so why not to choose insertion sort for a small set of element okay why not to choose insertion sort for a a small set of element okay so now this is important so for very small array quicksort does not perform as well as insertion sort because we will divide then we will select a pivot then multiply five would will be selected and in in in contrary in the quicksort can do our job okay and does not use quicksort recursively for a small array So, using a sorting algorithm that is efficient for a small array such as insertion sort. Okay. So, when using quicksort recursively, switch insertion sort. So, this is a variant. Okay. So, we are applying quicksort fine. That is working. But if the size of array is small, then we will recursively call what? Insertion sort. So, this version is called quick come insertion. Where when array size, we can set anything. array size is less than or equal to 5 what we will do we will go with the insertion sort. Okay so the main aim of the algorithm if you remember in quicksort was dividing a large problem problem into a small and we were setting a condition that if its size is less than or equal to 1 if size of array is less than or equal to 1 then we were saying we are at the base case or we stop but now when i saying these variants we would say that when array size is less than or equal to 5 then we will stop and directly apply insert and so on okay so if you visualize just a minute if you visualize so let's say we have an array of size something 20 then we will apply quicksort assuming the worst case is not there in one partition let's say we are getting 8 and in another partition we are getting well then here it is further divided and what we may form a size of array 5 a size of array 3 okay so here what will happen maybe we will get a seven and another will be of five so when we get a five or less than five what we will do we will immediately called insertion sort here we'll immediately call insertion sort on this part as well We will call insertion sort on this part. Sorry, on this part. For 7 part, insertion will not be applied. For this, insertion will be called. And for 7, it is further divided into 3 and 4. Then we will make an insertion call over here as well. Okay. So, what we found, now one can say, sir, you are saying, quick sort is taking n of log of n and you are repeatedly applying n square thing algorithm okay so so how could this could be better so this is better because we are dealing with just few number let's say size was 20 and we are dealing with one fourth size n by four then we are applying what quick shot okay so the number n square is not very big because we are already four times lower than the maximum number of element okay so the clock time difference will be very less okay so and computational requirement will be as per the algorithm requirement of quick sort and insert and sort and we also know that when the sub the arrays fairly sorted so insert and sort performs where it will tend toward its base case a best case okay so that could be a scenario so this algorithm is called quick come insertion become insertion I hope you people can visualize how this can be done so just you have to change the base case okay the base case means that the content you can see base case I mean I'm saying base case so primarily we are seeing the stopping criteria of recursion stopping criteria of the recursion okay so now you know as we have discussed partitioning part okay from the algorithm of median of three median of three is a strategy of our selection in quicksort And it avoids the worst case, reducing the computational time requirement by 14 plus. Okay. I am taking a break of 2-3 minutes and then I will resume to attend a call. So, partition that we have seen, median of 3 strategy, that is, a of left less than pi volt and a of right greater than pi volt okay so these are the pathway where we are going to choose the pi volt okay so so the basic strategy that we have adopted in median of three basic strategy that we adopt that is pi volt this is left and this is right okay so these are the strategy and the that we were following and if you talk about the median of three so basic idea that we already have done low that is the first index should be less than median should be less than high that is the last index so just these three indexes are there and what is the thing here we have to maintain this order key this must be lower this must be middle and this must be highest just a minute take a call median of three strategy was we will pick three element that is the first index last index and median index and arrange them in order that such that first less than median less than last okay and when this is done then we will replace median width second last element and that will act as a pivot and then we will start our operation of the quick shot okay now going ahead there's a question okay that I have started when I was starting the quick sort why quick sort is faster than much so okay so already we have discussed a little bit that already we have discussed a little bit that and due to external memory requirement requirement the quicksort is faster okay so let us see other regions as well so the inner loop consisting of an increment or decrement by one which is faster a test and a jump okay if you can see in I would selection there is no problem if say we are talking about the first element as power and our aim is to fix the position of pi one okay not comparing one one element label if you see in case of most of what we were doing s1 and s2 were there and this is compared this is compared and compared and then much and here we are although we are making comparison but we are just confining around a single element placement and here we were confining about the entire array comparison and then sorting in the order okay there is no extra juggling in much stuff that okay so this is the inner loop that we were discussing about okay and one more thing that is of course will be the external memory requirement or the caching requirement okay so that is not there in case of quicksort okay so now if we just simply want to do the analysis of the quicksort what we can say that a random pivot that is no median of three partition no cutoff of the small array to make it simple if run the s is zero or one then return the base case or pick element v in s called the five of okay so that already we have discussed so that will be the two partition 1 will be the this will be the pivot whose position is now fixed after each iteration so pivot selection time will be of course what order of 1 okay if you select the first element median element or last so it will be order of n if you do median of 3 so only 3 comparisons are happening so it could be as equivalent as order of 1 3 comparisons in median of 3 okay partitioning is linear time order of n because we can do maximum of n comparison and running running time of two recursive con that is important so this is the structure the algorithm should follow t i t n i i minus 1 plus c n okay this is how in worst case we will reach to the computational complexity of order of n square. So, this is this. Okay. So, this is just one element. One element or we can say one extreme element is selected. And this is the best case scenario where we are getting two equal partition in nearly all steps. Okay. But there is no such mechanism to exactly identify the middle element always okay if this scenario could be possible every time the pivot selection is the middle element middle element does not mean that it should be the median element it is the element that is appearing every time as pivot in the middle of the array sub array and sub sub array okay in that case only the computational complexity will reach toward n of log of n okay so if you go back to this slide so pivot selection order of one even it is median of three it is order of three you can say just then partitioning order of n and we can say for recursive division it could be what log of n so we combine all then we will have n of log of n but this is for best case for worst case what will happen pivot selection order of one then we are doing the partitioning that is order of n and this is a recursive call here if you talk about pivot selection partition and recursive call so what we will get order of one fine partitioning order of n and recursive call will again order of n so ultimately what we will get n square rather than getting log of n because recursive call is making for all n entries when we have chosen a pivot that is extremely small in each step so these are the two things so I hope quick sort is easy to go I've already given the pseudo code of the quick sort you people have understand the concept how actually it is working simply select pivot move from left to right if there is a violation that left element is less than pivot then we will change the direction and this will continue to selection of all the pivot and sorting of the array now let us begin an interesting problem in divide and conquer that is called as the maximum summary problem okay so there is a company named volatile chemical corporation okay and it is a share market listed company the market listed company and its share are also volatile chemical corporation is rather volatile okay so so share means that let's say some days price was hundred some date is hundred and twenty some date is 75 and so on so this could be the trend of the share value okay now there's a condition there is a condition that is to buy one unit to buy one unit of stock only one time and then it can be sell on the letter date so that means that i will if i buy on 11th of september so i cannot sell it on 11th of september i will sell on 13 12 anything okay after the closing of the trading of the day trading day closing is allowed so that is mostly happening in uh share market as well today also but just it is not applicable for the intraday stock prices like i hope because most of you are from this fintech company so you know better than me okay now we are not going into that stuff we are just going towards a problem okay so to compensate the restriction you are allowed to learn what price the stock will be in the future But here I am clearly saying we will not apply any ML technique. So, what you will do, our target is to buy the share at lower price and share it as the highest possible price. Okay. So, this is the primary objective. But here when to enter and when to exit. So, that is, so let's say we have a trend of the share of last year. year then we can follow that in the month of october the sale price was on the lowest and in the month of december we are getting the highest profit okay so if you see the curve so let's say this this this could be a curve for uh some duration if i say um from 30th september to 16 october this could be the scenario okay of 2025 now we are going to trade in 2026 i'm not going to apply any ml technique so what we found that it was someday it was 100 it was then 113 then 110 then the least price that the share could go was 63 even 63 then on some date is going what 9401 so if I buy the CR on 7th and sell on 11th if you can check so we will get the highest profits margin that is the minimum that is the requirement of a user that or or you can say that the user one okay so then if you see so now what actually i want what we need to ask so what it is least buying price and max selling price okay so if we have these set of values let's a 1780 number and we have to identify the entry and exit date so basically what we are trying to do we are trying to do NC2 where n is the total number of day and we have to identify those two day and if you realize what actually we want so initially let's say we say that profit is zero next day the profit is 13 if you can see this 13 minus 3 minus 25 20 minus 3 16 minus 23 18 and so on so basic our target is to identify the highest possible very odd or maximum summary that we want to identify maximum sub array whose sum is highest okay so if or in other word if I can say I had a set of number having both positive and negative as well having both positive and negative as well I want to identify a sub array whose sum is highest I want identify a severity whose sum is eyes therefore it is called as the maximum maximum severity maximum some severity okay that we we are seeing for this okay maximum some sub any okay this is the maximum some severity okay so I hope the problem is clear. We have an array of any size n that is containing both positive and negative number. If all are positive, so maximum subarray is what? Sum of all the element. If all are negative, the maximum subarray will be the least, will be just one number that is having the least negative value okay so just giving you a glimpse of the problem so here we had an array that is 13 minus 3 minus 25 okay 20 minus 3 20 minus the dot dot dot so on okay so if all the elements or positive and what we can conclude the summit no need to do any maximum salary anything if all the elements are negative and what we will choose the smallest negative choose a smallest negative just a simple negative value that is having the smallest negative means that or you can say not as smallest the negative so let's say minus 1 other minus 20 so I will choose minus 1 and declare it is maximum sum okay so because in negative we keep on adding that the negativity will increase so we will try to choose the least number with negative sign or what we can say in this case we will select the least number with negative sign. Simple. Don't confuse. We will select the least number with negative sign. Okay. Just picking a call. Maybe two, three minute break. Again, I'm taking. Actually, we are having the exam duty of the regular. Good morning. So, my doubt was when you say that PuigSort is faster than MergeSort and you told that in the worst case scenario, right, PuigSort is taking n square and the MergeSort is taking n log n. So, how will it be the faster, how we can say that? So, the worst case will rarely appear, okay, assuming and we are not comparing on the worst case. Okay, of course when we do a worst case comparison, then your merge sort will be better than that of quicksort But but we are not assuming is someone will provide us already sorted array for doing a sorting Any other doubt to anyone Otherwise, I said I have Yes, I have said please. So what else what we are doing and numeric data now suppose you're doing some these things data source and search So, what will happen if we convert into ASCAI character and then do the sorting or some other thing on the background we can do to increase performance? That is my question. So, here we are primarily talking about the numbers. So, in case of, let's say alphabetical or later, so that, of course, you will convert into ASCAI code and whatever the number will appear. Like for A, B, C, D, there are different numbers, 63 something. for smaller number it's around 90s and something so accordingly we will do the sorting okay and of course for a the number will be lower and for z the number will be higher so that is also there so so this scheme is applicable as well just we have to convert into its equivalent let's say binary equivalent or something and then we will perform the sorting any other doubt so basically on the array which you have on the screen it has the negative values on both the sides like opposite sides actually right so which particular you can say median side it will be taken at all in this case because the not median we will select the sub array that is getting you the highest values for example here if you can see so if i'm not wrong so there is only one possibility that i will choose i will enter before 13 and exit after 13 that is the maximum possibility otherwise we are having 20 as well or sorry we can take 20 not 13 because 20 is the highest positive number and other thing if i add so it become more negative so i will choose 21 and let's say the situation is 20 minus 11 and 25 so this will be the severity i will enter on this day and exit on this the profit will be maximum so it can be either side of that uh lower negative number will be there with negative number will be in between in between yeah because i then and your team yeah good morning sir am i heard of it yes yes you're on so um so for maximum survey you have uh like we are using a quick sort and there is also no no no before maximum survey we will do a separate algorithm it is not a quick sort variant okay so so the question is that given a problem like how do we identify that which algorithm or which solution we should apply for that problem there is a dedicated algorithm when i'm asking about sorting so you can use insertion merge or quicksort depending upon the number of the element and how the elements are it is they are fairly sorted sorted or not sorted at all or the size of the element if it is let's say 10 20 30 we will go for insertion if it is very large then we will go for quicksort and more sort if your memory is a constant then we will definitely go for quick sort so that kind of things we have to assume okay and some one one last question so there is also a problem called balance sub array so is uh so maximum sub array and balance sub array are same kind of question and same solution will be applied for both uh i have to check but uh but probably that will be different concept balance of error is not getting the maximum sum okay so so that that i will if you want i will discuss separately but this one is interesting because it is uh having three form solution that is brute force uh divide and conquer as well as the dynamic programming variant okay so complexity uh varying from n squared analog and n so all three cases are here okay so with that that for this problem is interesting because we can solve by the three methods and other that balance are very i will check it out and and if i had something then i will say it as well okay thank you sir yeah good morning sir we can use dual pivot in the quickshot so dual or trial or you can say four five but that is applicable when we are going for a so there is a subject called path like this is designing an analysis of algorithm so there there is a subject that is called parallel analysis of algorithm. In that, we will try to parallelize this algorithm. So, in that case, you will see that the sub-problems are treated separately or different processors where you have to choose multiple pivots. So, let's say one partition I'm doing with a pivot, then I'm doing multiple pivots selection. So, that is efficient only when we are going for a parallel variant of the quicksword. In sequential, you can choose multiple pivots, multiple places, so they will execute in a sequential order. So, that will not be much beneficial, I guess. okay so but there is a parallel variant of quicksort so you can refer the parallel analysis of algorithm or you can identify so you will get it there multiple pivot selection is allowed yes predefined sort methods are used dual pivot in quicksort in java and other languages so maybe they are doing some sort of parallelism but we are not aware of or if you are working then you know well okay okay so i hope the questions are done um there are three variants okay so for example this is the severity we have to identify the maximum severity so brute force algorithm we will try what we will try to form all the combination okay we will try to form all the combination and among that combination whichever giving you the highest sum we will pick. Okay. Just a minute. Today, there are some certain disturbance. Finish one part of it. That is the brute force mechanism for solving the maximum severity problem. Okay. So, let us see an example. Then we will come back again. So, let us say we have this question. Okay. Where we have the elements at indices 1, 2, 3, 4, 5, 6 and 7. Seven elements are there so basically what we will do in step one i will just pick one element okay then i will add these two so what i will get minus four then add this one then i will get minus five then adding three what i will get minus two then adding minus one minus three then adding two minus one then adding this minus three so highest among this is what two then in step number two what i will do I will start with the second index that is minus six minus seven minus four minus five minus three minus five maximum is how much minus three okay so then in third iteration we will start with the third index okay so in brute force the problem is that irrespective of the available solution we will explore all possible okay so that is minus one two one three then minus one so maximum among this is how much maximum on this will be three then fourth one will start with the fourth index three two four two so it maximum is four then fifth we will start with minus one minus one one minus one so maximum is four then in sixth we will start with the this location two zero maximum is two and the seventh index will be of course last that is minus two and minus two what we identified this is the highest four and four is highest when when we are adding three one and two so the maximum severity solution for this is index number four to six and this is brute force mechanism simple we will in brute force we have to check all the possibilities and among which which and whatever be the highest we will pick and give as a result we will pick and give it as a result so that is happening here as well okay so just removing this okay so this is the thing so maximum if you can see the maximum sum that we have bought is four so this is this will be the result and it is appearing when we are starting with index number four and reaching to the index number six okay so this is the result so this mechanism is brute force but what we will see we will see run one loop for a row and one root for column so the complexity will be just what order of n square okay if you see the algo stuff so this is looking like this so to for loop running for n times so complexity will be n square and complexity will be n square okay so now So if you see in maximum sum array, there are three possible solutions. This one was brute force. There is another variant that is called divide and conquer that already we are covering. And the third variant will be the dynamic programming, dp. So in brute force, we are checking all possibilities. Here we are reaching to the computational complexity of order of log of n. And here, if you surprisingly see, it is order of n only. So, this is the best approach. But the drawback of this one is what? The drawback of this one is, the drawback of this one is that it required memory to store previous outcome. Okay. So, using that, it is, on the top of it, it is working. And the algorithm that is known in this is called as the cadence algorithm, famous one. cadence algorithm okay so check it out cadence algorithm for dynamic program okay so okay so yeah what I will do divide and conquer algorithm we will see in the next class and I hope you people had received assignment one for assignment to the syllabus will be till maximum summary so which I'm just writing clearly till maximum summary till maximum summary and brute force one okay whatever I will taught in the next week that will not will be the part of your assignment to okay so I hope you people have receive assignment one soon you will also receive assignment two so that will be till brute force mechanism of maximum survey area okay so now I'm closing the class early closing because I have to go for a exam duty today and we'll meet next week as he's is having a query I will take it those who have done can leave the meeting and I will take few queries then then I will close the session