# DAA 27 Sep Lab

- **Course:** 5101 - Design & Analysis of Algo
- **Recorded:** 2026-09-27 00:00
- **Transcript:** 1667 segments, 10486 words
- **Made by:** deepdml/faster-whisper-large-v3-turbo-ct2

---
I will cover the merge slot. So the last time, I think I was feeling hungry, last to last time. So I couldn't explain well, we are confused in that. So I will cover that. Then I will go to this quick sort one. Then we will cover the cadence algorithm, which is maximum serverism. And then comes to the easier one, which is binary search. Banner is not saying both you guys are coming from computer science.com. You are referring to the trends like what trends are going on in the idea of those and you are being able to cope with that you know saving my screen first so yeah much should happen but the file itself is more ridiculous right so i'll explain again okay that this is the easier one okay you can able to get it and we'll move to the next weekly okay we'll not spend here okay yes so what happened in a more short i'll take one example as Previously, okay, like, okay, so, this is the, okay, this is the quick short, short start from here, short, and also write the date, two days to date, so that you will not confuse both, okay, so, fundamentally simple, right, so, we will first divide the array, okay, into the two halves,

I also written the like format you can see so you will divide the array into two halves then you will recursively sort both of the halves going to first the left side and then the right side then you will merge you will follow the merge function which is taking only the left side and the right side so before you see I will switch yeah so before you say we are taking some mid values then array left hash we are not going into that this is a simple word taking only this left value right value and merging that and then condition is same condition was the same so and if there is any left over values or left over add-ins result like we have been in the result hey I didn't explain how you brought that out ok no worries what's the doubt started the recording that's the doubt it's not doubt yeah I'll start the recording thanks thank you recording is started so we have similarly I will go to one example here it is written also I will take this one on you

so what is happening here so first of all we are like we are calling this function by passing this array 1, 2, 3, 6, 7, 8 create elements are there. Okay. We are passing this error into this function. Function call is happening. So, I will call this function. So, something like this. Okay. And this paste. Okay. Then, what's the length of gate? Okay. So, in this function what is written if the length of the array is less than 1 which is what okay which is coming to the 8 so it will not go to this function okay then coming to this okay it equals to length of the array divided by 2 so in the python we don't write just divided by this okay next last line we write in this manner okay so divided by 2, which is coming to 4, okay, and then left equals to, okay, let me show you, what is this? If you are a new guy, so this is the start, this is the end, you can say, okay, in between that, okay, let me go to this first, okay, let me not confuse you,

so this is the start, and this is the end, okay, so this is means that okay so column means you are starting from zero going to till mid which is four okay four is coming as a mid so means zero one two three four okay then in the left side we are dividing this right side we are dividing this mid to the till last okay if we are not giving any values in the starting or ending it will go till the last it will start from the first okay hope you got it another thing is that okay if you're writing in this man step okay step means it will uh simply like skip the values okay skip one values and it will go to another value like you can see okay so like example they found i will tell the example 0 1 1 2 3 okay if i am writing the step 1 okay so it will go to it will start from the 0 okay let's say we are starting from the 0 and going till the end correct so what step value will give it 1 okay so it will point out to 0 okay so for the pointing out how i can

point. So, it will, okay, I am giving the point. It will skip this value 1. It will go to the 2. It will skip next value. Okay. So, if you want to got the result, you will get only 0 and 2. Okay. Got it? So, this is how this will work. We are just giving starting and ending not step value. Okay. This just means this okay so i have mid value equals to 4 we are getting and then left equals to we are starting from the 0 until 4 right side equals to starting from the mid going till last 2 okay if it is then how we are dividing okay so this is an array okay we are containing array in that array what we are containing? This number of index. Okay. This you can consider as an index. Okay. Zero to four. Okay. What does it mean? It means, okay. Sorry. In the left side, what I am containing? 10, 7, 8, 9. Okay. In the right side, 1, 5, 3, 2. Okay. For the simplicity only i have taken eight values okay i can take uh all number of values you can you can take that

and you can write out okay so now it is divided into two halves okay now we will go to the next one okay so what is this this function will call i am simply copying this state here this function will come first left part we have to divide okay so dividing the left part okay so what left and all the okay it will again take the length okay what's the length four okay four is the length four is less than one okay four is less than then it will skip that okay then it will go to the dividing part. It made, when it was 2, okay, how it came to 2, 4 divided by 2, which is 2, okay, how it will divide, then 7, 8, so I will write in this manner only, left side, right side, 9 then I don't need to debug, sorry then the left part over here, right part over here then again we will call this function ok copy paste again it will call this function ok, so this is what we are calling recursively calling this function left, left, left

