[00:00:00] 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. [00:00:29] Banner is not saying both you guys are coming from computer science.com. [00:01:01] You are referring to the trends like what trends are going on in the idea of those [00:01:07] and you are being able to cope with that you know saving my screen first so yeah much should happen [00:01:35] but the file itself is more ridiculous right so i'll explain again okay that this is the easier [00:01:44] one okay you can able to get it and we'll move to the next weekly okay we'll not spend here okay [00:02:06] yes so what happened in a more short i'll take one example as [00:02:22] 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, [00:03:02] I also written the [00:03:04] like format you can see [00:03:06] so you will divide the [00:03:10] array into two halves [00:03:11] then you will recursively sort both of the [00:03:14] halves going to [00:03:16] first the left side [00:03:18] and then the right side [00:03:19] then [00:03:21] you will merge [00:03:23] you will follow the merge function [00:03:26] which is taking only the [00:03:28] left side and the right side [00:03:29] so before you see I will switch [00:03:31] yeah [00:03:34] so before you say [00:03:37] we are taking some mid values [00:03:38] then [00:03:39] array [00:03:42] left hash [00:03:43] we are not going into that [00:03:47] this is a simple [00:03:48] word [00:03:49] taking only this left value [00:03:56] right value and merging that [00:03:57] and then condition is same [00:04:01] condition was the same [00:04:02] so [00:04:03] and if there is any [00:04:05] left over values or left over [00:04:07] add-ins [00:04:08] result [00:04:11] like we have been in the result [00:04:13] hey I didn't [00:04:15] explain [00:04:16] how you brought that out [00:04:19] ok no worries [00:04:22] what's the doubt [00:04:26] started the recording that's the doubt [00:04:34] it's not doubt [00:04:35] yeah [00:04:38] I'll start the recording [00:04:41] thanks [00:04:42] thank you [00:04:43] recording is started [00:04:56] so we have [00:05:05] similarly I will go to one example [00:05:07] here it is written also [00:05:12] I will take this one on you [00:05:14] so [00:05:20] what is happening here [00:05:22] so first of all we are [00:05:24] like we are calling this function [00:05:26] by passing this array [00:05:27] 1, 2, 3, 6, 7, 8 [00:05:30] create elements are there. Okay. We are passing this error [00:05:34] into this function. [00:05:39] Function call is happening. So, I will call [00:05:42] this function. So, something like this. Okay. [00:05:49] And [00:05:50] this paste. Okay. Then, what's the length [00:06:01] of gate? Okay. So, in this function [00:06:06] what is written if the length of the array is less than 1 [00:06:12] which is what okay which is coming to the 8 [00:06:16] so it will not go to this function okay then coming to [00:06:21] this okay it equals to length of the array [00:06:24] divided by 2 so in the python we don't write just [00:06:29] divided by this okay next last line we write [00:06:33] in this manner okay so divided by [00:06:37] 2, which is coming to 4, okay, and then [00:06:41] left equals to, okay, let me show you, what is this? [00:06:45] If you are a new guy, [00:06:48] so this is the start, this is the [00:06:54] end, you can say, okay, in between that, [00:07:00] okay, let me go to this first, okay, let me not confuse you, [00:07:04] so this is the start, and this is the end, okay, [00:07:08] so this is means that okay so column means you are starting from zero going to till mid which [00:07:17] is four okay four is coming as a mid so means zero one two three four okay then in the left [00:07:24] side we are dividing this right side we are dividing this mid to the till last okay if we [00:07:31] are not giving any values in the starting or ending it will go till the last it will start [00:07:37] from the first okay hope you got it another thing is that okay if you're writing in this [00:07:46] man step okay step means it will uh simply like skip the values okay skip one values [00:07:58] and it will go to another value like you can see okay so like example they found [00:08:05] 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 [00:08:18] start from the 0 okay let's say we are starting from the 0 and going till the end correct so what [00:08:23] step value will give it 1 okay so it will point out to 0 okay so for the pointing out how i can [00:08:33] point. So, it will, okay, I am giving [00:08:35] the point. It will skip [00:08:37] this value 1. [00:08:38] It will go to the 2. [00:08:41] It will skip [00:08:42] next value. Okay. [00:08:45] So, if you want to [00:08:47] got the result, you will get only 0 and [00:08:49] 2. Okay. Got it? [00:08:51] So, this is how [00:08:52] this will work. We are just [00:08:55] giving starting and ending [00:08:56] not step [00:08:59] value. Okay. [00:09:03] This just means this [00:09:04] okay so i have mid value equals to 4 we are getting and then left equals to we are starting [00:09:14] from the 0 until 4 right side equals to starting from the mid going till last 2 okay if it is [00:09:26] then how we are dividing okay so this is an array okay we are containing array in that array what [00:09:34] we are containing? This number of index. Okay. This you can consider as an index. Okay. [00:09:39] Zero to four. Okay. What does it mean? It means, okay. Sorry. In the left side, what [00:09:46] I am containing? 10, 7, 8, 9. Okay. In the right side, 1, 5, 3, 2. Okay. For the simplicity [00:10:01] only i have taken eight values okay i can take uh all number of values you can you can take that [00:10:07] and you can write out okay so now it is divided into two halves okay now we will go to the next [00:10:13] one okay so what is this this function will call i am simply copying this state here this function [00:10:23] will come first left part we have to divide okay so dividing the left part okay so what [00:10:34] left and all the okay it will again take the length okay what's the length four okay four [00:10:41] is the length four is less than one okay four is less than then it will skip that okay then it [00:10:46] will go to the dividing part. [00:10:49] It made, when it was 2, okay, how it came to 2, 4 divided by 2, which is 2, okay, how [00:10:57] it will divide, then 7, 8, so I will write in this manner only, left side, right side, [00:11:09] 9 [00:11:12] then [00:11:14] I don't need to debug, sorry [00:11:18] then the left part over here, right part over here [00:11:23] then again we will call this function [00:11:25] ok [00:11:26] copy paste [00:11:28] again it will call this function [00:11:31] ok, so this is what we are calling [00:11:33] recursively calling this function [00:11:35] left, left, left [00:11:36] ok, then it will return [00:11:38] it will, ok, so what is the base condition [00:11:40] this one [00:11:41] this one is the base condition [00:11:43] ok, so it will return from here [00:11:45] when it will return [00:11:46] then the length of the array is [00:11:48] less than or 1. [00:11:51] Okay. It will return the array. [00:11:53] Correct. [00:11:54] It will return to whom? It will return [00:11:56] to merge out only [00:11:58] to this function. Then [00:12:00] after ending index function, [00:12:02] it will call to this one. [00:12:04] Then right part will be divided. [00:12:07] After everything is [00:12:08] divided, then we will go to the [00:12:10] merge function. [00:12:12] So, I am quickly doing this. [00:12:16] first word only. So, what's the length of the array? Which is 2. 2 is less than equals [00:12:21] to 1. Yes, it will not go to that condition and it will go to mid. So, mid equals to 2 [00:12:30] divided by 1, which is, it will divide the left one again. So, what is the left? 10. [00:12:37] What is the right? 7. Okay, we go. Now, it will go to the condition. Okay, what's the [00:12:47] condition uh what's the condition if the length of the array okay okay again it will call to this [00:12:55] function okay correct you can you can call to this function in the left side it will pass [00:13:01] only the 10 okay which is length of the array is 1 1 1 is less than equals to 1 so it will return [00:13:07] return to much okay now when it will return to much okay much short so length of the 10 is 1 [00:13:18] 1 is less than 1 so it will return return the array okay so we are returning the right see here [00:13:26] we are returning the array okay we return that now it will go to the right side part right [00:13:37] right side part so when it will return to that okay now it is recursively calling now it was [00:13:44] recursively calling so when it will return to this okay now this is completed okay [00:13:50] this is completed now it will start will start okay when it will start i will copy this [00:14:00] okay taste it here now in the right side what is in the right side we have only 7 okay so we have [00:14:10] only um 7 correct so in the 7 again it will go okay so length of the error is 1 correct why it [00:14:20] 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 [00:14:27] go to the, again return, okay. Then it [00:14:31] will return, okay. Why it is returning, okay, for this simplicity [00:14:35] I am telling, why it is returning? When it is going to this [00:14:39] function, it will try to recursively call this function. [00:14:43] See the name, must shout only, see the name, must shout, okay. [00:14:46] It will try to recursively call. When it will try to recursively call, there should be [00:14:51] a base condition to complete that, okay, recursiveness. [00:14:55] So, for that, we are writing this base condition. [00:15:00] Okay. [00:15:01] What the completion is. [00:15:03] Okay. [00:15:04] So, when it will come to this, it will say, 7 is there. [00:15:10] 7 is there, which is length is 1 only. [00:15:12] 1 is less than 1. [00:15:13] I will return this array. [00:15:15] So, this array will return. [00:15:17] Okay. [00:15:17] In the right side, we have only the 7. [00:15:20] In the left side, we only have the 10. [00:15:23] Okay. [00:15:23] correct and it is returned okay now i will write here it is also one minute because [00:15:33] okay so it will return okay now it will go to the in the right side we know that [00:15:50] we have 7 in the left side we knew that we have 10 okay now it will go to another function which [00:16:03] is merge merge of a i given only the left and right correct so left and right correct [00:16:13] then what it will pass only the array will pass right so we will shortly look what is there in [00:16:26] the left sorry what is there in the merge function so now we know that what does function these two [00:16:32] dividing only right so it is merging so merge means merging merging the both array so how it [00:16:38] is merging it is starting from index i equals to 0 j equals to 0 so there is a result array also [00:16:44] which is containing the result after sorting okay then it is comparing both of the left and right [00:16:50] okay so uh it is comparing the i okay so we are writing in a while function uh also previously [00:16:58] i told that we can also write in a manner of a for loop okay uh so yeah so it is first checking [00:17:07] the length okay so if it is not satisfying then it will not yeah so yeah so if we write in the [00:17:18] follow loop then what will happen we have to write an extra if condition right so we'll go to till [00:17:25] that right although like if we have to write one if condition if it is checking the length of the [00:17:31] array is satisfying then only you go to this so we'll quickly start to not take the time okay so [00:17:39] there is some result function okay and then i equals to starting from zero j equals to starting [00:17:47] from 0, left side containing, again [00:17:51] for the remindedness, left side containing [00:17:54] 10, right side containing [00:17:58] 7, which is both of the length is 1, [00:18:02] okay, while i is [00:18:06] less than length of left [00:18:10] and j is less than length of [00:18:14] 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? [00:18:40] these two functions will be satisfied. [00:18:44] It will not go for the next check. [00:18:46] If one condition fails, [00:18:48] and one condition passed, [00:18:50] then what happens? [00:18:51] If one condition fails, [00:18:53] in the end case, [00:18:55] it will not go for the next check. [00:18:59] If one condition fails, [00:19:01] then it will not check. [00:19:06] 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. [00:19:30] 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. [00:19:41] 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. [00:19:55] then storing it in a result area [00:19:58] see [00:20:00] storing it in a result area [00:20:01] so [00:20:03] what it is checking is [00:20:06] the left of i [00:20:06] left of i [00:20:10] is [00:20:11] less than [00:20:13] right of i [00:20:15] which is not [00:20:17] 10 is less than 7 [00:20:21] which is not which is false [00:20:23] therefore [00:20:25] okay therefore it will not go to it will not go to this one okay else what it [00:20:34] will do this it will do it will go to the result.append right of a j okay right [00:20:47] of a j is what okay in result we store 7 store the right we have a 7 [00:20:54] 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 [00:21:14] plus 1 0 plus 1 which is 1 okay it will check also this one okay add the remaining element [00:21:36] 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. [00:21:58] okay and i will i is less than length of uh which is zero is less than one add 10 okay [00:22:15] in the result array it will say here 7.10 okay what append means append means it will [00:22:25] add into the left uh add into the last of the array okay append means last may add [00:22:31] and let us take it so now the it will return the function okay much short it will return [00:22:48] it will return okay return this from j return 7 comma 10 okay correct now okay likewise like [00:23:25] it will call much short [00:23:29] much short of [00:23:32] 8 and 9 [00:23:34] it will come [00:23:35] and then it will say like [00:23:38] it is already [00:23:41] divided right so [00:23:42] it will go directly [00:23:45] to this one okay [00:23:46] left and the right [00:23:49] okay it will again [00:23:51] recursively call 8 and 9 [00:23:53] okay then it will go to [00:23:55] again 9 and 8 [00:23:57] okay, it will compare [00:23:59] and then it will [00:24:02] merge, okay, got my [00:24:07] point, like you got the point, right [00:24:09] so, okay, [00:24:13] let me see [00:24:14] in the second part, so this is the [00:24:17] first pass, okay, we [00:24:19] got one function, okay [00:24:21] let me [00:24:24] see the second one, 8 [00:24:25] and 9, okay [00:24:27] so, what I am assuming [00:24:29] is okay it is returning okay it will comparing and it is uh returning 8 and 9 okay i'm not [00:24:38] repeating into that now coming to main part okay now coming to main part is 7 and 10 which will [00:24:48] merge okay and then in the left side we have a 7 and 10 in the right side we have a [00:24:55] no no no [00:25:01] we will merge both of this [00:25:03] so now we are [00:25:08] returning much short of [00:25:09] much short of [00:25:15] 10 7 [00:25:16] 8 9 [00:25:19] correct [00:25:19] at this point [00:25:21] we have a left [00:25:23] 7,10 [00:25:27] and [00:25:29] it is only returning the human [00:25:37] right okay [00:25:38] so [00:25:40] in the left we have a 7.10 [00:25:42] in the right we have a 8.9 [00:25:44] okay [00:25:44] and then we will [00:25:47] go to 7.10 [00:25:56] 8.9 [00:25:59] okay [00:26:00] so if we will [00:26:02] execute this okay [00:26:04] so if we go to the left [00:26:07] okay so [00:26:08] we need to take that again [00:26:11] clean [00:26:12] okay [00:26:14] and again we will see [00:26:16] i goes to 0 [00:26:18] j goes to 0 [00:26:20] okay [00:26:21] and then [00:26:23] one result array is there [00:26:24] okay [00:26:25] result array is there [00:26:28] now it will compare [00:26:30] okay [00:26:31] left of i [00:26:33] okay [00:26:34] so both it will check the [00:26:36] both it will check the length of the array [00:26:39] okay [00:26:39] I am assuming that [00:26:41] it will go to the while loop [00:26:43] okay [00:26:43] then I am telling [00:26:44] okay [00:26:45] left of i [00:26:47] okay [00:26:48] which is 7 okay and then right of j see in the if condition what it is checking [00:26:59] in the if condition what it is checking left of i with right of j correct so that's i'm checking [00:27:07] 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 [00:27:17] 8 of j means 8. [00:27:19] Okay, it will check. [00:27:21] If 7 is less than 8, [00:27:23] it will say 2. [00:27:26] Okay, then add 7. [00:27:29] Okay, in the result error, [00:27:31] we have a 7. [00:27:41] Result error, we have a 7. [00:27:44] Then move the i to, [00:27:46] move the i to, i plus 1. [00:27:52] i plus 1. [00:27:54] i equals to 0. [00:27:56] Sorry, i equals to 1. [00:27:58] j equals to 0. [00:28:00] 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. [00:28:17] and then [00:28:21] left of 5 is 10 [00:28:22] right of j [00:28:25] will be 8 [00:28:29] ok then [00:28:32] we will check if 10 is [00:28:35] less than 8 [00:28:35] it is now to be false [00:28:38] in the false condition what is happening [00:28:41] we are adding the [00:28:42] we are adding the [00:28:45] right values [00:28:47] in the else condition [00:28:49] correct [00:28:51] So, it will add the, so, it will add the right one, correct, add 8, the result, the result [00:29:07] we have 7, 8, okay, then move j to j2, j plus 1, which is i plus 1, j plus 1, so, it [00:29:25] will again check the length okay so is it satisfying the length yes it is satisfying [00:29:31] the length then it will go to again left of i equals to i am not checking the while condition [00:29:39] again again okay you can check that left of i okay so what is the left of i testing here [00:29:53] 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. [00:30:33] result equals to [00:30:35] 7,8,9 [00:30:37] ok [00:30:38] we have a 7,8,9 [00:30:41] now [00:30:43] we will move [00:30:45] j to [00:30:46] j plus 1 [00:30:49] ok [00:30:50] so now it will check [00:30:54] j to j plus 1 means [00:30:57] i equals to 1 [00:30:58] j equals to 2 [00:31:00] now condition will fail [00:31:02] now right side is finished [00:31:05] right [00:31:05] so [00:31:06] right side is finished [00:31:11] and the length of [00:31:12] right is supposed to 2 [00:31:16] ok so when it will check the condition [00:31:20] j is less than length of [00:31:22] right [00:31:23] ok so first condition will pass [00:31:26] ok so where is the condition [00:31:28] so [00:31:40] what is 1 [00:31:43] so i is equals to 1 [00:31:46] and length of the left [00:31:49] length of the left is 2 [00:31:51] ok [00:31:52] so this is passing [00:31:54] ok this is 2 [00:31:56] now it is failing [00:31:57] 2 ok [00:31:59] is less than 2 [00:32:01] because length of the right is 2 [00:32:03] correct [00:32:03] and then [00:32:05] what happened [00:32:08] so it will not go to [00:32:10] the function [00:32:12] ok it will not go to the value [00:32:14] now what will happen [00:32:16] so [00:32:17] is false, then it will [00:32:20] go to the remaining element row. [00:32:23] So, [00:32:24] it will go to [00:32:25] this one. [00:32:33] So, it will check for while i is [00:32:37] length of left. [00:32:41] It will say [00:32:42] yes. [00:32:43] So, it will not go to this. [00:32:46] Even if it will go to [00:32:47] this, it is failing. [00:32:50] So, I am writing [00:32:51] this because of adding the [00:32:53] leftover element. What is the leftover element is [00:32:55] this? 10. [00:32:57] In the result array, we didn't add [00:32:59] the 10, right? [00:33:01] So, that's why [00:33:02] I am going to leftover [00:33:07] element. [00:33:09] So, while i is less than left, [00:33:11] length of the left, result [00:33:13] dot append, left of i. [00:33:16] So, left of i is [00:33:17] 10. So, in the result [00:33:19] array, it will append [00:33:21] the 10, which is [00:33:23] now 7, 8, 9, 10 and then i is equals [00:33:27] to i plus 1. Now, both of the conditions will [00:33:31] fail here, here and here. [00:33:36] Now, it will return the result. [00:33:39] It will return the result to this. [00:33:44] So, this is how 7, 8, 9, 10 will be [00:33:47] now the left side is sorted. [00:33:51] Okay, now we will go for the right hand. [00:33:54] So, it will sort like this, correct? [00:33:57] So, this is how [00:33:58] Meshrot will work, correct? [00:34:00] Got the point? [00:34:04] You don't have any doubts? [00:34:06] Okay. [00:34:09] Now, [00:34:12] Vikesh Pumarthivari [00:34:13] Hi, Vikesh. [00:34:28] Yeah, hi, Adita. [00:34:30] Thanks. [00:34:30] Thanks for [00:34:31] the explanation. [00:34:34] Actually, I had a doubt [00:34:36] when we check the condition [00:34:38] in merge sort function [00:34:40] if you could go to merge sort [00:34:42] the first condition length of [00:34:46] array is less than equal to 1 [00:34:48] so you said that [00:34:50] since 1 is less than [00:34:52] equal to 1 [00:34:53] then it will return array [00:34:55] but it is not the case [00:34:57] 1 is less than equal to 1 [00:35:00] it's true [00:35:00] right [00:35:02] okay [00:35:06] okay okay okay i thought it's not equal to yeah it will get into this and return the array [00:35:13] my bad okay thanks thank you vikis so we will go to the quicksort so what is quicksort let me tell [00:35:42] you first i have already written because i don't want to waste the time in this so quicksort is [00:35:55] like here okay so don't go to this first so what is pivot and all don't want so i can write [00:36:07] quicksort is like so quicksort is a divide and conquer [00:36:14] just like [00:36:30] it is also dividing and conquering the piece [00:36:34] however there is a major difference [00:36:37] so more short is like [00:36:40] divide first [00:36:45] divide the array first into pieces [00:36:48] then sort [00:36:52] while merging [00:36:54] ok [00:36:54] so quicksort in hand [00:36:59] is like [00:37:04] it will place a pivot [00:37:07] it will come to the point [00:37:09] what is pivot [00:37:10] in its correct position first [00:37:14] then [00:37:22] recursively [00:37:28] then [00:37:32] recursively [00:37:36] sort [00:37:37] the elements [00:37:41] on its [00:37:44] left and [00:37:45] right. I'll take that out on the [00:37:55] channel in the letter. [00:37:57] Thank you. So, [00:38:06] this is the difference. [00:38:08] So, what is the pivot? [00:38:10] Pivot means like a center [00:38:12] position, you can say. [00:38:17] So, here [00:38:18] the pivot is slow. [00:38:20] So, what happened? Actually, [00:38:22] I can take one example. [00:38:24] Let's say 8, 3, 5, 4, 7, 6, 1, 2. [00:38:31] Okay. [00:38:33] Something like that. [00:38:35] So, after some point, let's say I'm taking the pivot value as this. [00:38:43] Signing P. [00:38:44] Okay. [00:38:45] In the last point, I will take any L. [00:38:47] Okay. [00:38:49] Any of the pivot element. [00:38:51] So, first we will place the pivot element into its correct tool machine. [00:38:56] Okay. [00:38:57] 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. [00:39:23] This 3 is less than 2, no, passing, okay. [00:39:31] This 5 is less than 2, passing, 4, no, 7, no. [00:39:38] It will check with the pivot element, right? [00:39:40] Okay. [00:39:41] So, we are trying to placing the pivot element into its correct position first. [00:39:47] It will check with the 6, no, 1, yes. [00:39:52] Okay. [00:39:52] 1 is yes [00:40:00] ok [00:40:00] no [00:40:02] what it will do [00:40:04] it will replace [00:40:06] the first element [00:40:08] with [00:40:10] 0th one [00:40:14] what it [00:40:21] does is like [00:40:24] it just replaced [00:40:26] the first element [00:40:27] with the current one [00:40:30] which is lesser [00:40:31] ok [00:40:32] Okay. [00:40:33] Then what will happen? [00:40:35] It will go to its correct position. [00:40:39] How do I do? [00:40:41] It will simply [00:40:42] already replace. [00:40:44] Now it is replaced. [00:40:46] Plus 1. [00:40:46] Okay. [00:40:47] It will do them just like that. [00:40:49] Then what we will get? [00:40:50] 1, 2, 3, [00:40:52] 1, 2, [00:40:57] 5, 4, [00:40:59] 7, 6, [00:41:01] 8, [00:41:03] 3. [00:41:04] Now what will happen, if you see, which is pivot element, which is in this as a pivot element, right? [00:41:11] So, after the partition, after the first partition, okay, so this is the first partition, okay? [00:41:17] So, after the first partition, 2 is in its final sorted position, okay? [00:41:23] Everything to its left is more than, if you see, and everything to its right is larger. [00:41:29] So, the two sides are not necessarily sorted yet. [00:41:34] Okay, again I am saying, the two sides are not necessarily sorted. [00:41:39] If you see, this one is sorted, right? [00:41:41] So, because this is the first element. [00:41:44] If the pivot element, like some about here, [00:41:48] then it may, like, it is not sorted, it is also not sorted. [00:41:53] Something like that, I am taking the next. [00:41:55] Okay, then in the second part, also we will do like that. [00:41:59] Okay, so this will, again, go to choose the pivot element [00:42:03] from this side okay then it will uh choose this one is a pivot element okay so now this will [00:42:11] chosen as a pivot element as i'm taking uh the last element as a pivot element okay again and [00:42:17] again so that's why it will choose this as a pivot element now except okay so it will not compare [00:42:24] with this also okay so what we have chosen as a pivot element except this it will compare all of [00:42:31] this so accept this we will go until this okay so now it will again check okay which is smaller [00:42:40] okay so no one is smaller right so again for that also we have a condition okay [00:42:49] it will replace with the correct one okay so it will something like that so for that we will [00:42:58] try it on. Okay. So, this is the [00:42:59] philosophy what I am writing later. [00:43:02] So, choose the pivot element, put [00:43:03] this one, [00:43:06] everything with the [00:43:08] smaller, the left side, everything [00:43:09] bigger in the right side. [00:43:12] Quicksort the left side [00:43:13] first, then quicksort the right side [00:43:15] first. So, this is the philosophy of a [00:43:17] quicksort. [00:43:19] And this is the code. We will [00:43:21] go through this code. We will [00:43:23] try it on in this [00:43:24] one only. [00:43:35] we can take [00:43:39] we can take this [00:43:42] this will be easy [00:43:45] so [00:43:55] let's go to the code first [00:43:59] so what it is telling [00:44:02] ok [00:44:03] so first we are taking the array [00:44:06] then we are calling the function quicksort [00:44:08] ok [00:44:08] this is taking the array [00:44:10] and the 0th position [00:44:12] and the length of the array minus 1 [00:44:14] ok [00:44:15] so [00:44:16] we will go to the quicksort first [00:44:19] ok [00:44:19] we will go to the quicksort [00:44:26] this one [00:44:28] it is checking in the [00:44:30] base condition [00:44:31] in merge sort also we take in the [00:44:34] base condition as a [00:44:36] if length is [00:44:38] less than equals to 1 [00:44:39] it is also checking if low is [00:44:42] like [00:44:43] greater than high [00:44:45] why it is that [00:44:46] because it is checking [00:44:49] from both of the side, okay. [00:44:51] Now, if you will go to the [00:44:53] dry run, then you can understand also better. [00:44:55] Okay, it is checking from the both of the side. [00:44:58] If it is like a [00:44:59] swapped or something, okay. [00:45:01] Then, it will return, okay. [00:45:03] When low is something [00:45:05] as a large, okay. So, by the [00:45:07] way, what is low and high? [00:45:09] This is only an index, okay. [00:45:14] This is only the index, [00:45:15] correct? [00:45:17] This is not an array. [00:45:20] See, [00:45:21] Like a 0, length of array minus 1, taken, okay. [00:45:29] So, that's fine. [00:45:30] So, now, place the pivot in its current position, okay. [00:45:34] So, for that, one pivot index, okay, for the tracking, and then I am calling this function, [00:45:43] which is passing partition of array, comma, low, comma, tag, okay. [00:45:51] 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. [00:46:34] 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. [00:46:56] 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. [00:47:14] it's written also [00:47:59] like a boundary of a smaller advance [00:48:01] although I will explain [00:48:02] this is very important I represent that [00:48:04] the boundary of elements [00:48:06] that are smaller than [00:48:09] or equals to the pivot element [00:48:10] ok so initially there are [00:48:13] no such elements ok [00:48:14] which is smaller than or equals [00:48:17] to the pivot element ok [00:48:18] that's why I am assigning i equals [00:48:21] to minus 1 ok [00:48:22] so if you will see [00:48:24] 0, okay, it will come as a 0, okay, 0 minus 1, then it will assign as a minus 1, okay, [00:48:36] correct, so now it will go to the for loop, for j in a range of, okay, for j in a range [00:48:43] of a low, high, okay, and then it is checking with the pivot element, as I said, it will [00:48:51] check recursively with the pivot [00:48:53] element. If it is [00:48:55] low, then it will go to the i plus [00:48:57] 1, okay. [00:48:58] Means we have found the first element as a [00:49:01] something lower, okay. [00:49:03] So, until that, we have [00:49:05] we don't have any lower element than [00:49:06] pivot, right? So, we have found [00:49:09] first element, okay. So, [00:49:11] it will take [00:49:12] i plus 1, okay. [00:49:15] So, which is [00:49:16] minus 1 plus 1, which is 0. [00:49:19] We will both look at [00:49:20] No worries. [00:49:23] So, for i in a range of [00:49:28] low, high [00:49:31] low is equals to 0 [00:49:34] high equals to 7 [00:49:36] so j is going to 0, 1, 2, 3, 4 [00:49:41] 5, 6, 7 [00:49:44] 6 up to 6 it will go. [00:49:47] So, high is 7, right? [00:49:49] So, for i in a range [00:49:51] range means 0 to 6 it will go [00:49:53] ok it will not going to check [00:49:55] the last one because last one is our pivot element [00:49:58] right [00:49:58] then [00:50:01] array of [00:50:03] array of a j [00:50:06] it will check [00:50:07] array of a j [00:50:10] which is 8 [00:50:12] and pivot [00:50:15] is 2 [00:50:15] so array of a j [00:50:18] we will check [00:50:20] with pivot [00:50:22] element [00:50:23] which is [00:50:27] 8 is [00:50:28] less than 2 [00:50:30] which is not [00:50:32] so [00:50:34] it will come as a false [00:50:36] then again [00:50:38] it will check 2j equals to 1 [00:50:40] then it will go j equals to 1 [00:50:42] in the j [00:50:44] what do we have? [00:50:46] I am not checking one by one [00:50:48] like 3, 5 [00:50:51] it will go, then come into the 1. [00:50:53] So, now I am going [00:50:55] to 1. [00:50:59] Okay. [00:51:01] So, [00:51:03] it will check [00:51:04] continuously [00:51:05] till [00:51:08] it form [00:51:09] smaller [00:51:11] element [00:51:15] and pivot. [00:51:20] Okay. [00:51:23] Small element and pivot. [00:51:25] It is less than 2. [00:51:36] Okay. [00:51:36] Then, i equals to i plus 1. [00:51:41] i is currently minus 1. [00:51:44] So, i will become 0. [00:51:52] Okay. [00:51:53] i will become 0. [00:51:55] Then, what it is doing? [00:51:58] Swapping. [00:51:58] As I said, okay. [00:51:59] It is swapping the values with the first element. [00:52:06] Okay. [00:52:07] So, what is the array of a 0? [00:52:10] What is the array of a 0? [00:52:13] 8. [00:52:14] okay so this is the way of writing to swap the element okay so we are not going for the c and c [00:52:20] plus plus profile we have to pick the third element and we have to write okay or we are not [00:52:27] going for the plus and minus to swap the values there is a leverage in python or you can like [00:52:33] writing this manner so it will swap so it will swap with [00:52:39] So, let me write it [00:52:43] And then [00:52:50] Array of a 6 [00:52:51] What does it mean? [00:52:54] I will show you that [00:52:55] Also [00:52:58] It means that [00:53:01] Array of a 0 will swap with [00:53:04] Array of a 6 [00:53:05] Array of a 6 will swap with [00:53:08] Array of a 0 [00:53:09] Means 8 will [00:53:13] swap with [00:53:16] something like that [00:53:19] with 1. [00:53:22] So, [00:53:23] array will be [00:53:25] 1, 3, [00:53:36] 5, 4, [00:53:38] 7, 6, [00:53:41] 8, 2. [00:53:43] Okay. [00:53:47] After swapping, what happened? [00:53:49] Place the pivot in its correct position, [00:53:52] which is this one. [00:53:53] I told right [00:53:54] it will place the pivot element also [00:53:57] so array of i plus 1 [00:53:59] ok [00:53:59] so [00:54:01] now [00:54:04] it will not go to the last element [00:54:09] and it will check the i first of 0 [00:54:11] so now i first of 0 [00:54:13] i [00:54:15] i plus 1 means [00:54:17] 0 plus 1 [00:54:18] means array of a 1 [00:54:20] and then [00:54:23] array of a height. What we have taken as a height? [00:54:27] 7, right? Then [00:54:31] 7 will replace with [00:54:33] array of a 1, okay? Which 2 will swap? [00:54:40] 3 will swap with [00:54:41] 3 will swap with 2, okay? [00:54:49] 3 will swap with 2. So, [00:54:52] array will become 1, 2, [00:54:55] 5, 4, [00:54:58] 7, 6, [00:55:01] 8, 3. [00:55:03] Okay. [00:55:06] Now, what happened? [00:55:10] Return i plus 1. [00:55:11] Okay. [00:55:13] So, now i was 0. [00:55:16] Okay. [00:55:17] So, now i will become [00:55:18] return 1. [00:55:24] Okay. [00:55:28] Return 0 plus 1. [00:55:30] Correct. [00:55:31] So, therefore, [00:55:35] what it is returning to? [00:55:36] it is returning to [00:55:39] pivot index. [00:55:41] Where we are coming from? [00:55:43] We are coming from this. [00:55:45] We are coming from this. [00:55:47] It is returning [00:55:49] to this one. [00:55:52] Partition. [00:55:54] So, now [00:55:55] what it will get? [00:55:57] 1. It means [00:55:58] our pivot index is [00:56:01] now 1. [00:56:04] You got the point? [00:56:06] How it is 1? [00:56:07] See here. [00:56:09] We have taken this as a pivot element, right? [00:56:12] So now, what is the index? [00:56:14] 1. [00:56:15] So it is returning 0 plus 1. [00:56:17] So 1. [00:56:18] Okay. [00:56:19] Why it is returning? [00:56:20] Why we are calculating the pivot? [00:56:29] Sort of array, flow, pivot index minus 1, pivot index plus 1. [00:56:35] So if you will see here, we are taking the low and high. [00:56:40] Okay. [00:56:40] First of all. [00:56:41] 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. [00:56:56] 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? [00:57:09] after the update [00:57:10] of this one [00:57:12] so [00:57:14] we are sorting the left side first [00:57:16] right [00:57:17] 2 [00:57:19] 3 [00:57:27] 4 [00:57:28] 5 [00:57:29] 6 [00:57:31] 7 [00:57:32] ok [00:57:32] so [00:57:33] we are sorting the [00:57:34] left side first [00:57:36] ok [00:57:36] so what is the left side code [00:57:38] this one [00:57:40] ok [00:57:41] I will write here [00:57:48] here why we can if i can't just go to here and write and see will not do mess up here [00:57:57] okay so this one okay so after that after returning from the pivot index [00:58:03] so what is our lows we are passing the array as a result this update uh a decade okay [00:58:10] what we have in the left side low what is low index number so index number is zero [00:58:17] so this is the left side okay and this is the right side okay so so this is the zero [00:58:32] pivot index minus one what is the pivot index one okay for now it is one minus one which is [00:58:42] coming out to be zero okay when it will coming out to be zero so r what is low and high low [00:58:50] and high is this one only correct so when it is going to so yeah so i'll write here again [00:58:58] 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 [00:59:07] manner don't it so yeah zero and a high okay so now it will check the if low is if low is [00:59:19] greater than high. So, it will tell 0 is less than 0. Then, please return to your function. [00:59:31] So, this is the base condition. It will come again. It will come to this one. It will come [00:59:37] to this one. It is completed. It means completed. When it will return to this, this will complete [00:59:48] it. Okay, now it will go to the right side. [00:59:50] Okay, so I'll [00:59:51] Varun Kumar, I'll take that out. [00:59:54] Okay, no worries. [00:59:57] Let me [00:59:57] understand you. Okay, and I'll [01:00:00] take the, this is the right side part. Okay, [01:00:01] I'll write, I'll [01:00:03] write here also mentioning this is the [01:00:06] left side. [01:00:07] Okay, we are sorting [01:00:09] and this is the right side. [01:00:13] Again, [01:00:14] I will write this. Okay, [01:00:16] on the downside, [01:00:18] okay. Now, this is the a we are passing, then pivot index plus 1, okay. So, what is the pivot [01:00:28] index? 1 plus 1, which is 2. So, this function is telling you start from pivot index plus 1, [01:00:39] okay. Then, what is the high? What is the high value? Till the last, right, which is last 7, [01:00:48] correct [01:00:52] so now it will check [01:00:56] if [01:00:57] low is [01:01:00] greater than high [01:01:01] it will say no [01:01:03] if it is not greater than high [01:01:05] you go and check [01:01:07] you go and place [01:01:09] go and place [01:01:12] your pivot [01:01:14] in correct [01:01:15] position [01:01:17] and [01:01:19] after [01:01:21] send it 10th [01:01:28] right position [01:01:30] please [01:01:32] give me the [01:01:34] correct [01:01:36] index [01:01:37] so that [01:01:39] I will [01:01:41] execute [01:01:43] so now it will go to again [01:01:54] it will check [01:01:56] can I show another pass also [01:01:59] by partitioning [01:02:01] or it is not required [01:02:02] what do we have a time [01:02:05] we have a 12 right [01:02:06] pattern and [01:02:08] pattern is easy, binary also is easy [01:02:10] I can show you another class okay [01:02:12] so yeah [01:02:13] now it will pass [01:02:19] quick sort of [01:02:25] array 2,7 [01:02:29] okay [01:02:30] array 2,7 [01:02:32] and then [01:02:37] so yeah in the partition what we have the code [01:02:40] we have the code of a [01:02:43] pivot okay [01:02:45] pivot of [01:02:46] okay [01:02:46] as we [01:02:47] are taking [01:02:48] the pivot [01:02:49] element [01:02:49] is high [01:02:50] then we [01:02:51] don't know [01:02:52] what's the [01:02:53] we didn't [01:02:54] got any [01:02:55] smaller element [01:02:56] so that's [01:02:56] why we are [01:02:57] taking low [01:02:57] minus 1 [01:02:58] okay [01:02:59] so let's [01:03:01] load things [01:03:02] so [01:03:03] it's a low [01:03:06] minus 1 [01:03:08] so what is [01:03:08] the low [01:03:09] okay [01:03:11] so 2 [01:03:11] minus 1 [01:03:12] okay [01:03:13] which is [01:03:13] 1 [01:03:14] and then [01:03:18] what is the [01:03:19] pivot element [01:03:20] array of a high. [01:03:23] So, I will write here [01:03:24] in the mat [01:03:26] which is to array of a [01:03:27] high. [01:03:29] Array of a high means [01:03:30] array of a 7 which is [01:03:32] equals to [01:03:33] right here also [01:03:36] array [01:03:41] gap. So, [01:03:46] then [01:03:46] 4j in a range. [01:03:51] Okay, 4j in a range [01:03:52] 4j in a range [01:03:54] go to [01:03:57] 2 to 6, okay [01:03:59] it will not check for the last element [01:04:02] because last element is our pivot element [01:04:04] it will not check, okay [01:04:06] there is no [01:04:08] point, then go to the second [01:04:10] partition, okay, so j equals to [01:04:12] 2, j equals to 2 [01:04:17] and then it will check [01:04:19] like an array of a 2 [01:04:20] array of a 2 is [01:04:23] 5 [01:04:24] 5 is less than 3 [01:04:30] it will say false [01:04:32] ok now it shows [01:04:34] what's the next error [01:04:36] I'll paste the [01:04:38] updated error here [01:04:40] so that I can also able to [01:04:42] then it will [01:04:47] go to the 4 [01:04:48] 4 is less than [01:04:52] 3 [01:04:52] it will say false [01:04:54] loss name [01:04:55] then it will go to [01:05:02] 7, ok, false [01:05:08] then it will go to 6, false [01:05:12] then it will go to 8 [01:05:17] which is false, so we didn't found any of the [01:05:26] case, ok, so it will not [01:05:30] execute, yeah, write for [01:05:37] it will not execute [01:05:43] this one [01:05:45] and also this one [01:05:47] it will not serve [01:05:49] but we will go for [01:05:50] placing the pivot elements to it [01:05:53] correct position [01:05:54] it will go to this [01:05:57] so what is [01:06:00] area of i now [01:06:01] is 1 [01:06:03] i will write here [01:06:07] i is now 1 [01:06:08] area of i plus 1 is [01:06:11] 1 plus 1 [01:06:13] area of i [01:06:16] 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? [01:06:42] So, 5 will swap with 3. [01:06:52] So, it means, okay, 5, 3 equals to 3, 5. [01:07:07] Okay. [01:07:08] So, 5 will swap with 3. [01:07:12] So, array will become, what was the array? [01:07:16] Okay. [01:07:20] Okay, so, array will become 1, 2, 3, 4, 7, 6, 8, return i plus 1, okay, 1, return 2. [01:07:57] So, now, we got the pivot index as 2, okay, which means our pivot element is this one, okay, pivot element is this one. [01:08:13] So, again, it is not necessary that [01:08:15] we go to this, okay. [01:08:20] It's not necessary that [01:08:21] it's sorted, it's also sorted. [01:08:25] Then it will go in recursively, recurs again, okay. [01:08:29] So, it will call the left-hand side first, [01:08:33] which will pass a quick sort of array, [01:08:36] array of a low, high, which is 2, 1, okay. [01:08:42] then it will check for the left side like 2 is greater than 1 right so so it will check here [01:08:56] so it will check here like 2 is greater than 1 then it will finish then it will go to the [01:09:03] three two seven so zero one two three so three two seven it will go in and it will check [01:09:12] 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. [01:09:42] So, this is how it will work, okay, so it's not necessary, again, you have to take the [01:09:57] pivot as a first element, last element, you can take as a first element or any element. [01:10:02] Hi, Subrat, you have any doubt? I think Subrat is not. Harun Kumar Agarwal, you have any [01:10:33] haven't it out raised your hand not exactly doubt sir i want to see the last part of your code where [01:10:41] you were changing the pivot index and that part can you show again that part sure sure uh better [01:10:47] i will paste the uh like a totally link okay although i'll paste okay so which part taking [01:10:55] the pivot element right yeah so i understand all the logic what i'm trying to understand is why [01:11:02] we are in changing the pivot index [01:11:05] at the very last [01:11:09] after the return you do [01:11:10] yes you [01:11:12] returning this pi plus 1 [01:11:14] which is assigned to which one to what [01:11:17] with the [01:11:19] pivot index [01:11:20] so [01:11:22] pivot index it is returning the [01:11:25] pivot index only okay [01:11:26] so why we need [01:11:29] to do maintain the pivot index [01:11:31] variable sir it's because [01:11:32] so because we have to do [01:11:35] accordingly okay then we will [01:11:37] get the pivot index here okay [01:11:39] so we have to [01:11:41] sort the left side and we have to [01:11:43] sort the right side according so that's why [01:11:45] we need pivot index [01:11:46] okay you got it I missed this [01:11:49] I thought we have two different variables [01:11:51] okay clear sir [01:11:52] so there are two different functions also if you see [01:11:55] one is a partition [01:11:56] and another one is for the [01:11:58] okay [01:12:00] yeah okay clear sir [01:12:01] Thank you, Varun. [01:12:07] You, Subrat, come back. [01:12:11] Hi, Subrat. [01:12:17] Are you allowed to mic and unmute and speak? [01:12:29] I think it's not there, otherwise [01:12:30] I don't know what is happening. [01:12:34] Okay, so [01:12:38] quick sort is [01:12:40] clear to you guys, right? [01:12:43] So, [01:12:44] that's the question only. [01:12:46] If you really [01:12:48] go here, okay. [01:12:53] So, yeah. [01:12:54] So, these are the test [01:12:56] cases. [01:12:58] These are [01:12:58] you can complete. [01:13:03] So, [01:13:04] we will go to [01:13:05] we will go to the [01:13:08] maximum [01:13:10] sub-array [01:13:15] sum. [01:13:17] So, this is the simple [01:13:24] portion, maximum sub-array sum [01:13:26] which is [01:13:28] developed by [01:13:30] cadans. [01:13:32] 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, [01:14:02] So, this is the simple one. [01:14:08] See, [01:14:09] which is also [01:14:16] the correct one. [01:14:18] So, let's [01:14:23] take it. [01:14:24] I'm taking like it, including [01:14:27] positive, this negative one, right? [01:14:46] So, [01:14:48] sample, okay. [01:14:50] So, we have [01:14:52] to find the maximum sum [01:14:53] by anything, okay? [01:14:56] so first group force approach [01:14:59] what we will do [01:14:59] we will maintain one [01:15:00] result array [01:15:01] and we will maintain [01:15:03] two for loops [01:15:03] okay [01:15:04] one is [01:15:05] on the [01:15:07] on the whole array [01:15:08] and another is one [01:15:09] for the [01:15:10] internal array [01:15:11] okay so let's say [01:15:12] one is [01:15:13] plus with this one [01:15:14] okay so [01:15:15] we are taking first [01:15:16] then [01:15:18] we are adding with this [01:15:20] this [01:15:23] and we are maintaining [01:15:25] one result [01:15:25] okay [01:15:25] then also we are taking this one okay and adding this this this this this we are gaining maintaining [01:15:33] one result and then both the result are comparing okay which is greater okay then result the final [01:15:39] result is coming okay then we are taking also this one okay so again we are doing this okay [01:15:46] we are maintaining two for loops. So, in that, what will happen? Time complexity will be [01:15:55] like a more. If we have a 9 element, if we are taking two for loops to check for the array, [01:16:04] so 9 element, so time complexity will be something around 9 x 9, which is coming as a [01:16:13] 81. So, something [01:16:20] 81 minute maybe, okay, 81 second, okay [01:16:24] or arc, okay. So, which is not [01:16:28] cool, okay. We have to do in single pass [01:16:32] correct. Through that, we can maintain also [01:16:36] our time complexity and we can [01:16:40] maintain also our space complexity, correct. So, [01:16:44] base will be like [01:16:45] minor [01:16:47] which will [01:16:48] take [01:16:49] hope you got the question [01:16:55] ok [01:16:55] maximum [01:17:03] sum array [01:17:04] maximum sum array sum [01:17:07] I am taking an array [01:17:13] ok [01:17:14] what I will do, I will take [01:17:16] first current sum [01:17:18] what is up to the current sum [01:17:19] till now, which is going on [01:17:23] which is going on sum, this one [01:17:25] okay and this is the global sound okay this is the global sound which is array of a zero i'm [01:17:34] taking both both of this okay it doesn't matter you can take minus one also you can take something [01:17:41] you can like minus one okay you can take any of the element okay let's say i want to take [01:17:46] array of 7. I can take [01:17:49] something like that you can take [01:17:52] not necessarily array of 0. Then in the first pass only [01:17:59] 1, length of [01:18:03] 1, length of array. I will maintain [01:18:09] my current sum. I am starting from [01:18:13] 1. Why? Because I have taken [01:18:16] 0th element is [01:18:18] this one, okay. [01:18:21] That's why I am starting from 1. [01:18:22] I will compare that element to other [01:18:25] elements, that's why I am starting from [01:18:26] 1, okay, till [01:18:28] length minus 1, [01:18:31] okay, because [01:18:32] the range is like a n minus 1, [01:18:34] it will take, so that's minus 1. [01:18:36] So, I will update my current sum [01:18:38] first, [01:18:45] which is maximum [01:18:48] of, okay, [01:18:50] Okay, area of a i, area of a i means area of a 1, okay, maximum of 1, okay, and then [01:19:00] current sum plus area of a i, okay, current sum plus area of a i, and then I will maintain [01:19:11] another maximum sum which will compare with current sum, okay. [01:19:15] okay so let's say our maximum sum is something like that okay it will compare with the current [01:19:23] sum okay and then it will return the max sum okay and do you want me to dry run or you will [01:19:39] understand let's dry run right okay so same with this element it's quite long but it's good [01:19:48] to understand [01:19:49] so let's say this is the array [01:19:54] okay [01:19:54] I am taking [01:19:57] this one [01:20:01] as [01:20:03] this [01:20:04] okay [01:20:08] so what will be our current sum [01:20:12] so I am writing [01:20:14] not underscore okay current sum I am writing [01:20:16] as a minus 2 [01:20:17] and then maximum sum will be [01:20:20] minus 2 okay [01:20:22] and then [01:20:23] for i in a range. [01:20:25] I will start from 1 [01:20:27] because I am starting from 1. [01:20:29] You see, comparison. [01:20:33] I am starting from 1. [01:20:36] Array of a 1 [01:20:37] which is [01:20:41] 1. [01:20:43] What I am doing? [01:20:47] I am maintaining current sum. [01:20:50] I am maintaining [01:20:51] this one. [01:20:53] Current sum and then [01:20:58] which will come out to be [01:21:01] come out to be maximum of [01:21:05] 10 [01:21:08] which it is, sorry I am writing again [01:21:12] 1 [01:21:13] minus 2 plus 1 [01:21:16] ok [01:21:17] which is [01:21:19] maximum of [01:21:24] 1 comma [01:21:27] minus 1 [01:21:27] ok, so what is the current sum? [01:21:32] final answer [01:21:33] which is max 1 [01:21:38] ok, so till now [01:21:40] we compared and got that [01:21:42] 1 is our greater element till now. [01:21:44] Current sum. [01:21:46] Then it will go to the [01:21:48] maximum sum. [01:21:54] Max sum is [01:21:54] 1. [01:21:57] Sum is [01:21:58] x sum is [01:22:11] 0. [01:22:12] 0 is minus 2. [01:22:14] Current sum is [01:22:15] 1. [01:22:17] So, max sum [01:22:18] goes to 1. [01:22:20] So, till now, we confirm that [01:22:22] max sum is 1 only, correct? [01:22:26] Then it will go to the i equals to 2. [01:22:32] Area of 2. [01:22:36] So, area of 2 is minus 3. [01:22:42] So, area of 2 is minus 3. [01:22:45] So, current sum is [01:22:50] right, area of i. [01:22:53] So, max of [01:22:55] 3. Area of i, max of 3. [01:23:00] and then current sum [01:23:05] plus area of area. So, what is the current sum we have got? [01:23:09] 1. Okay. So, [01:23:13] 1 plus, sorry, minus 3 plus [01:23:18] current sum will be maximum law [01:23:31] minus 2. Oh, sorry. [01:23:39] Minus 3, not 3. Yep. Current sum will be [01:23:46] minus 3 is greater or minus 2 minus 2 is greater right so till now we got current sum minus 2 is [01:23:57] greater we have compared correct so now we will calculate the max sum max sum is maximum of max [01:24:05] sum okay which was the max sum 1 and then what we have the current sum till now 2 okay so which is [01:24:16] greater. [01:24:18] X equals 2. 1 is [01:24:20] till now greater. So, we have [01:24:22] we have iterated [01:24:24] up to this element. [01:24:26] We got 1 is our [01:24:28] greater element. So, we will iterate [01:24:30] 2 theories. Okay. So, now [01:24:31] it will come as a 4. Okay. 4 will compare [01:24:34] with the 1 again. Okay. So, [01:24:36] it will go and iterate. [01:24:39] So, hope you [01:24:40] got the point. [01:24:43] Right. How cadence [01:24:47] algorithm works. It will be [01:24:52] minus 3 [01:24:53] yeah [01:24:53] I corrected [01:24:54] thank you [01:24:55] so any [01:24:59] any doubt [01:25:00] you love [01:25:01] oh I [01:25:03] don't [01:25:03] so far [01:25:08] no any [01:25:08] doubt [01:25:08] hey [01:25:10] Subratpal [01:25:11] you are [01:25:12] playing with [01:25:12] you know [01:25:12] what [01:25:13] you are [01:25:13] raising [01:25:14] the hand [01:25:14] and the [01:25:16] land [01:25:16] and the [01:25:16] night [01:25:17] and you [01:25:17] are not [01:25:17] speaking [01:25:18] can you [01:25:25] type like [01:25:25] what's your [01:25:26] doubt [01:25:26] hello [01:25:27] yes [01:25:28] hi [01:25:29] yes I'm [01:25:29] actually [01:25:29] I had [01:25:33] some problem with my browser that's why i don't have any option to speak so i changed my browser [01:25:39] now it's okay so i had a doubt regarding the quick shot right so i implemented the quick shot and [01:25:46] when i uploaded try to upload now there are some hidden test cases which are failing so uh do you [01:25:54] consider those test cases also because uh it's little bit which case number is failing can you [01:25:59] Can you tell me? I will note it down. [01:26:01] 4 problem. [01:26:17] 1 test case is failing but that test case is hidden. [01:26:19] No, that was the...deliberately it was finding. [01:26:21] Okay, like it was an intense test case. [01:26:23] Okay, hidden test case [01:26:25] and it is giving runtime error. [01:26:27] So without seeing the input [01:26:29] it is a bit difficult to [01:26:31] sort that problem. [01:26:33] That's why [01:26:35] I am asking you this question. [01:26:37] Scroll down. [01:26:39] Okay. [01:26:43] I'll take care of this four and five, okay. [01:27:02] Okay, Raviranjan, sing, I think, yeah. [01:27:05] I am allowing your mic. [01:27:09] Raviranjan, Raviranjan, are you there? [01:27:25] I am here, sir. [01:27:30] I can able to hear you with some noisy sound. [01:27:33] Yeah, still here, I'm fine. [01:27:37] Where are you, first of all? Where are you? [01:27:41] i'm from ara no no where are you right now you are going somewhere no no okay i thought [01:27:52] okay so let's get to the point okay so you told like please do the time until the end you cannot [01:27:58] able to understand so here i am able to get it all but i just wanted to know what will be the [01:28:04] Okay, so be with me, okay, let's go with the Ravir engine, okay, so tell me Ravir engine, [01:28:17] I already told up to this, so, okay, first of all, you mute your mic, please unmute, [01:28:25] yeah, thank you, so, first of all, which question you want to try around me, this one or like [01:28:30] quick sort one so already like the last this one okay so even though like a noisy sound scan [01:28:38] quickly and then handle that so now till now you got to this okay you understood up to this right [01:28:46] yes okay uh so now you only tell me okay what will be the next steps what should i write [01:28:56] you got to the okay so let me also provide you the code so that you can understand [01:29:01] i am pasting the code here okay so please go through this code okay and tell me the next steps [01:29:10] what will happen okay in this what should i write here if you got the point if you want me to try [01:29:18] it until the end i'll go with you there is no any hurry or worries you understand what is maximum [01:29:40] severism [01:29:41] yes [01:29:43] yeah [01:29:44] so [01:29:45] I already [01:29:46] provide you [01:29:47] the solutions [01:29:47] of [01:29:49] this one [01:29:50] okay [01:29:51] and [01:29:53] I [01:29:55] dry run up [01:29:56] to this [01:29:56] okay [01:29:57] and [01:29:59] you can [01:30:00] tell me [01:30:01] for the steps [01:30:02] from [01:30:03] 4 [01:30:03] yes [01:30:04] obvious things [01:30:09] I will write [01:30:09] the current sum [01:30:10] the current sum [01:30:11] will be [01:30:12] match of [01:30:13] the current element and [01:30:15] so what is the current element [01:30:16] current element will be the [01:30:18] next one what is the i [01:30:20] what is the i [01:30:22] okay i will be 3 [01:30:25] array of a [01:30:28] array of a 3 right [01:30:30] yes [01:30:32] so array of a 3 is [01:30:33] okay i am sorry for that [01:30:35] i can also provide you the array [01:30:38] you can check out [01:30:40] this okay [01:30:44] yep [01:30:45] So, yes, maximum of? [01:30:52] Maximum of 4, comma. [01:30:55] Maximum, oh, okay, sorry, we will go one by one, right? [01:30:58] As we are going to this one, right? [01:31:02] So, area of 3, so, yeah. [01:31:06] 4, comma. [01:31:07] 4, comma, sum of current sum plus area of... [01:31:12] What's the current sum? Tell me the values. [01:31:15] I know that. [01:31:15] Minus 2. [01:31:19] current sum will be minus 2 plus 4 [01:31:24] minus 2 plus 4 [01:31:27] maximum of [01:31:33] max of 4 comma 2 [01:31:36] so which is maximum [01:31:39] will be 4 [01:31:40] then next steps [01:31:44] then max sum will be [01:31:46] max of [01:31:48] max sum [01:31:50] plus max sum and comma current sum [01:31:53] what is the max sum till now max sum is one yeah and current sum is four is four so maximum will [01:32:06] become four good okay so next steps yes so next inputting array okay i pulse to become four [01:32:22] array of four four will be array okay yeah i see here now it will be minus one current sum [01:32:41] 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. [01:33:18] Max sum is equal to, max sum and current sum, so max sum is 4 and current sum is 3. [01:33:28] so it will be 4 and sum is equal to max of [01:33:53] that is 2, current sum that is 3 [01:33:59] sorry sorry sorry 3 plus [01:34:10] 3 plus [01:34:15] 2 plus 3 that is 5 [01:34:17] current sum is equal to max of 2 comma 5 [01:34:25] which is 5 [01:34:27] max sum is equal to max of [01:34:55] max sum in the previous step we got [01:34:59] that is 4 I think [01:35:01] I don't think we did something wrong or like, okay, I just, we did like, and I equals to 6. [01:35:43] So, array of 5 is, array of 6 will become 1. [01:35:50] 1 comma? [01:36:04] Array of 6 plus current sum. [01:36:08] Array of 6 is 1, plus current sum was? [01:36:14] Current sum was 5. [01:36:22] So current sum will become maximum of 1,6 [01:36:29] So current sum will become maximum of 1,6 [01:36:35] What is to? [01:36:46] Max of 5,4,5 [01:37:10] 5 plus current sum 6 [01:37:26] Current sum is equal to max of [01:37:34] 6,1 [01:37:50] And of 8 equals to? [01:38:22] Current sum 1 [01:38:35] Current sum is? [01:38:38] 1 plus 4 [01:38:39] Max of 4 and 5 [01:38:52] maximum will become [01:39:02] max of 6, 5 [01:39:04] becomes 6. [01:39:17] Maximum of the [01:39:18] subarray will be [01:39:19] the sum for that subarray will be 6. [01:39:22] 6. Okay. [01:39:24] You got the point. [01:39:25] And if I need to find the [01:39:27] subarray [01:39:29] Okay. [01:39:38] So you return the maximum sum. Okay. [01:39:48] Thank you, Ravi. I hope [01:39:54] Paul got the point. [01:39:56] We till the last try-run. [01:39:58] Okay. [01:40:00] And [01:40:01] yeah. [01:40:04] So any doubt regarding [01:40:10] regarding this? [01:40:29] We will go to the next concept [01:40:30] which is [01:40:32] binary search [01:40:35] which is very easy. [01:40:42] So what is searching? [01:40:43] Like we are [01:40:45] searching through the elements. [01:40:48] Okay. And then [01:40:53] we have to [01:40:55] don't go for the linear search [01:40:57] because it will take time [01:40:58] that's why what we will do [01:41:00] we will divide the array [01:41:01] and we will search [01:41:02] through left and right point [01:41:04] so something like that [01:41:06] and suppose [01:41:08] and binary search is like [01:41:12] it don't check every element [01:41:14] it will look at the middle [01:41:15] and eliminate half of the array [01:41:18] every time [01:41:19] so it will divide [01:41:22] the [01:41:22] what was it [01:41:26] It will only work for the sorted array. [01:41:32] And array is sorted. [01:41:34] And if you want to see [01:41:35] what is [01:41:37] what you are finding, [01:41:41] let's say you have the element like [01:41:44] 2, 5, 8, [01:41:47] 16, [01:41:49] 93, 58, [01:41:53] 58. [01:41:54] right? And you are finding the element [01:41:58] paths which is 23. In the [01:42:02] linear search, we have to go one by one. We will compare [01:42:06] with if x is equals to this element, no. [01:42:11] If 5 is this element, no. 8, 12, [01:42:15] 16, 23, oh, we're fine. Let's say [01:42:18] we have a million of elements. We will go for the linear search, no. That's a not [01:42:22] right approach so that's why we will like a half the array okay so we will find the mid element [01:42:29] so in this case what i have said so mid element is like a 16 okay so we want to compare 16 with [01:42:40] the 23 okay so is 23 is greater than 16 okay so yes 23 is greater than 16. then because the [01:42:50] array is sorted we immediately know that 2 5 8 12 16 is not containing the 23 so we will remove [01:43:00] these things okay we will remove this okay and then we will check for another half okay so you [01:43:07] see how much like a element we have removed and how much we have time we have removed [01:43:14] time cut down, we update [01:43:18] so now it will check again, it will divide for the middle [01:43:22] I can see the middle one is 38 [01:43:26] and it will [01:43:30] compare again, 23 is [01:43:33] greater than or like a smaller than 38 [01:43:38] which will say yes, then it will remove [01:43:42] this half, okay, this half [01:43:45] and we find the element, okay, 23. [01:43:50] So, for this, we will take like a three elements [01:43:54] like a low, mid and high, okay, which we'll check [01:43:58] and we will mid [01:44:02] the half using low and high, that's how [01:44:06] we will go to the mid element and then we will [01:44:10] proceed. So, it's [01:44:12] a very simple quote. I will show you [01:44:14] binary search [01:44:20] which we required [01:44:23] array and one target [01:44:24] and we are considering [01:44:27] low as a 0 [01:44:28] high as [01:44:30] length of array [01:44:34] minus 1 [01:44:35] while low [01:44:42] is less than [01:44:44] high. [01:44:44] means it is not swapped [01:44:49] ok, we will find the made [01:44:55] 2 plus y divided by 2 [01:45:00] ok, then I will check [01:45:03] if area of a made is equal to [01:45:11] first two packet, then simply return that [01:45:18] return what? return the index number [01:45:22] return index number, return made means [01:45:25] return index number. [01:45:28] Return array of mid means [01:45:29] return that element. [01:45:31] Then, [01:45:34] else if [01:45:35] array of mid [01:45:38] is [01:45:40] less than the target, [01:45:43] is it the case? [01:45:45] Okay. [01:45:49] Then, return [01:45:50] or like a [01:45:55] you can say like a [01:45:56] low equals to mid plus 1. [01:46:00] Then, [01:46:03] else [01:46:04] i equals to [01:46:13] right minus one okay found anything okay we will simple return minus one because element is not [01:46:28] there in that case otherwise we will found so this is the port you can try to run it by yourself [01:46:39] not with you and yeah sending it out in this binary search for two people hello amir [01:47:00] do you have any doubt [01:47:02] or make sense to be not there [01:47:11] hello Bhishatli do you have any doubt [01:47:20] it says also not there [01:47:29] is it like [01:47:36] ok you can [01:47:43] if you cannot able to speak you can [01:47:45] let it paste at least your doubt [01:47:47] in this chat box [01:47:48] I will go through [01:47:50] ok so how do you find the subarray [01:47:53] how to [01:47:55] find the subarray [01:47:59] which total [01:48:00] is 6 [01:48:02] other than the concepts [01:48:17] seems to be [01:48:25] okay can we [01:48:39] can we end the class then [01:48:42] I have a question actually [01:48:50] regarding one of the assignment [01:48:52] for the lab [01:48:54] yeah [01:48:55] okay so for [01:48:57] last lab I was unable to complete [01:49:00] because of my family [01:49:01] like medical emergency [01:49:04] so will it be possible [01:49:06] to complete this week as well [01:49:08] I have checked that [01:49:10] the link is working fine [01:49:12] so can I submit in this week [01:49:14] yeah sure [01:49:16] yeah okay thank you [01:49:18] thank you [01:49:19] okay thank you guys [01:49:24] sorry [01:49:28] I forgot to paste the [01:49:29] Portland link by the way [01:49:31] thank you Bernard Lee [01:49:35] okay here is your Portland link [01:49:45] and if you raised your hand again [01:49:50] okay I already unmuted you I think so [01:49:52] let's take [01:49:53] Thank you, Suryans. Thank you, Krishna. Thank you, Dhanush. Thank you, Alavia. Thank you, Leon.