[00:00:02] We have added quicksort and started maximum serve array. So, in quicksort, just a brief revision I am giving. In quicksort, there is a mechanism of median of 3 for selection of 5V. [00:00:22] Okay, so as it is median of 3, so the three things are first, middle and last element [00:00:30] and it arranged what? [00:00:33] First should be less than, make sure that this order should be followed and then it [00:00:44] prevents the worst case behavior in nearly sorted algorithm and we have also studied [00:00:49] that it reduces the computational requirement by 14 percent because it somehow maintained [00:00:57] to perform nearly equal partition. [00:01:07] That is important, that is tn equal to 2t n by 2 plus order of n, if this is the case [00:01:15] then only the computational complexity is n of log of n otherwise we may reach to n square [00:01:22] when it is already sorted. So this is an example, standard quick sort example 10, 20, 30, 40, 50. [00:01:41] So this is already sorted, already sorted. And number of elements are 1, 2, 3, 4, 5, 6, 7, [00:01:54] 8, 9, 10. And here total number of comparison required is 45. And worst case behavior is [00:02:04] order of n and if you follow the same strategy so here the total number of comparison that you [00:02:12] will require will be 45 on the other hand here the total number of comparison is 39 although it [00:02:18] is 6 less okay but when the number is when the number is only 10 okay let's say when the number [00:02:27] is 100 and it is 60 less so of course it is good so in this manner you can clearly visualize that [00:02:35] median of three mechanism reduces the computational complexity from order of n [00:02:40] square towards n of log of n. So, this is the then this is the beauty of this median of three [00:02:51] mechanism in quicksort. Okay, then other mechanisms are there that has been discussed. [00:03:03] Okay, so what why what are the key differences between quicksort and merge sort just giving the [00:03:11] the glimpse so quicksort is in place merge sort required extra in place means that same memory [00:03:18] location okay and here it the result is stored in different memory at different place and quicksort [00:03:37] is cache friendly merge sort has more memory operations okay so cache friendly means that [00:03:42] no extra space is primarily required okay already we have discussed about these key why this quicksort [00:03:55] is faster and now coming on to the maximum salary problem so we understand that maximum [00:04:03] salary problem is primarily originating from the real world market scenario real world stock market [00:04:27] scenario okay i will yes monica okay already you are presenter so you can ask if you have any [00:04:47] good morning sir yeah be louder and say i understand [00:05:10] okay and enable my for this krishna uh yes krishna you can ask uh hi sir good morning [00:05:32] it seems recording was off for this session [00:05:35] okay yeah [00:05:36] thank you thank you so much [00:05:41] okay so we have started a discussion on the maximum salary problem [00:05:54] that is inspired from the real world market scenario [00:05:58] where we can purchase a share on a certain day [00:06:03] and will sell after the entire day operation, okay? Or after some day. So, let us say I buy [00:06:11] share on morning of 7. I can sell it not before that, okay? So, that is good. So, we can sell it [00:06:20] on the evening of 7 or morning of 8 or evening of 8 and so on. So, this means that the share [00:06:28] remain pre-used or blocked for some day. [00:06:33] So, let us say buy on 7, sell on 8 and initially price was 110 and further on the price was [00:06:40] 107. [00:06:41] So, we will be in the loss. [00:06:43] So, the scenario is for a share market perspective, if we entered on a day where the price is [00:06:51] very low and we sell on the day where the price is very high, then our profit margin [00:06:56] become maximum. [00:06:58] So, inspired from that, this maximum subarray problem is coming where in an array we have both positive and negative numbers and we have to identify a subarray whose sum is highest. [00:07:12] Okay, the simple strategy we have, let's say this set of numbers, 16 numbers and among these 16 numbers in the array, we have to identify a subarray whose sum is maximum. [00:07:29] Okay, so there are different mechanism of solving this, even you will surprise that it could be solved by a brute force, it could be solved from dynamic divide and conquer and it can be also solved by dynamic programming. [00:07:55] So, interesting thing is that if all the elements are negative and if all the elements are positive, [00:08:04] so this algorithm will work, but it is very simple. [00:08:08] If all elements are positive, so of course the sum of all the elements will be resulting [00:08:12] or will be the maximum sum value. [00:08:15] If all are negative, then we will pick the smallest negative, that is a single number [00:08:19] that will act as, that is, if all are negative, then the single number you will get, you will [00:08:37] get, that is least negative, least negative, okay. [00:08:45] And the problem is really interesting when the array contain both positive as well as [00:08:51] negative number. [00:08:52] So, when we talk about maximum subarray problem, so you have to think that this problem is [00:09:07] more suited for, this problem is more suited for array having positive as well as negative [00:09:36] numbers. Okay, so array having both positive and negative numbers, then this problem is [00:09:50] suited or this problem is suitable for that scenario. So, on the previous class, [00:09:58] we have already started discussion on the brute force mechanism [00:10:03] where we will check all the possibilities and identify whichever is highest. [00:10:15] One more interesting fact is that the brute force algorithm that we are discussing [00:10:21] will impose a computational complexity of order of n square [00:10:25] If we will get more randomize or check all possible subsets, then it reaches to order of n cube as well. [00:11:01] But here what we are doing in brute force mechanism, we are, if I take a value a and b, [00:11:10] I am not taking the value b, a in a subset. [00:11:13] That is important because we are maintaining the order because we need not to bother about [00:11:18] whether A's will come first or B will come first because we know that their sum will [00:11:23] be remain same. [00:11:25] Okay, so what I try to convey here while determining the subsets we won't bother about the orders [00:12:00] of number which reduces complexity from n cube to n square. If we bother about the order, [00:12:22] so this means that if we are considering a comma b as a subset, so we should also consider [00:12:27] b comma a as a subset, but here we are not doing so. So thus computational complexity [00:12:33] shifted to order of n square. If you see on the internet or any literature, so somewhere [00:12:38] you will find the computational complexity to be order of n square but the but the thing is there [00:12:45] we are considering all possibility and here we are considering the possibility in a unique direction [00:12:51] or we are wisely removing the reoccurrence of the same set of numbers. [00:12:58] Okay. So, here we are holding, we are wisely removing duplicate entry, entries, subsets. [00:13:30] Okay. So, we are wisely removing a duplicate entries from the subset. So, that reduces the [00:13:38] complexity to the n square. Okay. Now, here is the question that we have already solved. [00:13:45] So, we are basically, what we are doing, we have these set of elements. [00:13:59] We have these set of elements, that is 2, minus 6, minus 1, 3, minus 1, 2 and 3. [00:14:06] So, what we are doing, just this element, then sum of these 2, minus 4, then sum of these 3, minus 5, then sum of these 3, minus 2, minus 1, then it will minus 3. [00:14:17] Then, we are adding both, minus 1, then we are adding last, then we are getting minus 3. [00:14:24] So, if you see what is the highest sum value that we are receiving here, that will be of [00:14:32] course 2, if you can check, ok, 2 minus 4, then now in the next step we will take this [00:14:40] number as the first entry and go till last, so minus 6, minus 6, minus 7, minus 4, minus [00:14:54] 5, minus 3, minus 5. What we are doing? 6, minus 1, minus 4, minus 5, minus 3 and minus [00:15:04] 5. So, what is the maximum possible sum here we are getting? That is getting minus 3. Now, [00:15:14] similarly, we will start from this number. So, minus 1, 3, that become 2, then minus [00:15:20] 1, 1, then 2, it become 3, then minus 2, it become 1. So, maximum value we are achieving [00:15:26] 3. Similarly, we start from this number. So, 3 minus 1, 2 plus 2, that is 4. So, here we [00:15:34] are getting 4 for these set of numbers. Then so on. So, here it is 1, here it is 2, here [00:15:42] it is. So, among these, what we are getting? This one is the highest value. So, the maximum [00:15:47] sum array will be what? 3, minus 1 and 2 and whose sum will be equivalent to the 4. Okay. [00:15:58] So, sum is equivalent to the 4. So, this is a simple mechanism. Okay. But remember, this [00:16:08] does not consider, space does not consider repetition of same set of elements. [00:16:36] So, this is important. [00:16:37] If we consider, then we will reach to an order of n cube. [00:16:40] Because we know that brute force mechanism do what? [00:16:42] It will check out or search all the possibilities irrespective of whether the solution is possible [00:16:48] or not. [00:16:49] So, likewise, there is an interesting example associated with the brute force algorithm [00:16:54] that if you want, let us say your laptop is misplaced. [00:16:59] So, when you apply brute force mechanism, [00:17:01] so it will search for every space in your house, [00:17:05] garden, washroom, everywhere. [00:17:07] But of course, in garden and washroom, [00:17:09] there is no possibility. [00:17:10] There is a high chance that it will be residing [00:17:12] in your bedroom or study room. [00:17:14] So, when we apply little bit heuristic or intelligence, [00:17:19] there we restrict our search in the living area, [00:17:23] study and bedroom, then the chances of getting the laptop is high as well as it is removing [00:17:30] the irrelevant things. Okay. So, there we are applying certain brute force, certain [00:17:36] you can say heuristics or the existing informations or our intelligence little bit. Okay. If you [00:17:43] see the algorithm, how it is working, we are starting from 1 going to N. Okay. And then [00:17:50] there is a two loops are running, okay. One loop i equal to 1, 2 and another loop is j equal to 1, [00:17:57] 2, okay. So, let us take a problem and try to iterate this. So, 2 minus 6 minus 1. Okay, [00:18:21] I am randomly taking any series. So, it is well, numbers are 1, 2, 3, 4, 5 and 6. So, [00:18:28] first loop will be start. So, i equal to 1, we will go inside. So, for j equal to 1 to n, that is [00:18:40] 6, what we will do? Sum equal to sum of aji. So, initially sum is how much? Sum is 2. If sum is [00:18:48] greater than max, here max was 0. Yes. So, what will happen? Max equal to, now j equal to 2, [00:19:00] then sum equal to minus 4, max remain intact, that is 2. When j equal to 3, sum becomes how much? [00:19:10] Minus 5 and max remains 2. When j equal to 4, then sum equal to minus 2, max will remain intact, [00:19:26] that is 2. Then j equal to 5, so sum equal to minus 4, max remain intact. Then j equal [00:19:37] to 6, sum equal to minus 9 and max remains 2. Okay, so in similarly manner when i equal [00:19:51] to 1, then j will start with, sorry i equal to 2, then j will start with 2 to 6, repeat [00:19:58] all those steps and so on. So, if you follow the similar strategy, the algorithm will work [00:20:02] and here we are what we are witnessing that there is a loop inside loop, there is a loop inside [00:20:12] loop that imposes the computational complexity of order of n square, that is the computational [00:20:18] complexity of the brute force algorithm. This was brute force mechanism for solving [00:20:29] the maximums of a problem. Now, there is an interesting thing that is divide and conquer [00:20:35] also solve this problem. So, before going in the formal discussion, let me show you [00:20:42] an interesting thing. What divide and conquer says, divide, conquer, combine. Divide, conquer [00:21:09] and combine. So, now when I talk about divide, conquer and combine, then what could be the [00:21:18] situation? The merge sort or binary search strategy we could adopt. I will partition [00:21:25] the array, search minimum here and search minimum here. So, there is a possibility that we could [00:21:34] find the element in the left side or in the right side. Now, one question arises, so if there is a [00:21:42] vary like this one and this is left half, this is right half. So, if there is a vary like [00:21:49] locating here, so this is called as the cross sum. So, three sums are there, left sum, right sum and [00:21:56] cross some. Taking a little break, just coming and then we will take the queries as well to start. [00:22:40] So, we were talking about the divide and conquer mechanism. Puneet, we will take the queries. [00:22:47] Okay, let me complete this mechanism, then we will complete. Because this is important, [00:22:55] algorithm and other things are the formal things about this, but if you understand the concept, [00:23:01] then it is very easy. Now, what we were doing, we have to identify the maximum sum. So, there [00:23:07] is a possibility that the maximum sum lie on the left side or on the right hand side. [00:23:16] And there is a possibility that in between, but we know that in divide and conquer what [00:23:20] we will do, we have a big problem, then we will divide into sub problem, then we will [00:23:25] further divide into sub sub problem and we will stop when we will reach to the single [00:23:30] element level. So, here also we will try to do the similar thing. And in the meanwhile, [00:23:40] when we reach to 1, 1 element level, when we reach to 1, 1 element level, then we will [00:23:49] stop. Then this recursive division is stopped. Primarily what we are saying recursive division [00:23:56] is stopped. Now, think about scenario. We are having 2 minus 3. These are the single [00:24:15] element level. So, now left sum is 2, right sum is minus 3 and when we are going up, then [00:24:24] what we have to do? We have to do a cross sum. So, cross sum is how much? Because here [00:24:29] are 1, 1 element, so it is minus 1. So, which one is highest? So, here the highest one is [00:24:34] left sum. So, the sum that proceed upward will be the left sum that is 2. Similarly, [00:24:42] when we are having these two elements, that is now left sum is 2 and here let us say we [00:24:46] are getting left sum, right sum is some minus 1, then when we will proceed upward, then [00:24:52] we are adding both. But there is a catch. So, I hope you people understand. Left sum [00:24:59] means that adding the entries of left side and picking out the maximum. When we are talking [00:25:06] about single element, so maximum, minimum, everything is there. So, there is no problem. [00:25:11] And in the right sum also, we will pick the max. Then we are talking about the cross sum. [00:25:25] So, when there are two elements, let us say 2 and minus 3, so cross sum is of course this [00:25:31] plus this, but what is the cross sum strategy? [00:25:35] So just see this, in cross sum of a given sub array. [00:25:43] So for example, we have 7, 8 element, so first we will identify the middle part or the median [00:25:51] part while doing the cross sum. [00:25:54] Then from median to left identify the maximum sum and from medium to right identify the [00:26:04] maximum sum and then add them. [00:26:06] So this is sum on the median to left and sum on the median to right and then add them. [00:26:16] That is the strategy. [00:26:18] That is sum on the median towards left, that is highest, not lowest, highest plus sum on the medium to right. [00:26:32] This is important catch. [00:26:34] Cross sum does not mean that just taking all the entries of left side and all the entries of right side and add them. [00:26:40] That is not there. [00:26:41] In cross sum, what we have to do? [00:26:43] We have to identify median. [00:26:44] from median we have to go toward the left and identify the maximum possible sum and from median [00:26:51] we have to go toward the right and identify the maximum sum and then we will add. So let's say I [00:26:57] identify the maximum sum on the these index and these index. So this will be automatically [00:27:02] discarded. So that we will see with an example but the basic thing is that the maximum [00:27:08] sub array maybe reside on the left part, maybe reside on the right part or maybe reside on the [00:27:15] cross section. So, left part means that we have to identify the maximum possible sum on the left [00:27:21] side. Right part means that we have to identify the maximum sum on the right side and cross sum [00:27:27] means that we have to identify the maximum sum value starting from the middle to the left plus [00:27:32] starting from middle to the right so this is the catch important catch okay so if you see here [00:27:39] the interesting only when array contain some negative number this is important okay if we [00:27:46] had an array and we have to identify the maximum sum so if numbers are not negative and positive [00:27:52] then there is no significance of it if it is all positive just pick just add all and get the result [00:28:00] Okay. [00:28:00] If all negative, so you have to just identify the minimum one and your task is done. [00:28:08] Now, this is divided entirely in the sub array. [00:28:17] Low to mid, mid to high and cross point is this one. [00:28:21] This is interesting. [00:28:22] Low, mid, j. [00:28:25] So, entire region we have to search. [00:28:30] But we have to search for what? [00:28:32] Max sum here and max here. [00:28:34] Then only we can do a merge. [00:28:36] Okay. [00:28:37] So, this is an interesting thing, if you check, here there is a possibility of getting the number, here there is a possibility of getting the number, this is left, this is right and also here we have started with the middle end, reach towards some step and reach towards also some step. [00:28:55] Why not we are moving till end because we have achieved the highest value possible in these entries only. [00:29:02] Otherwise your algorithm will check. [00:29:05] But it will pick the highest. [00:29:07] So assuming highest is appearing here and highest is appearing here that we are summing. [00:29:14] So this is the you can say I will go for that. [00:29:19] okay and if we reach to the single element level that is high to low then we will return [00:29:26] okay so we will see the algorithm at the later stage let us solve one problem using the maximum [00:29:32] sub array okay so best way is this is how i am following the algorithm i will write down the [00:29:40] problem okay try to solve my divide this divide and conquer strategy then i will take the queries [00:29:48] Okay. So, just give me some time. I am just noting down the problem. Just give me one [00:30:18] minute. Just listen to me. If you do not understand, I am happy to help you. But let me finish [00:30:25] this. So, we are having an array, okay, that is 13, minus 3, minus 25, 20, minus 3, minus [00:30:42] 16, minus 23, 18, 20, minus 7, 12, minus 5, minus 22, 15, minus 4 and 7, okay. So, in the next line [00:31:05] we will try to draw full one. Here we have minus 4 and 7 and here we have and for this array we [00:31:21] have to identify. So, two entries are also as well there, minus 4 and 7. So, we are having [00:31:27] total 16 element. Although it is also applicable for the odd, so same thing you can adopt int [00:31:35] low plus high by 2. So, low is the, this index 1 and high in the 16 index. So, now if we apply [00:31:46] that mid division. So, what we will get? Two entries with 8 and 8. So, we are getting two [00:31:54] entries that is 13, minus 3, minus 25, 20, minus 3, minus 16, minus 23 and 18. This is [00:32:14] one array where we are getting and another one will be the remaining elements. What it is? 20 [00:32:29] minus 7, 12 minus 5 minus 22, 15 minus 4 and 7. Then it is further divided because we have taken [00:32:40] 16, but of course you can take odd one also. Now we will get 4, 4 element that is 13 minus 3 [00:32:50] minus 25, 20 in one subarray and in another subarray we will find minus 3, minus 16, [00:32:59] minus 23 and 18. Then we will get how much? 13, minus 3, then minus 25 and 20. Here we will get [00:33:12] minus 3, minus 16 and minus 23, 18. Okay. And this is the last option that is 13 and [00:33:22] minus 3. Okay. So, and this will be minus 25 and 20. This will be minus 3 and minus 16. This will [00:33:36] be minus 23 and 18. So, now this is how we are recursively dividing a problem. This is similar [00:33:46] as merge sum. Now, if we are at here, so left sum is how much? This is single entry, 13. Right sum [00:33:54] is how much? Minus 3. And if we do a cross sum, so cross sum means that we are having two element [00:34:01] that is 13 and minus 3 from the middle. Identify the highest sum in the left direction. Identify [00:34:08] the highest sum in the right direction and merge them. So, here they are only one element. So, [00:34:13] cross sum will be how much? Cross sum will be 10. So, whichever is highest. The highest one is 13. [00:34:19] So, the left sum for this one will be propagate up that is highest value with one element. [00:34:27] Similarly, we will do for the right side. So, 25 is the left sum, right sum is 20 and cross sum is [00:34:35] minus 5. So, which one is highest? Right sum. So, right sum will proceed upward. [00:34:42] Now, if you talk about this larger array, so we are having left sum 13, right sum 20. So, [00:34:50] what could be the cross sum? So, for cross sum, we are doing what? 13, minus 3, minus [00:34:57] 25 and 20. Mid, from mid to here, the maximum value of the sum is how much? 10, because [00:35:05] minus 3 and 13. Here it is minus 25 and 20, that is minus 5. So, cross sum will be what? [00:35:12] 5. And which one is highest? The cross sum is 5. So, which one is highest? 13. 5 or 20? So, 20. [00:35:21] So, right sum 20 will proceed further. And if you check this arrow, [00:35:26] the maximum sum possible will be, of course, 20. Now, coming to this side. So, minus 3, [00:35:34] minus 16, cross sum will be minus 19. So, left sum that is minus 3 will proceed. [00:35:39] Similarly, here minus 23, 18 cross sum will be minus 5. [00:35:44] So, right sum will proceed that is 18. [00:35:46] Now, talking about this. [00:35:49] So, we have minus 3, minus 16, minus 23 and 18 starting from the mid. [00:35:57] If we go this direction, so maximum possible sum is how much? [00:36:00] Minus 16 because if we include minus 3, then it becomes more negative. [00:36:05] And here if you go, so here we will include 18 because it is reducing the minus influence. [00:36:11] So, minus 23 plus 18 minus 5 and minus 16. [00:36:15] So, it will be minus 21. [00:36:16] So, cross sum is how much? [00:36:18] Minus 21. [00:36:19] So, of course, right sum will proceed upward that is 18 with one element. [00:36:24] Now, for this big array, what we are getting? [00:36:30] Here, the maximum value is, right sum is 20. [00:36:34] that is propagated. So, now it becomes the left part and here on the right sum, we are getting [00:36:40] the 18 as the maximum value. Now, let us talk about the cross sum. So, for cross sum, we go [00:36:46] in the middle, start adding. So, 20 minus 25 minus 5 minus 8 and then 13 is coming. [00:36:59] So, total sum that we are getting, if we add all, then what it is? [00:37:04] 33, 5. [00:37:07] But we will not proceed. [00:37:09] We will just bound our things to the 21. [00:37:12] So, on the left side, we are getting the maximum sum of 20. [00:37:15] Because if we add all, then we are getting the negative value or less positive value. [00:37:20] Now, in this direction, minus 3, minus 16, minus 23, minus, sorry, plus 18. [00:37:27] So, we will not proceed further because we will bound to the minus 3. [00:37:36] Because if we go beyond that, then we are not getting. [00:37:42] So, left sum is 20, right sum is 18, which will proceed further. [00:37:45] That is, for the upper array, the sum 20 will proceed. [00:37:49] And its index is obviously, we know that it is just a4. [00:37:53] Similarly, for this portion, what we will do? [00:37:56] We will try to do division first. [00:38:00] So, 20 minus 7, 12 and minus 5 and in this direction we have minus 22, 15, minus 4 and 7. [00:38:12] Okay, then it is further divided 20 minus 7 and here it is dividing 12 minus 5, this will be minus 22, 15 and this will be minus 4 and 7. [00:38:32] this is divided as 20 and minus 7, this is divided as 12 and minus 5, this is divided as [00:38:43] minus 22 and 15, this is divided as minus 4 and 7. Now, left sum 20, right sum minus 7 cross sum [00:38:54] 13. So, of course, left sum will proceed that is the value of 20. Here it is 12 minus 5 cross will [00:39:00] be 7. So, left sum again from, so here you can see left sum is coming 12. Now, cross sum if you [00:39:08] want to calculate. So, minus 7, 20, of course, it will be added 13 from this side and here we will [00:39:14] stop at 12. So, cross sum will be what? 25, that is highest. So, cross sum will be 25 and if you [00:39:22] see the index, it is taking this much portion, from 20 to 12. This is a cross sum. And if [00:39:30] you see the, if you identify the sub array for this one, so we will get maximum value [00:39:35] as 25. Similarly, if you see on this side, so minus 22, 15, so 15 will of course come [00:39:42] up, that is the left sum. And for this minus 4 and 7, so 7 will come up, that is the right [00:39:48] sum. Now, for this sum array, what we will do? If we proceed in this direction from the [00:39:53] mid, so we will get more negative. So, we will stop at 15. In this direction, we are [00:39:58] about to get what? Minus 4 and 7. That is 3. So, cross sum will be what? 18. So, from [00:40:09] this branch, 15, 7 or 18. So, cross sum we will take that is 18. Now, this becomes left [00:40:16] sum and this becomes right sum that is 18 and left sum is 25. Now talking about this [00:40:22] big array, if you proceed plus 7, 0, 20. So if you consider all 4, then we are getting [00:40:30] the sum of 20. And here if you see minus 22, minus 4, 26. And 5 and 7, 22, minus 4 we [00:40:43] are getting. So that is good because we will consider all 4. So cross sum becomes what? [00:40:49] cross sum become 16. [00:40:54] So, because from the right hand side also we have to take the positive value. [00:41:00] So, we are considering what? [00:41:01] Minus 22, 15 that is minus 7, minus 4 will become minus 11 and when we add 7 then it [00:41:08] become minus 4. [00:41:09] So, cross sum, since 16 is coming and from this side we have already identified 20 was [00:41:15] coming. [00:41:15] Okay, so now we will calculate the cross sum for this one. [00:41:24] But the good thing is that we already know this is at 4 and 4 and this cross sum of 16 [00:41:33] is sorry cross sum of 25 is around the 20 and minus 5, this one. [00:41:49] Two other values, this is the 20 and this is this one. [00:41:52] So, while estimating the cross sum, we will bound to this area only. [00:42:01] So, now from this, if you keep on adding, so you will get minus 16, minus 3, 20, then [00:42:08] it become 1, then minus 25. [00:42:11] So, what is this indicates? [00:42:12] Beyond 20, we will not go. [00:42:14] And here, if you consider minus 23, 18, so minus 5 plus 20. [00:42:22] So, beyond this, you will not get a higher value. [00:42:26] or beyond 12, we will not get a higher value. So, you will get some cross sum x. I am not [00:42:32] calculating that right now. So, for estimating the cross sum, now a question arises, sir, [00:42:44] you are seeing also, no, we will bound to this 4, to this 4, 5, 6. So, when we are calculating [00:42:57] the cross sum, so we will bound that, we will not go beyond 4 and here, whatever the index [00:43:03] we are getting, that is 9, 10, 11. So, from A of 4 to A of 11, we will calculate the cross [00:43:11] sum, not beyond that. Because if we calculate beyond that, then there is no significant [00:43:15] difference of this algorithm. That is, from left side, we are getting 20. And from right [00:43:21] side, we are getting 9, 10, 11, 12. So, we will not go beyond that. So, that is the cross [00:43:27] sum value. I hope you people got a brief idea. And I was assuming you also have a doubt. [00:43:33] so let me take it then we will proceed who was moderator i forgot the name yeah monica so one [00:43:47] by one enable mic for um someone i am labeling for punit yes punit yeah my question was like [00:43:59] to solve this problem why you are not using the kadani algorithm uh rather to do that we will [00:44:06] come that will i have said that we can solve that this uh maximum sum via brute force via [00:44:13] dynamic divide and conquer and then dynamic programming so when i will talk about the [00:44:16] dynamic program then i will talk about that cadance algorithm okay any difference between [00:44:28] dynamic programming and its space complexity is little higher than this divide and conquer [00:44:33] but it is famous one in for maximum summary so all the dynamic programming algorithm will [00:44:39] fasten the processing by taking extra space yeah so for storing the previous result we need to [00:44:47] use the memory and then then we are speed up so that is the property of dynamic programming [00:44:53] we will store all the previous results and using those results we are getting out the next step [00:44:59] result so but here but here also we are storing that right previous results after getting the median [00:45:06] okay so these are the just temporary so this is one sort process i am following step by step now [00:45:14] so yeah so this is a temporary store is not a fix but in dynamic program we have to [00:45:20] preserve the entire step in single loop then multiple looping operations so it will be remain [00:45:26] hold yeah okay we'll see the algorithm so you will find the difference clear difference yeah [00:45:34] so basically my query is respect to the right some which is when you go with the top right [00:45:57] if you go back to the problem [00:45:59] so we have selected [00:46:02] while you are just describing [00:46:05] the problem statement [00:46:07] or the algorithm process [00:46:09] that we will take the medium [00:46:11] and then somewhere we have an assumption [00:46:13] you mentioned that we will go [00:46:15] towards right and left [00:46:17] for a few steps [00:46:19] not completely [00:46:20] so is it the same way when we said [00:46:23] from bottom to top [00:46:25] and we went right so we went from bottom to top and we found that 20 and 16 whatever uh you can [00:46:31] say right sum and this was right sum right and we know the index now index of 20 is how much [00:46:39] a of 4 and index of uh index of this cross sum 16 was how much it is if if i say 1 2 3 4 5 6 7 8 [00:46:49] It is 9, 10, 11 and 12. [00:46:52] So, we have two indexes that is a of 4 and another subarray is from 9 to 12. [00:46:59] Agree? [00:46:59] So, now cross sum will be possible in between this one, not beyond this and not beyond this. [00:47:04] So, for estimating the cross sum, we will use an array that is a of 4 to 12. [00:47:11] So, my question was, what should be an ideal assumption that how much left or how much light we should be moving? [00:47:17] because [00:47:17] that is not an assumption [00:47:19] now that is fixed [00:47:20] we will not go beyond 4 [00:47:22] and we will not go beyond 12 [00:47:24] in between the cross sum [00:47:26] can be possible [00:47:27] ok [00:47:29] so for choosing that [00:47:31] you are confused or getting the thing [00:47:33] I am just trying to [00:47:35] here it is a of 4 [00:47:36] so we will not go beyond 4 [00:47:39] and here it is 9 to 12 [00:47:40] so we will not go beyond 12 [00:47:42] so cross sum is possible in between [00:47:44] 4 and 12 [00:47:47] Yeah, but that's what my question was. Why we are choosing from 9 to 12? Is it because from the bottom to top we meant that's why we are choosing? [00:47:55] Okay, sorry, here we will not take, cross sum is 16, but here if you see the maximum value is 25, I guess then you are confused. [00:48:05] So 25 will be pulled up. So whatever the, so the element that are responsible for 25 is how much? [00:48:11] 20, 7 and 12, and their indices are 9, 10 and 11. [00:48:14] okay so don't confuse so this 9 10 and 11 is the highest thing and here 20 is the highest thing [00:48:22] so its index is 4 and their index are 9 10 and 11 so the array will be 4 to 11 not 12 you think [00:48:29] okay so the final value from the right side should be 20 again or it's 19 sorry 16 it's [00:48:38] is 25 from the right side and 20 from the left side okay but but but it doesn't fall in the [00:48:47] error rate if we if you see in the error itself uh it's uh it has a sum i agree it has a sum [00:48:54] but how come it's represent it's uh it's likely to have no original if i consider these three [00:49:01] elements so then you are getting what okay yeah and then this is sub array okay and here in this [00:49:10] direction there is one sub array so the starting index was what four a of four and another sub [00:49:16] array that is having the maximum value is nine ten and eleven okay and the cross sum will be [00:49:21] possible in 4 to 11 okay okay okay sir understood thank you thank you so this is a little bit [00:49:32] complicated i will again explain if anyone asks the question yeah yes i have enabled your mic [00:49:46] yeah hi sir uh good morning good morning sir uh i have a question uh if you see the slide um [00:49:55] there was a sub array called 20 minus 7 12 and minus 5 yes so my question was how are we [00:50:05] calculating um cross sum because i am thinking the cross sum would be here 20 plus 12 because [00:50:12] maximum from the left side is 20 and maximum from the right side is 12 so if you sum it you'll get [00:50:17] like 32 why is it 25 no the cross sum is here here you are talking about 25 why it is called [00:50:26] 25 because for four element we are starting with the middle 27 and 251 let me do 20 minus 7 and 12 [00:50:40] and minus 5 getting so from the right side we are getting a left sum which is 20 the right sum is [00:50:47] how much 12 that we have already calculated now we are talking about the cross sum okay so from [00:50:54] the mid okay wrongly so from the mid we will go in this direction maximum possible sum is how much [00:51:06] 13 agree right minus 7 plus 20 and in this direction the maximum possible sum from the [00:51:15] median is 12 right if we add minus 5 so its value become how much 7 so we will stop at 12 [00:51:23] so 12 and 13 sum will be what 25 oh okay okay got it yeah i did travels around got it yeah okay [00:51:32] so um yes so this is the strategy yeah okay okay and one more thing um you also told about the [00:51:41] um boundaries like we have a bound to be set and we cannot go beyond it and what is how is that [00:51:48] okay so in the the left cross sum was what 20 so that was a of 4 if you so that's a good question [00:51:56] so it is a one minute i guess my cursor is blinking somewhere okay just so here it is a of 4 [00:52:03] and here it was a of 6 getting 12 was the a of 6 and we are just finding the cross sum in this one [00:52:12] so getting we are automatically stopping at 12 got it so my cross a of 6 so the cross sum will [00:52:22] always write in the extreme index of left sum and right sum so left sum extreme index with [00:52:28] just one element 4 and right sum extreme end is 6 so in between 4 and 6 you will find the cross sum [00:52:33] you need not to bother about the other element got it so that is a good good question you have [00:52:39] asked. I hope number of people doubt is now clear. So, what I will do for the top most [00:52:48] cross sum, I will show how the cross sum is working for the top part. So, if you remember [00:52:57] the left sum that was the 20 and the cross sum is just we have calculated is 25 from [00:53:07] that is also the right sum. So, if we consider the entire array again 13, minus 3, minus [00:53:15] 25. I will take other people query as well. 20, minus 3, minus 16, minus 23, 18, 20, minus [00:53:27] 7, 12, minus 5, ok, 12 and minus 5, not minus 15, ok, forgot about other element, this is [00:53:47] minus 5, do not confuse, so now if you see 1, 2, 3, 4, 5, 6, 7, 8, so this was the boundary [00:53:54] from which we have divided and here we find 20 at a of 4th, 4th index it was, if you see [00:54:01] 1, 2, 3, 4, 5, 6, 7, 8 and this one is 9, 10, 11, 12 and so on. [00:54:09] Now, when we are calculating the cross sum, so here maximum index that we will go is 4 [00:54:16] and here the extreme index is 11. [00:54:20] So, cross sum is possible between 4 to 11, not beyond this. [00:54:24] So, this is not an assumption, this is the algorithm part. [00:54:27] So, cross sum we will, so from 4 to 11, if you see the elements are 20, minus 3, minus [00:54:35] 16, minus 23, 18, 20, minus 7 and 12. [00:54:40] Okay. [00:54:42] So, if you see, so for this 1, 2, 3, 4, 5, 6, 7, 8 elements are there. [00:54:49] So, 4 will be act as a median. [00:54:52] So, from here we will go this side. [00:54:54] So, minus 23, minus 16, minus 3, but we are getting 20. [00:54:58] So, how much sum we will get? [00:55:00] 39, 42, that minus 22 from this side. [00:55:03] And from this end, what we will get? [00:55:05] 18, 20, minus 7 and 12. [00:55:08] So, all if you sum, so that is 30, 50, 43 we are getting. [00:55:12] So, cross sum, what resultant will be 21. [00:55:16] And this is 21 value and already we have achieved 25. [00:55:20] So, resultant of this cross sum will be 25. [00:55:23] that is the the thing I guess yeah someone I understand okay now looking [00:55:28] another people query yes sir good morning sir so basically sir my doubt was [00:55:39] regarding that only like how the things are the core logic I'm trying to get I [00:55:44] was unable to get the core logic while you are explaining with very large [00:55:47] example yeah so when you break down to a smaller one it is quite gettable the [00:55:54] core logic but i would request you sir to take a bit of a smaller example like eight of element [00:56:00] and do the whole process so that yeah yeah that is great so what i will do um then i will take [00:56:08] the other people's query because some are also yeah so sort of i will uh that is great see how [00:56:22] it is actually working. Because in large array, it is a space constant as well. That is not [00:56:26] possible for me to do. So, let me write the question again and solve it for the just 8 [00:56:32] elements. Just I am taking a 1 minute break, then I will write. If I had an example, it [00:56:46] will be more clear. So, let me write down the half portion. 13 minus 3 or I guess second [00:56:54] half was quite interesting where cross sum was giving the value. So, I will write that [00:56:58] second half 20 minus 7 well minus 5 minus 22 15 minus 4 and 7. The good thing is that when we [00:57:13] solve with a problem or when we solve a problem okay like numerical problem so your concept is [00:57:18] clear so nothing too much more worry about the algorithm and other respect that you can do [00:57:23] easily. So, I am just writing the index 1, 2, 3, 4, 5, 6, 7 and 8. So, now dividing is 20 minus 7, [00:57:40] 12 minus 5 and on this side we have minus 22, 15 minus 4 and 7. Again we are dividing 20 minus 7 [00:57:57] and here we are having 12 and minus 5 then we are going where minus 22 15 and here we are having [00:58:09] minus 4 and 7 and here we are having 20 minus 7 12 and minus 5 okay so if you talk about this [00:58:49] so left sum is just one element 20 right sum is minus 7 if you do a cross sum so cross sum means [00:58:56] median to this. So, there is one element and one element and if you see the index wise [00:59:01] it is 1 and 2. Both we are considering. So, in cross sum we have to also consider the both [00:59:08] that is now the left sum will propagate up that will the value is 20. And for 12 and minus 5 [00:59:21] left sum is 12, right sum is minus 5 and cross sum is 7. So, just one element, median to this [00:59:30] side, maximum value and median to that side, maximum value. And the bounding index are 3 [00:59:36] and 4 only. So, maximum value that is right sum is how much? That is 12. Now, for calculating [00:59:44] the cross sum we are getting two highest value 20 and 12 and their index are 1, 2, 3, 4. [00:59:52] So its index is 1, 2 and the right sum index is 3 only, not 4. So for calculating the maximum [01:00:02] sum we had the array a and from 1, 2, 3 we have to calculate the maximum sum. No other [01:00:07] thing is needed. So, the 3 values are 20, minus 7 and 12, odd number considering. So, left side, [01:00:15] the sum is 13 and on the right side, the sum is 12. Then the cross sum is how much? 25. Which one [01:00:21] is highest? 25 is highest. So, for this bigger entire array, the left sum will become 25 and [01:00:29] we know the index that is from 20 to 12. Now, on this portion, if you talk about minus [01:00:40] 23 to 15 cross sum is minus 7, of course, the left sum becomes 15 and index you know [01:00:50] that is 5 and 6. So, its index is 6. Similarly, from this side, the right sum will become [01:00:59] 7 and its index is 8. Now what we are saying we have to calculate the cross sum. So cross [01:01:05] sum index will be how much? 5, 6, 7, 8 will be from 6 a of 6 to a of 8. So what are the [01:01:14] numbers? 15 minus 4 and 7 considering same thing. So this become 11 and this become 7. [01:01:22] the cross sum value will 18. And if you see it is 15, it is 7. So, 18 is the cross sum that is now [01:01:30] become the right sum for the above problem. And here we have 18 as the resultant, 18 as the [01:01:38] resultant on the right side. Okay. I hope you people are getting how 18 is coming and how 25 [01:01:43] is coming. So, for 25, the values are a 1 to 3 and for 18, the values are 6, 7, 8, 6 to 8. [01:02:02] So, extreme ends are what? 1 to 8. Now, for calculating the cross sum, we have to refer [01:02:08] 1 to 8. If it was other index, then accordingly we can manage, but we have to take the extreme [01:02:14] values for calculating the cross sum. So, for cross sum of this, we have to move from [01:02:20] this side to this. So, what is the value? 20 from left and what is the value from right? [01:02:27] That is, because we have to go extreme, so that is minus 4. So, cross sum is what? 16 [01:02:34] we are getting. We have 16, we have 25, we have 18. What is highest? That is 25 and its [01:02:41] index are 1 to 3 so a 1 to 3 summing value of 25 is the resultant uh summary for this problem [01:02:51] now i will take the queries so basically in this slide as you have seen like 20 uh you have taken [01:02:58] the left sum to come out to be 25 right so it is indexed from 1 to 3 and the left sums uh come out [01:03:05] to be like uh 5 to 8 so basically we'll be taking the whole array for the cross sum right [01:03:10] yes yes yes okay so basically because extreme extreme we have to get so extreme is one and [01:03:16] extreme is eight so so basically it is like again traversing the whole area right for the sum but [01:03:23] this is not repeating for entire because if you see the larger problem now so there the number [01:03:27] of index is reduced yeah so but basically there can be a case like in the worst case there can [01:03:34] be a scenario where you have to calculate the sum for it yes yes yes yes okay moderator is not [01:03:45] working today i guess i make monica so just enable mic one by one for those who are raising query [01:03:52] and yes and ran i guess so i enable mic for you and if you can ask yes yes am i audible sir yes [01:04:11] Sir, I have a question. [01:04:15] So, like, can you go to the slide one, sir? [01:04:18] Sir, like, apart from the first, like, top level at 20, minus 7, 12, [01:04:24] in the bottom nodes, like, there, like, this cross sum can be considered as the sum of all the elements, right? [01:04:32] When there is, yes, yes, when there is only one element in left side and only one element is right side, [01:04:38] so, simply the cross sum is the sum. [01:04:39] oh okay so but for 20 minus 7 [01:04:44] 12 minus 5 also like it can be considered [01:04:48] as a sum of all the elements [01:04:49] no no so there you have to calculate the cross sum [01:04:51] okay okay [01:04:54] we are stopping at 3 third index not going to the fourth [01:04:57] if you remember if you remember this [01:04:59] thank you thank you [01:05:13] yes Varun you can ask [01:05:14] Well, I was, although it gets more clarify after your second example, but just to recheck one more thing, sir, idea is to get the highest sum possible from the short, from the array, that's the idea correct. [01:05:39] whether we go for a let sum or right sum [01:05:41] we are trying to find at the end [01:05:43] a short [01:05:45] the sub array [01:05:47] which has the maximum sum [01:05:49] possible in that sub array [01:05:51] yes yes yes [01:05:52] ok sir that's what I want to say [01:05:55] thank you [01:05:56] yeah Varun so can you help me [01:05:59] as a moderator just enable mic for [01:06:01] so I am with me [01:06:02] ok I can help [01:06:04] so I am giving you the permission of presenter [01:06:07] then [01:06:07] then that's all because i can only see few hands on my screen and you can help me out [01:06:15] to enable mic one by one then i will answer yeah one second i will do it give me a second [01:06:25] given you can go ahead please sir why we are calling it is a problem maximum [01:06:38] server problem cross-up problem is that i think it is given some that i want to know [01:06:42] first i have two questions first i want to know why it is a problem [01:06:46] so maximums are very problem because if you see the we have started with a very basic example of [01:06:53] the share market if we have to buy when and sell when so you will get an element of plus and minus [01:07:00] sorry positive as well as negative elements so if we intend to find a set that is having the [01:07:06] maximum sum so that's why it is called as a problem every time we get a problem of sorting [01:07:12] we get a problem of searching so like that suppose just in a suppose i in a company they [01:07:20] want to calculate that earning some in some quarter correct they will calculate the maximum [01:07:25] earning in some quarter correct that is maximum so that is some it is advantage correct so why [01:07:30] we are putting it a problem that is my ask okay so it is a problem because it probably you see [01:07:35] let i let me ask you one thing what is the profit of the uh maruti shares in last one year so this [01:07:43] is a problem i'm giving to you and you are solving by okay if you make a jump i got it that is an [01:07:49] problem in a project scenario they are saying yeah that is not a de-marriage that is a problem [01:07:55] in general they are saying what is it yes yes and some same way sir i able to understand maximum [01:08:02] problem in a practical scenario can you just relate this cross [01:08:05] problem just a practical example [01:08:09] maximum are you able to relate yeah so let me consider the share price [01:08:14] of the maruti for last 12 months so in first 6 months [01:08:18] okay initially in gen feb and march the price was [01:08:22] negative in april may and june the price was [01:08:26] positive and in july august the price was positive [01:08:30] again in september october november it was negative okay so if you go for the first half [01:08:36] so you may get negative number you may get very less profit you if you consider second [01:08:40] two quarters so you are getting but for the mid mid quarter you are getting the maximum value so [01:08:46] where if you want to analyze where the market share were receiving the highest value due to the [01:08:51] marriage season or due to the some increment in the people's salary or something anything we can [01:08:56] do so in that two quarters the shares was quite high so overall if you want to calculate when [01:09:02] this maruti share were profitable in general so anyone can say that it is from april to august or [01:09:08] april to september quarter otherwise you can not you should not buy that in that season the maruti [01:09:14] shares pop up so you can buy it getting or you should buy in jan and sell in august so that kind [01:09:20] kind of scenario is applicable for it. [01:09:22] Yes, sir. Thanks, God. I got it, sir. [01:09:24] Thank you, sir. [01:09:27] Jayashree, can you go next, please? [01:09:30] Yeah. [01:09:31] Sir, in the first [01:09:32] bigger question that you have taken, [01:09:34] we took the cross sum [01:09:36] from A4 to [01:09:38] A11. Yeah. Like we [01:09:40] had to take. So, in this, sir, [01:09:42] there are eight elements. So, will we [01:09:44] take mid as [01:09:45] seventh position [01:09:48] or if we take like that, [01:09:50] the maximum comes differently but whereas if we take the entire sub array for example [01:09:56] like the maximum sub array should be 18 to 12 yeah so i'm i'm like a bit confused if [01:10:03] like from 20 to 20 minus 3 minus 16 23 uh 18 20 minus 7 12 if we take this the mate [01:10:12] it will come as minus 23 okay so if we take my uh from here the sum from the left will be [01:10:20] like minus 23 only maximum and the right will be maximum of 43 yeah so so if i take median [01:10:31] anywhere so your left sum and right sum will disturb but aggregated cross sum will be same [01:10:36] getting? No, sir, it will be different. No, like if we take a test, like can you just solve that [01:10:42] alone, sir? Just give me the numbers, okay? Okay. Yeah. Yes, tell. 20. 20. Minus 3. Minus 3. Minus 16. [01:10:55] Minus 16 [01:10:57] Minus 23 [01:10:59] 18 [01:11:02] 20 [01:11:04] Minus 7 [01:11:05] Minus 7 and 12 [01:11:07] 12, yeah. [01:11:09] Yeah. [01:11:09] Then, what you are saying? [01:11:14] Taking median as 18 rather than taking 20, what you are saying? [01:11:20] Median over here should be 23, no sir? [01:11:23] Yes, yes. [01:11:23] so if we take the left maximum should be minus 23 [01:11:29] ok [01:11:30] the right should be 43 if we add everything [01:11:36] ok so from 23 you are saying go this side and from 23 go this side [01:11:43] correct sir [01:11:44] yeah so don't take 23 on the right half ok rather than taking on the left half that you are saying [01:11:51] Sir, what I mean to ask is, like in the big array that we had taken, 18 falls on the left side. [01:12:01] And from this 20, it will go on the right side. [01:12:05] Okay, so 18 fall on the right. [01:12:07] Okay, consider this as sub array and this as sub array. [01:12:10] Getting? [01:12:10] Yeah, correct. [01:12:12] So, if we take in this case, from 18 to 12, we will get the maximum sub array. [01:12:20] Okay. [01:12:20] but if we take like a sub segment for the cross sum that is 20 to 12 [01:12:29] the medium should be like int of length by 2 no so it should be like 4 should be at left 4 should [01:12:35] you are saying like this one this would be the median okay so this strategy n by 2 plus 1 you [01:12:41] have to adopt in all the lower branches then when you can comment on this one okay so just do solve [01:12:47] this considering n by 2 plus 1 as median then you will get same result. I am totally 100% [01:12:54] confirmed but you should not at intermediately you cannot change anywhere. If I am following [01:12:59] n by 2 so you should use n by 2. If you are following n by 2 plus 1 so use that one otherwise [01:13:04] you will get a different result. But surely you will get same result of 25 only solving [01:13:09] this or that mechanism. So just do one problem take n by 2 plus 1 as median and consider [01:13:17] that median has left part and other as right then you will see after some entire calculation [01:13:22] you will reach to same solution getting okay yeah so there that is not a conclusion point [01:13:29] whatever the mechanism of median i am taking it should be common to all the state okay so maybe [01:13:34] possible this survey that we are right now witnessing will be different okay because we [01:13:39] will not go beyond 18 in this survey we will not go beyond 18 and here we will not go beyond here [01:13:46] we will go till 12 okay okay so just do it okay or if you have a doubt then i will solve because [01:13:57] we have some time so for this part okay if i consider this and taking all these in the left [01:14:04] half so the sum is what 20 and here for here if you see about this the maximum possible sum is [01:14:12] how much 38 well 50 43 you are saying right sum is 43 okay so if i hadn't missed if i have missed [01:14:25] something so if you see 18 was yeah 18 is there in here okay okay so it is the division aspect [01:14:37] now so just follow for all the steps if it is not clear in the tomorrow's class i will solve [01:14:41] one problem taking n by 2 [01:14:43] plus 1. Okay. Okay. Any other doubt? [01:14:47] That's it, sir. [01:14:48] Yeah. So, Rishish, can [01:14:53] you go next? So, yeah, [01:14:55] yeah, I'll go. Hello, sir. [01:14:57] So, I have one doubt, sir. Can you go to the next [01:14:59] problem which you have solved? [01:15:01] The smaller one. Smaller one. [01:15:03] 20, yeah. 20 minus [01:15:05] 7, 12 minus 5, that one. [01:15:07] Sir, so here my question is [01:15:09] like in the second part, the second division [01:15:11] that we have, the 20 minus [01:15:13] 7 12 minus 5 and on the other hand we have minus 20 to 15 minus 4 and 7. So sir like here we are [01:15:20] getting like the left sum as 25 and right sum as I think 18 right. So let's say what we are actually [01:15:27] doing we are doing this thing just to get the indexes right only to retrieve the index so that [01:15:32] we can later on we can fetch its value yes yes. Okay so that we can go to the top array and we [01:15:40] can understand to what extent [01:15:42] we need to take it, we have to [01:15:44] take the values and find the sum [01:15:46] yes, yes, yes, okay [01:15:47] okay, sir, that's it [01:15:50] yeah, hi sir, good morning [01:15:54] yeah, I'm having [01:15:57] an issue here only [01:15:58] so where we are having left sum equals to 25 [01:16:01] and right sum 18 [01:16:02] so here we [01:16:04] have not calculated the cross sum [01:16:07] how we [01:16:09] are calculating from the below to top [01:16:10] I mean bottom to top we are calculating everywhere [01:16:12] left sum as well as the right sum [01:16:14] right sum yes yes and then cross sum [01:16:16] also yes yes [01:16:18] so here we have calculated the left sum [01:16:20] 25 right sum 18 [01:16:22] yes sir [01:16:23] yes yeah here here then [01:16:26] we are not calculating here cross sum [01:16:28] no no we are calculating [01:16:30] this is left sum for bigger array [01:16:32] and right sum this for this array this is [01:16:34] left sum and this is right sum so [01:16:36] then we are doing a cross across the [01:16:38] index so here it is [01:16:39] 1, 2, 3 and here the index is [01:16:42] something [01:16:44] till 8. So from 1 to [01:16:46] 8 we have to consider the [01:16:48] entire array for calculating the cross sum. [01:16:51] But [01:16:52] that I got it. [01:16:54] But the left sum, whatever the 25, let's say [01:16:56] 3 index is [01:16:58] 20 minus 7 and 12. [01:17:00] That should be the [01:17:01] responsible for the cross sum. Why we are [01:17:04] taking a point in between? No, no. So in cross [01:17:06] sum, it is what? [01:17:08] a 1 2 3 and another one is a 5 to 8 something let us say or something else. So, extreme [01:17:18] one is what? 8 1 and here extreme one is what? 8. So, therefore, we have to use. So, we [01:17:24] have to take the extreme ends of both the left sum, highest left sum and highest right [01:17:28] sum and in between we have to search the cross sum. Getting? If I just write, because this [01:17:36] is the algo part, this is just a concept wise I am saying, but in algo it is happening, while [01:17:40] taking or while doing cross sum, we have to consider extreme index, index of left sum [01:17:58] and right sum, this is important. So, this is not a concept, this you will, if you can [01:18:04] see the algorithm you will always find that okay so here if you see in the algorithm mid [01:18:12] down to low and mid plus one to high so that that we are doing down to lowest index and [01:18:19] down to highest index of the two sub-airies so that is there i hope you got it check once [01:18:27] more right more i'll ask again sir no no so just seeing this algorithm what this algorithm [01:18:32] is do so from mid we will go to the lower and check out the maximum possible sum okay so the [01:18:38] lower index will be the lowest index of the left sum and here the highest index will be the highest [01:18:43] index of right sum so from mid down to low and from mid plus one down to up to high it's a simple [01:18:55] example if for a one two three i am getting the maximum value that was 25 and for a five to eight [01:19:05] i was getting the maximum value that was 18 clear now if i want to calculate the cross sum then i [01:19:12] will calculate for a one to eight because i have to take the extreme of this and extreme of this [01:19:18] and if you see on this so if i am getting left some highest for this and right some highest for [01:19:24] this so cross sum will check out possibility in this direction as well as in this direction [01:19:29] i have one question so in the short smaller example which you have gone through yeah [01:19:47] um we have calculated cross sum from bottom to top uh cross sum as 25 and uh cross sum as 18 right [01:19:58] yeah but i don't um again we have where are we using that cross sum at the top layer [01:20:05] yeah the cross sum for this one is 25 and its index are a 1 2 3 the cross sum for this one is [01:20:16] 18 that is 15 4 and minus 7 that is 6 to 8 a of 6 to 8 okay that is clear now this cross sum [01:20:27] for this portion will become the left sum for the bigger array that is 25 and this cross sum [01:20:33] will be this 18 will become the right sum for the bigger array that is 18 getting [01:20:38] then we have to [01:20:41] calculate the cross sum [01:20:42] so cross sum [01:20:43] is the highest [01:20:44] for this label [01:20:45] that become [01:20:46] the left sum [01:20:46] for the upper label [01:20:47] got it [01:20:49] ok [01:20:49] so those who have done [01:20:52] can leave the class [01:20:53] because we are [01:20:54] around 935 [01:20:56] and those who have [01:20:57] query we can take [01:20:58] one or two more [01:20:58] yes [01:21:01] so cross [01:21:02] so a cross sum [01:21:04] becomes a left [01:21:05] sum [01:21:06] when we proceed [01:21:07] upward [01:21:07] when we [01:21:08] Thank you.