ok, then it will return it will, ok, so what is the base condition this one this one is the base condition ok, so it will return from here when it will return then the length of the array is less than or 1. Okay. It will return the array. Correct. It will return to whom? It will return to merge out only to this function. Then after ending index function, it will call to this one. Then right part will be divided. After everything is divided, then we will go to the merge function. So, I am quickly doing this. first word only. So, what's the length of the array? Which is 2. 2 is less than equals to 1. Yes, it will not go to that condition and it will go to mid. So, mid equals to 2 divided by 1, which is, it will divide the left one again. So, what is the left? 10. What is the right? 7. Okay, we go. Now, it will go to the condition. Okay, what's the condition uh what's the condition if the length of the array okay okay again it will call to this

function okay correct you can you can call to this function in the left side it will pass only the 10 okay which is length of the array is 1 1 1 is less than equals to 1 so it will return return to much okay now when it will return to much okay much short so length of the 10 is 1 1 is less than 1 so it will return return the array okay so we are returning the right see here we are returning the array okay we return that now it will go to the right side part right right side part so when it will return to that okay now it is recursively calling now it was recursively calling so when it will return to this okay now this is completed okay this is completed now it will start will start okay when it will start i will copy this okay taste it here now in the right side what is in the right side we have only 7 okay so we have only um 7 correct so in the 7 again it will go okay so length of the error is 1 correct why it

is 1 only 7 is there right 7 means 1 1 is less than 1 yes 1 is less than 1 means it will also go to the, again return, okay. Then it will return, okay. Why it is returning, okay, for this simplicity I am telling, why it is returning? When it is going to this function, it will try to recursively call this function. See the name, must shout only, see the name, must shout, okay. It will try to recursively call. When it will try to recursively call, there should be a base condition to complete that, okay, recursiveness. So, for that, we are writing this base condition. Okay. What the completion is. Okay. So, when it will come to this, it will say, 7 is there. 7 is there, which is length is 1 only. 1 is less than 1. I will return this array. So, this array will return. Okay. In the right side, we have only the 7. In the left side, we only have the 10. Okay. correct and it is returned okay now i will write here it is also one minute because

okay so it will return okay now it will go to the in the right side we know that we have 7 in the left side we knew that we have 10 okay now it will go to another function which is merge merge of a i given only the left and right correct so left and right correct then what it will pass only the array will pass right so we will shortly look what is there in the left sorry what is there in the merge function so now we know that what does function these two dividing only right so it is merging so merge means merging merging the both array so how it is merging it is starting from index i equals to 0 j equals to 0 so there is a result array also which is containing the result after sorting okay then it is comparing both of the left and right okay so uh it is comparing the i okay so we are writing in a while function uh also previously i told that we can also write in a manner of a for loop okay uh so yeah so it is first checking

the length okay so if it is not satisfying then it will not yeah so yeah so if we write in the follow loop then what will happen we have to write an extra if condition right so we'll go to till that right although like if we have to write one if condition if it is checking the length of the array is satisfying then only you go to this so we'll quickly start to not take the time okay so there is some result function okay and then i equals to starting from zero j equals to starting from 0, left side containing, again for the remindedness, left side containing 10, right side containing 7, which is both of the length is 1, okay, while i is less than length of left and j is less than length of Alright, okay. Then, what is i? 0. Okay. What is length of the and? So, in the and condition, both of the conditions should also be satisfied. Then only it will go to the, in that condition. Okay. So, what does that mean?

these two functions will be satisfied. It will not go for the next check. If one condition fails, and one condition passed, then what happens? If one condition fails, in the end case, it will not go for the next check. If one condition fails, then it will not check. So, what is the distance? It will come out of it. So, that is the benefit. And if one is true, let's say this one is true, check this one. If it fails, then also it will not go to the while condition. So, this is the speciality and then, yeah, j is less than length of the write, okay, j is less than length of the write, which is condition satisfy or I, okay. Then, what we have, we have the if loop, if loop the write, what it is checking, it is checking for the, you can say, this one, 10 and 7, okay, 10 and 7. then storing it in a result area see storing it in a result area so what it is checking is the left of i left of i is less than right of i which is not

10 is less than 7 which is not which is false therefore okay therefore it will not go to it will not go to this one okay else what it will do this it will do it will go to the result.append right of a j okay right of a j is what okay in result we store 7 store the right we have a 7 we get the right we have a 7 plus 1 okay j equals to j plus 1 so j was a 0 1 plus 1 which is 0 plus 1 0 plus 1 which is 1 okay it will check also this one okay add the remaining element Okay, so there is there will be a condition, okay, which is already sorted. Okay, you just need to append that. You don't want to be check all these things. You just need to append. So it will go to the it will go to this function. Okay, so while I is less than the left. Okay, then please append that. okay and i will i is less than length of uh which is zero is less than one add 10 okay in the result array it will say here 7.10 okay what append means append means it will

add into the left uh add into the last of the array okay append means last may add and let us take it so now the it will return the function okay much short it will return it will return okay return this from j return 7 comma 10 okay correct now okay likewise like it will call much short much short of 8 and 9 it will come and then it will say like it is already divided right so it will go directly to this one okay left and the right okay it will again recursively call 8 and 9 okay then it will go to again 9 and 8 okay, it will compare and then it will merge, okay, got my point, like you got the point, right so, okay, let me see in the second part, so this is the first pass, okay, we got one function, okay let me see the second one, 8 and 9, okay so, what I am assuming is okay it is returning okay it will comparing and it is uh returning 8 and 9 okay i'm not repeating into that now coming to main part okay now coming to main part is 7 and 10 which will

merge okay and then in the left side we have a 7 and 10 in the right side we have a no no no we will merge both of this so now we are returning much short of much short of 10 7 8 9 correct at this point we have a left 7,10 and it is only returning the human right okay so in the left we have a 7.10 in the right we have a 8.9 okay and then we will go to 7.10 8.9 okay so if we will execute this okay so if we go to the left okay so we need to take that again clean okay and again we will see i goes to 0 j goes to 0 okay and then one result array is there okay result array is there now it will compare okay left of i okay so both it will check the both it will check the length of the array okay I am assuming that it will go to the while loop okay then I am telling okay left of i okay which is 7 okay and then right of j see in the if condition what it is checking in the if condition what it is checking left of i with right of j correct so that's i'm checking

so what is left of i like i what is i which is 0 0 means left of i is 7 okay and then right of j 8 of j means 8. Okay, it will check. If 7 is less than 8, it will say 2. Okay, then add 7. Okay, in the result error, we have a 7. Result error, we have a 7. Then move the i to, move the i to, i plus 1. i plus 1. i equals to 0. Sorry, i equals to 1. j equals to 0. Okay. Now, it will compare again. Okay. Now, it will compare again. Left of 5. Okay. It will compare the again while you do. Okay. It will come out to be true because length is 2. Correct. and then left of 5 is 10 right of j will be 8 ok then we will check if 10 is less than 8 it is now to be false in the false condition what is happening we are adding the we are adding the right values in the else condition correct So, it will add the, so, it will add the right one, correct, add 8, the result, the result we have 7, 8, okay, then move j to j2, j plus 1, which is i plus 1, j plus 1, so, it

will again check the length okay so is it satisfying the length yes it is satisfying the length then it will go to again left of i equals to i am not checking the while condition again again okay you can check that left of i okay so what is the left of i testing here Now, i is pointing out to this, j is pointing out to this, okay, left of i and right of j, okay, in the left of i, right of j, okay, it will again compare, 10 is less than 9, no, false, in the false condition, we are adding the right value, okay, to the result, okay, we will append. result equals to 7,8,9 ok we have a 7,8,9 now we will move j to j plus 1 ok so now it will check j to j plus 1 means i equals to 1 j equals to 2 now condition will fail now right side is finished right so right side is finished and the length of right is supposed to 2 ok so when it will check the condition j is less than length of right ok so first condition will pass ok so where is the condition

so what is 1 so i is equals to 1 and length of the left length of the left is 2 ok so this is passing ok this is 2 now it is failing 2 ok is less than 2 because length of the right is 2 correct and then what happened so it will not go to the function ok it will not go to the value now what will happen so is false, then it will go to the remaining element row. So, it will go to this one. So, it will check for while i is length of left. It will say yes. So, it will not go to this. Even if it will go to this, it is failing. So, I am writing this because of adding the leftover element. What is the leftover element is this? 10. In the result array, we didn't add the 10, right? So, that's why I am going to leftover element. So, while i is less than left, length of the left, result dot append, left of i. So, left of i is 10. So, in the result array, it will append the 10, which is now 7, 8, 9, 10 and then i is equals to i plus 1. Now, both of the conditions will

fail here, here and here. Now, it will return the result. It will return the result to this. So, this is how 7, 8, 9, 10 will be now the left side is sorted. Okay, now we will go for the right hand. So, it will sort like this, correct? So, this is how Meshrot will work, correct? Got the point? You don't have any doubts? Okay. Now, Vikesh Pumarthivari Hi, Vikesh. Yeah, hi, Adita. Thanks. Thanks for the explanation. Actually, I had a doubt when we check the condition in merge sort function if you could go to merge sort the first condition length of array is less than equal to 1 so you said that since 1 is less than equal to 1 then it will return array but it is not the case 1 is less than equal to 1 it's true right okay okay okay okay i thought it's not equal to yeah it will get into this and return the array my bad okay thanks thank you vikis so we will go to the quicksort so what is quicksort let me tell you first i have already written because i don't want to waste the time in this so quicksort is

like here okay so don't go to this first so what is pivot and all don't want so i can write quicksort is like so quicksort is a divide and conquer just like it is also dividing and conquering the piece however there is a major difference so more short is like divide first divide the array first into pieces then sort while merging ok so quicksort in hand is like it will place a pivot it will come to the point what is pivot in its correct position first then recursively then recursively sort the elements on its left and right. I'll take that out on the channel in the letter. Thank you. So, this is the difference. So, what is the pivot? Pivot means like a center position, you can say. So, here the pivot is slow. So, what happened? Actually, I can take one example. Let's say 8, 3, 5, 4, 7, 6, 1, 2. Okay. Something like that. So, after some point, let's say I'm taking the pivot value as this. Signing P. Okay. In the last point, I will take any L.

Okay. Any of the pivot element. So, first we will place the pivot element into its correct tool machine. Okay. So, how it will work? So, it will first compare the 8 with 2. So, is 8 is less than 2? No. Then it will come to this something like that it will work. It will copy. So, it will check is 8 is less than 2? No. This 3 is less than 2, no, passing, okay. This 5 is less than 2, passing, 4, no, 7, no. It will check with the pivot element, right? Okay. So, we are trying to placing the pivot element into its correct position first. It will check with the 6, no, 1, yes. Okay. 1 is yes ok no what it will do it will replace the first element with 0th one what it does is like it just replaced the first element with the current one which is lesser ok Okay. Then what will happen? It will go to its correct position. How do I do? It will simply already replace. Now it is replaced. Plus 1. Okay. It will do them just like that. Then what we will get?

1, 2, 3, 1, 2, 5, 4, 7, 6, 8, 3. Now what will happen, if you see, which is pivot element, which is in this as a pivot element, right? So, after the partition, after the first partition, okay, so this is the first partition, okay? So, after the first partition, 2 is in its final sorted position, okay? Everything to its left is more than, if you see, and everything to its right is larger. So, the two sides are not necessarily sorted yet. Okay, again I am saying, the two sides are not necessarily sorted. If you see, this one is sorted, right? So, because this is the first element. If the pivot element, like some about here, then it may, like, it is not sorted, it is also not sorted. Something like that, I am taking the next. Okay, then in the second part, also we will do like that. Okay, so this will, again, go to choose the pivot element from this side okay then it will uh choose this one is a pivot element okay so now this will

chosen as a pivot element as i'm taking uh the last element as a pivot element okay again and again so that's why it will choose this as a pivot element now except okay so it will not compare with this also okay so what we have chosen as a pivot element except this it will compare all of this so accept this we will go until this okay so now it will again check okay which is smaller okay so no one is smaller right so again for that also we have a condition okay it will replace with the correct one okay so it will something like that so for that we will try it on. Okay. So, this is the philosophy what I am writing later. So, choose the pivot element, put this one, everything with the smaller, the left side, everything bigger in the right side. Quicksort the left side first, then quicksort the right side first. So, this is the philosophy of a quicksort. And this is the code. We will go through this code. We will

try it on in this one only. we can take we can take this this will be easy so let's go to the code first so what it is telling ok so first we are taking the array then we are calling the function quicksort ok this is taking the array and the 0th position and the length of the array minus 1 ok so we will go to the quicksort first ok we will go to the quicksort this one it is checking in the base condition in merge sort also we take in the base condition as a if length is less than equals to 1 it is also checking if low is like greater than high why it is that because it is checking from both of the side, okay. Now, if you will go to the dry run, then you can understand also better. Okay, it is checking from the both of the side. If it is like a swapped or something, okay. Then, it will return, okay. When low is something as a large, okay. So, by the way, what is low and high? This is only an index, okay. This is only the index, correct?

This is not an array. See, Like a 0, length of array minus 1, taken, okay. So, that's fine. So, now, place the pivot in its current position, okay. So, for that, one pivot index, okay, for the tracking, and then I am calling this function, which is passing partition of array, comma, low, comma, tag, okay. So, how many elements are for 1, 2, 6, so it will call this function, okay, call this function, we will put short of array, comma, 0, comma, 7, it will check if flow is high, which is not 7, okay. Then it will come to this pivot index, which is calling the partition of array comma logoma i, and partition of array comma 0 comma 7. If we go to the partition, it is taking first is a pivot element, which is the last one, array of a high, high means the last one, which is 7, array of a 7. it's written also like a boundary of a smaller advance although I will explain this is very important I represent that

the boundary of elements that are smaller than or equals to the pivot element ok so initially there are no such elements ok which is smaller than or equals to the pivot element ok that's why I am assigning i equals to minus 1 ok so if you will see 0, okay, it will come as a 0, okay, 0 minus 1, then it will assign as a minus 1, okay, correct, so now it will go to the for loop, for j in a range of, okay, for j in a range of a low, high, okay, and then it is checking with the pivot element, as I said, it will check recursively with the pivot element. If it is low, then it will go to the i plus 1, okay. Means we have found the first element as a something lower, okay. So, until that, we have we don't have any lower element than pivot, right? So, we have found first element, okay. So, it will take i plus 1, okay. So, which is minus 1 plus 1, which is 0. We will both look at No worries. So, for i in a range of low, high low is equals to 0

high equals to 7 so j is going to 0, 1, 2, 3, 4 5, 6, 7 6 up to 6 it will go. So, high is 7, right? So, for i in a range range means 0 to 6 it will go ok it will not going to check the last one because last one is our pivot element right then array of array of a j it will check array of a j which is 8 and pivot is 2 so array of a j we will check with pivot element which is 8 is less than 2 which is not so it will come as a false then again it will check 2j equals to 1 then it will go j equals to 1 in the j what do we have? I am not checking one by one like 3, 5 it will go, then come into the 1. So, now I am going to 1. Okay. So, it will check continuously till it form smaller element and pivot. Okay. Small element and pivot. It is less than 2. Okay. Then, i equals to i plus 1. i is currently minus 1. So, i will become 0. Okay. i will become 0. Then, what it is doing? Swapping. As I said, okay. It is swapping the values with the first element. Okay.

So, what is the array of a 0? What is the array of a 0? 8. okay so this is the way of writing to swap the element okay so we are not going for the c and c plus plus profile we have to pick the third element and we have to write okay or we are not going for the plus and minus to swap the values there is a leverage in python or you can like writing this manner so it will swap so it will swap with So, let me write it And then Array of a 6 What does it mean? I will show you that Also It means that Array of a 0 will swap with Array of a 6 Array of a 6 will swap with Array of a 0 Means 8 will swap with something like that with 1. So, array will be 1, 3, 5, 4, 7, 6, 8, 2. Okay. After swapping, what happened? Place the pivot in its correct position, which is this one. I told right it will place the pivot element also so array of i plus 1 ok so now it will not go to the last element and it will check the i first of 0 so now i first of 0

i i plus 1 means 0 plus 1 means array of a 1 and then array of a height. What we have taken as a height? 7, right? Then 7 will replace with array of a 1, okay? Which 2 will swap? 3 will swap with 3 will swap with 2, okay? 3 will swap with 2. So, array will become 1, 2, 5, 4, 7, 6, 8, 3. Okay. Now, what happened? Return i plus 1. Okay. So, now i was 0. Okay. So, now i will become return 1. Okay. Return 0 plus 1. Correct. So, therefore, what it is returning to? it is returning to pivot index. Where we are coming from? We are coming from this. We are coming from this. It is returning to this one. Partition. So, now what it will get? 1. It means our pivot index is now 1. You got the point? How it is 1? See here. We have taken this as a pivot element, right? So now, what is the index? 1. So it is returning 0 plus 1. So 1. Okay. Why it is returning? Why we are calculating the pivot? Sort of array, flow, pivot index minus 1, pivot index plus 1. So if you will see here, we are taking the low and high.

Okay. First of all. So, we are trying to sort the left side first, then we will sort the right side first, by again taking the pivot index, pivot index, and then again checking this condition, this condition. So, if we will go to the left side of the pivot element, what we have, so as usual, we are passing the array, what is in the left side? after the update of this one so we are sorting the left side first right 2 3 4 5 6 7 ok so we are sorting the left side first ok so what is the left side code this one ok I will write here here why we can if i can't just go to here and write and see will not do mess up here okay so this one okay so after that after returning from the pivot index so what is our lows we are passing the array as a result this update uh a decade okay what we have in the left side low what is low index number so index number is zero so this is the left side okay and this is the right side okay so so this is the zero

pivot index minus one what is the pivot index one okay for now it is one minus one which is coming out to be zero okay when it will coming out to be zero so r what is low and high low and high is this one only correct so when it is going to so yeah so i'll write here again maybe it will like a b c d for you okay so i'm i'm sorry for that i have to explain in this manner don't it so yeah zero and a high okay so now it will check the if low is if low is greater than high. So, it will tell 0 is less than 0. Then, please return to your function. So, this is the base condition. It will come again. It will come to this one. It will come to this one. It is completed. It means completed. When it will return to this, this will complete it. Okay, now it will go to the right side. Okay, so I'll Varun Kumar, I'll take that out. Okay, no worries. Let me understand you. Okay, and I'll take the, this is the right side part. Okay,

I'll write, I'll write here also mentioning this is the left side. Okay, we are sorting and this is the right side. Again, I will write this. Okay, on the downside, okay. Now, this is the a we are passing, then pivot index plus 1, okay. So, what is the pivot index? 1 plus 1, which is 2. So, this function is telling you start from pivot index plus 1, okay. Then, what is the high? What is the high value? Till the last, right, which is last 7, correct so now it will check if low is greater than high it will say no if it is not greater than high you go and check you go and place go and place your pivot in correct position and after send it 10th right position please give me the correct index so that I will execute so now it will go to again it will check can I show another pass also by partitioning or it is not required what do we have a time we have a 12 right pattern and pattern is easy, binary also is easy I can show you another class okay

so yeah now it will pass quick sort of array 2,7 okay array 2,7 and then so yeah in the partition what we have the code we have the code of a pivot okay pivot of okay as we are taking the pivot element is high then we don't know what's the we didn't got any smaller element so that's why we are taking low minus 1 okay so let's load things so it's a low minus 1 so what is the low okay so 2 minus 1 okay which is 1 and then what is the pivot element array of a high. So, I will write here in the mat which is to array of a high. Array of a high means array of a 7 which is equals to right here also array gap. So, then 4j in a range. Okay, 4j in a range 4j in a range go to 2 to 6, okay it will not check for the last element because last element is our pivot element it will not check, okay there is no point, then go to the second partition, okay, so j equals to 2, j equals to 2 and then it will check like an array of a 2 array of a 2 is 5 5 is less than 3 it will say false

ok now it shows what's the next error I'll paste the updated error here so that I can also able to then it will go to the 4 4 is less than 3 it will say false loss name then it will go to 7, ok, false then it will go to 6, false then it will go to 8 which is false, so we didn't found any of the case, ok, so it will not execute, yeah, write for it will not execute this one and also this one it will not serve but we will go for placing the pivot elements to it correct position it will go to this so what is area of i now is 1 i will write here i is now 1 area of i plus 1 is 1 plus 1 area of i high is 7, area of a high is 7, area of a high is 1 plus 1, so area of a 2, area of a 7, area of a 7, area of a 2, ok? So, 5 will swap with 3. So, it means, okay, 5, 3 equals to 3, 5. Okay. So, 5 will swap with 3. So, array will become, what was the array? Okay. Okay, so, array will become 1, 2, 3, 4, 7, 6, 8, return i plus 1, okay, 1, return 2.

So, now, we got the pivot index as 2, okay, which means our pivot element is this one, okay, pivot element is this one. So, again, it is not necessary that we go to this, okay. It's not necessary that it's sorted, it's also sorted. Then it will go in recursively, recurs again, okay. So, it will call the left-hand side first, which will pass a quick sort of array, array of a low, high, which is 2, 1, okay. then it will check for the left side like 2 is greater than 1 right so so it will check here so it will check here like 2 is greater than 1 then it will finish then it will go to the three two seven so zero one two three so three two seven it will go in and it will check It will again find the pivot element, okay, pivot element is our last element, okay, then it will compare with all of the elements, okay, if it is found lesser than, which is yes, this one is lesser than, it will first swap with the greater one and then it will likely swap with its correct position, then it will return its position, okay.

So, this is how it will work, okay, so it's not necessary, again, you have to take the pivot as a first element, last element, you can take as a first element or any element. Hi, Subrat, you have any doubt? I think Subrat is not. Harun Kumar Agarwal, you have any haven't it out raised your hand not exactly doubt sir i want to see the last part of your code where you were changing the pivot index and that part can you show again that part sure sure uh better i will paste the uh like a totally link okay although i'll paste okay so which part taking the pivot element right yeah so i understand all the logic what i'm trying to understand is why we are in changing the pivot index at the very last after the return you do yes you returning this pi plus 1 which is assigned to which one to what with the pivot index so pivot index it is returning the pivot index only okay so why we need to do maintain the pivot index

variable sir it's because so because we have to do accordingly okay then we will get the pivot index here okay so we have to sort the left side and we have to sort the right side according so that's why we need pivot index okay you got it I missed this I thought we have two different variables okay clear sir so there are two different functions also if you see one is a partition and another one is for the okay yeah okay clear sir Thank you, Varun. You, Subrat, come back. Hi, Subrat. Are you allowed to mic and unmute and speak? I think it's not there, otherwise I don't know what is happening. Okay, so quick sort is clear to you guys, right? So, that's the question only. If you really go here, okay. So, yeah. So, these are the test cases. These are you can complete. So, we will go to we will go to the maximum sub-array sum. So, this is the simple portion, maximum sub-array sum which is developed by cadans. Okay, so there is nothing, just we are finding the contiguous sub array, okay, let's say, so this one is the whole array, right, which is length of 9, so we are finding the contiguous array, okay, which will come as a maximum sum, okay, so let's say,

So, this is the simple one. See, which is also the correct one. So, let's take it. I'm taking like it, including positive, this negative one, right? So, sample, okay. So, we have to find the maximum sum by anything, okay? so first group force approach what we will do we will maintain one result array and we will maintain two for loops okay one is on the on the whole array and another is one for the internal array okay so let's say one is plus with this one okay so we are taking first then we are adding with this this and we are maintaining one result okay then also we are taking this one okay and adding this this this this this we are gaining maintaining one result and then both the result are comparing okay which is greater okay then result the final result is coming okay then we are taking also this one okay so again we are doing this okay we are maintaining two for loops. So, in that, what will happen? Time complexity will be

like a more. If we have a 9 element, if we are taking two for loops to check for the array, so 9 element, so time complexity will be something around 9 x 9, which is coming as a 81. So, something 81 minute maybe, okay, 81 second, okay or arc, okay. So, which is not cool, okay. We have to do in single pass correct. Through that, we can maintain also our time complexity and we can maintain also our space complexity, correct. So, base will be like minor which will take hope you got the question ok maximum sum array maximum sum array sum I am taking an array ok what I will do, I will take first current sum what is up to the current sum till now, which is going on which is going on sum, this one okay and this is the global sound okay this is the global sound which is array of a zero i'm taking both both of this okay it doesn't matter you can take minus one also you can take something you can like minus one okay you can take any of the element okay let's say i want to take

array of 7. I can take something like that you can take not necessarily array of 0. Then in the first pass only 1, length of 1, length of array. I will maintain my current sum. I am starting from 1. Why? Because I have taken 0th element is this one, okay. That's why I am starting from 1. I will compare that element to other elements, that's why I am starting from 1, okay, till length minus 1, okay, because the range is like a n minus 1, it will take, so that's minus 1. So, I will update my current sum first, which is maximum of, okay, Okay, area of a i, area of a i means area of a 1, okay, maximum of 1, okay, and then current sum plus area of a i, okay, current sum plus area of a i, and then I will maintain another maximum sum which will compare with current sum, okay. okay so let's say our maximum sum is something like that okay it will compare with the current sum okay and then it will return the max sum okay and do you want me to dry run or you will

understand let's dry run right okay so same with this element it's quite long but it's good to understand so let's say this is the array okay I am taking this one as this okay so what will be our current sum so I am writing not underscore okay current sum I am writing as a minus 2 and then maximum sum will be minus 2 okay and then for i in a range. I will start from 1 because I am starting from 1. You see, comparison. I am starting from 1. Array of a 1 which is 1. What I am doing? I am maintaining current sum. I am maintaining this one. Current sum and then which will come out to be come out to be maximum of 10 which it is, sorry I am writing again 1 minus 2 plus 1 ok which is maximum of 1 comma minus 1 ok, so what is the current sum? final answer which is max 1 ok, so till now we compared and got that 1 is our greater element till now. Current sum. Then it will go to the maximum sum. Max sum is 1. Sum is x sum is 0. 0 is minus 2. Current sum is

1. So, max sum goes to 1. So, till now, we confirm that max sum is 1 only, correct? Then it will go to the i equals to 2. Area of 2. So, area of 2 is minus 3. So, area of 2 is minus 3. So, current sum is right, area of i. So, max of 3. Area of i, max of 3. and then current sum plus area of area. So, what is the current sum we have got? 1. Okay. So, 1 plus, sorry, minus 3 plus current sum will be maximum law minus 2. Oh, sorry. Minus 3, not 3. Yep. Current sum will be minus 3 is greater or minus 2 minus 2 is greater right so till now we got current sum minus 2 is greater we have compared correct so now we will calculate the max sum max sum is maximum of max sum okay which was the max sum 1 and then what we have the current sum till now 2 okay so which is greater. X equals 2. 1 is till now greater. So, we have we have iterated up to this element. We got 1 is our greater element. So, we will iterate 2 theories. Okay. So, now

it will come as a 4. Okay. 4 will compare with the 1 again. Okay. So, it will go and iterate. So, hope you got the point. Right. How cadence algorithm works. It will be minus 3 yeah I corrected thank you so any any doubt you love oh I don't so far no any doubt hey Subratpal you are playing with you know what you are raising the hand and the land and the night and you are not speaking can you type like what's your doubt hello yes hi yes I'm actually I had some problem with my browser that's why i don't have any option to speak so i changed my browser now it's okay so i had a doubt regarding the quick shot right so i implemented the quick shot and when i uploaded try to upload now there are some hidden test cases which are failing so uh do you consider those test cases also because uh it's little bit which case number is failing can you Can you tell me? I will note it down. 4 problem. 1 test case is failing but that test case is hidden. No, that was the...deliberately it was finding.

Okay, like it was an intense test case. Okay, hidden test case and it is giving runtime error. So without seeing the input it is a bit difficult to sort that problem. That's why I am asking you this question. Scroll down. Okay. I'll take care of this four and five, okay. Okay, Raviranjan, sing, I think, yeah. I am allowing your mic. Raviranjan, Raviranjan, are you there? I am here, sir. I can able to hear you with some noisy sound. Yeah, still here, I'm fine. Where are you, first of all? Where are you? i'm from ara no no where are you right now you are going somewhere no no okay i thought okay so let's get to the point okay so you told like please do the time until the end you cannot able to understand so here i am able to get it all but i just wanted to know what will be the Okay, so be with me, okay, let's go with the Ravir engine, okay, so tell me Ravir engine, I already told up to this, so, okay, first of all, you mute your mic, please unmute,

yeah, thank you, so, first of all, which question you want to try around me, this one or like quick sort one so already like the last this one okay so even though like a noisy sound scan quickly and then handle that so now till now you got to this okay you understood up to this right yes okay uh so now you only tell me okay what will be the next steps what should i write you got to the okay so let me also provide you the code so that you can understand i am pasting the code here okay so please go through this code okay and tell me the next steps what will happen okay in this what should i write here if you got the point if you want me to try it until the end i'll go with you there is no any hurry or worries you understand what is maximum severism yes yeah so I already provide you the solutions of this one okay and I dry run up to this okay and you can tell me for the steps from 4 yes obvious things I will write the current sum

the current sum will be match of the current element and so what is the current element current element will be the next one what is the i what is the i okay i will be 3 array of a array of a 3 right yes so array of a 3 is okay i am sorry for that i can also provide you the array you can check out this okay yep So, yes, maximum of? Maximum of 4, comma. Maximum, oh, okay, sorry, we will go one by one, right? As we are going to this one, right? So, area of 3, so, yeah. 4, comma. 4, comma, sum of current sum plus area of... What's the current sum? Tell me the values. I know that. Minus 2. current sum will be minus 2 plus 4 minus 2 plus 4 maximum of max of 4 comma 2 so which is maximum will be 4 then next steps then max sum will be max of max sum plus max sum and comma current sum what is the max sum till now max sum is one yeah and current sum is four is four so maximum will become four good okay so next steps yes so next inputting array okay i pulse to become four

array of four four will be array okay yeah i see here now it will be minus one current sum So, it will be max of array of 4, that is minus 1, so minus 1 plus, minus 1 plus current sum will be max of minus 1 and 3, which is 3. Max sum is equal to, max sum and current sum, so max sum is 4 and current sum is 3. so it will be 4 and sum is equal to max of that is 2, current sum that is 3 sorry sorry sorry 3 plus 3 plus 2 plus 3 that is 5 current sum is equal to max of 2 comma 5 which is 5 max sum is equal to max of max sum in the previous step we got that is 4 I think I don't think we did something wrong or like, okay, I just, we did like, and I equals to 6. So, array of 5 is, array of 6 will become 1. 1 comma? Array of 6 plus current sum. Array of 6 is 1, plus current sum was? Current sum was 5. So current sum will become maximum of 1,6 So current sum will become maximum of 1,6 What is to? Max of 5,4,5 5 plus current sum 6

Current sum is equal to max of 6,1 And of 8 equals to? Current sum 1 Current sum is? 1 plus 4 Max of 4 and 5 maximum will become max of 6, 5 becomes 6. Maximum of the subarray will be the sum for that subarray will be 6. 6. Okay. You got the point. And if I need to find the subarray Okay. So you return the maximum sum. Okay. Thank you, Ravi. I hope Paul got the point. We till the last try-run. Okay. And yeah. So any doubt regarding regarding this? We will go to the next concept which is binary search which is very easy. So what is searching? Like we are searching through the elements. Okay. And then we have to don't go for the linear search because it will take time that's why what we will do we will divide the array and we will search through left and right point so something like that and suppose and binary search is like it don't check every element it will look at the middle and eliminate half of the array every time so it will divide

the what was it It will only work for the sorted array. And array is sorted. And if you want to see what is what you are finding, let's say you have the element like 2, 5, 8, 16, 93, 58, 58. right? And you are finding the element paths which is 23. In the linear search, we have to go one by one. We will compare with if x is equals to this element, no. If 5 is this element, no. 8, 12, 16, 23, oh, we're fine. Let's say we have a million of elements. We will go for the linear search, no. That's a not right approach so that's why we will like a half the array okay so we will find the mid element so in this case what i have said so mid element is like a 16 okay so we want to compare 16 with the 23 okay so is 23 is greater than 16 okay so yes 23 is greater than 16. then because the array is sorted we immediately know that 2 5 8 12 16 is not containing the 23 so we will remove these things okay we will remove this okay and then we will check for another half okay so you

see how much like a element we have removed and how much we have time we have removed time cut down, we update so now it will check again, it will divide for the middle I can see the middle one is 38 and it will compare again, 23 is greater than or like a smaller than 38 which will say yes, then it will remove this half, okay, this half and we find the element, okay, 23. So, for this, we will take like a three elements like a low, mid and high, okay, which we'll check and we will mid the half using low and high, that's how we will go to the mid element and then we will proceed. So, it's a very simple quote. I will show you binary search which we required array and one target and we are considering low as a 0 high as length of array minus 1 while low is less than high. means it is not swapped ok, we will find the made 2 plus y divided by 2 ok, then I will check if area of a made is equal to first two packet, then simply return that

return what? return the index number return index number, return made means return index number. Return array of mid means return that element. Then, else if array of mid is less than the target, is it the case? Okay. Then, return or like a you can say like a low equals to mid plus 1. Then, else i equals to right minus one okay found anything okay we will simple return minus one because element is not there in that case otherwise we will found so this is the port you can try to run it by yourself not with you and yeah sending it out in this binary search for two people hello amir do you have any doubt or make sense to be not there hello Bhishatli do you have any doubt it says also not there is it like ok you can if you cannot able to speak you can let it paste at least your doubt in this chat box I will go through ok so how do you find the subarray how to find the subarray which total is 6 other than the concepts seems to be

okay can we can we end the class then I have a question actually regarding one of the assignment for the lab yeah okay so for last lab I was unable to complete because of my family like medical emergency so will it be possible to complete this week as well I have checked that the link is working fine so can I submit in this week yeah sure yeah okay thank you thank you okay thank you guys sorry I forgot to paste the Portland link by the way thank you Bernard Lee okay here is your Portland link and if you raised your hand again okay I already unmuted you I think so let's take Thank you, Suryans. Thank you, Krishna. Thank you, Dhanush. Thank you, Alavia. Thank you, Leon.

