[00:00:01] Okay, so let us start. So, in the last class, we were discussing about maximum sub-array problem. Okay, so here maximum sub-array refer to set of values stored in an array with both negative and positive signs and we need to identify a subset whose sum will be maximum. Okay, so discussing about maximum sum. So, we have two sub-arrays. [00:00:37] identify a subset whose sum is maximum. So, if there is one positive number and all are negative [00:00:58] in an array, so you need not to bother anything, just the positive number will be the [00:01:03] maximum summary. Okay, because that is the only positive number and if you include any other [00:01:10] number whose are negative so obviously that number becomes the that numbers becomes the [00:01:19] maximum sum then yesterday we have also witnessed brute force and divide and conquer based [00:01:36] mechanism in brute force we have used some heuristic we have used some heuristic that is [00:01:48] to minimize the search space, to minimize the space, to minimize the search space. [00:02:07] Okay, so the problem was we have removed the reoccurrence of elements or duplicate entities [00:02:20] and thereby we have reached to the computational complexity of order of n square. [00:02:26] Then we have started discussion on divide and conquer, okay, [00:02:32] that imposes a computational complexity of n of log of n. [00:02:37] The divide and conquer strategy primarily rely on the similar feature [00:02:41] what we have studied in merge sort and fix sort, [00:02:43] dividing the subarray into the smaller component [00:02:46] till we have reached to a single element label. [00:02:48] So the base condition of the recurrence is what? [00:02:56] when we reach to single element label. And then we will do what? Then we will identify left sum, [00:03:13] right sum and cross sum. So, left sum is single element, one right sum is that and if there is [00:03:21] one element then cross sum will be just the addition what yesterday we have seen. But when [00:03:26] it is applicable when there is one element and here is one element. And later on we will decide [00:03:32] and in cross sum what we have identified, from median we will go this side and from median we [00:03:37] will go this side and whatever the maximum possible sum value in the left side, maximum [00:03:41] possible value in the right side will be added, Ls plus Rs will be added to get the cross sum. [00:03:48] Okay, so this was the logic and as we have seen the sub array can be on the left sub half or [00:03:59] right sub-half or on the intersection. [00:04:07] Okay. [00:04:09] Then, this is the algorithm. [00:04:17] Okay. [00:04:20] To find. [00:04:20] So, here it is written if high is equivalent to low, this means that we are having one [00:04:26] number. [00:04:26] Then, we will return what? [00:04:27] Low, high and A of low. [00:04:29] A of low means that the array having one value. [00:04:33] That is the, this is, this condition is called as the base case also written, base condition. [00:04:41] Otherwise, what we will do? [00:04:42] Here we are using floor. [00:04:46] Floor of something. [00:04:47] You can use int. [00:04:48] You can also use ceiling. [00:04:51] That is totally up to u. [00:04:53] Then we are doing what? [00:04:54] Left low, left high and left sum will be again coming from a low mid. [00:05:02] That is half. [00:05:03] This is a mid plus 1 and high. [00:05:06] Again that is half. [00:05:07] And for cross sum what we are supplying? [00:05:10] A, low, mid, high. Okay. Then it will call. And after, so this will be a recursive call [00:05:19] to the same function. And this will be the recursive call for cross sum. What we have [00:05:27] did? From left, from median, we will go to the right. From median, we will go to the [00:05:34] left then what we will do we will check out we will check out maximum sum this side and this side [00:05:50] so this this is a functionality of the find crossing survey okay then we will check if left [00:05:56] sum is greater than right sum if left sum is greater than cross sum so result will be what [00:06:01] left sum otherwise right sum otherwise cross sum so what we were doing there could be left sum [00:06:06] highest right sum highest or cross sum highest whichever is highest will be your result so this [00:06:12] is how the algorithm proceeds and there is one more part for this one that is called [00:06:15] maximum crossing subarray and that imposes the computational complexity of order of n [00:06:22] because if you see what we are doing from the median we are maximum going what n by [00:06:30] 2 and here we are going n by 2 for calculating the sum so that is why it imposes the complexity [00:06:37] of order of n. And this recursive division imposes log of n and these one or two comparisons [00:06:47] we can say it is 2 or something. So it is n of log of n plus 2 or something. So this [00:06:53] could be ignored and ultimately the computational complexity reaches to n of log of n. So this [00:07:01] is one problem, the same problem that we have addressed today. I have tried to solve via [00:07:07] the discussed algorithm. So, just try to follow because it is a bigger problem of 16 elements. [00:07:15] So, you may, it will take longer time. So, this is totally up to you. You can take 5, [00:07:22] 6 element sub-array and try to identify the maximum sum. Okay. So, before starting the [00:07:29] dynamic programming variant. I am showing you this example again with indices. So now we have [00:07:38] 13, minus 3, minus 25, 20, minus 3, 16, minus 23 and 18. We have to identify maximum survey array [00:07:55] for this. Now, we have divided. So, we have reached to this situation. 13 minus 3, minus 25, [00:08:20] 20, minus 3, 16. And they have indexes 1, 2, 3, 4, 5, 6, 7 and 8. So, this will help to identify [00:08:32] the from where to where we can have, we have to identify the cross sum indexes. So, 30 left sum [00:08:40] is 13 so we will see what low high sum this is low high and sum value similarly from this side [00:08:53] we will have low high and sum value that is 2 2 minus 3 so which one is highest this one is highest [00:09:02] because cross sum if you calculate the it will be what 1 2 10 this is cross sum this is initial [00:09:10] index this is longest index and this so ultimately after this we will get this as the solution that [00:09:16] will propagate and here these are the lower lower index higher index and the sum what we are exactly [00:09:22] doing yesterday then from this side 25 20 so we will get 4 4 20 so the right sum is now 20 and [00:09:31] here left sum is now 13 okay so for cross sum what we have to do lowest of this and highest of this [00:09:39] So, it will be 1, 4, 10 this side. [00:09:58] So, from here, if we are going, so what we will get? [00:10:03] 10 this side and here we will get minus 5. [00:10:07] One thing. [00:10:08] Second thing is that if we take 25 as medium value, what yesterday someone was asking, [00:10:13] then what will happen? [00:10:14] 20 this side and 28 minus 28 and 13. [00:10:25] That is minus 15. [00:10:27] So, I guess this may be wrong. [00:10:29] Okay. [00:10:29] So, what we are getting? [00:10:31] 10. [00:10:32] And this side we are getting minus 5. [00:10:33] So, we are getting what? [00:10:35] 5. [00:10:35] Okay. [00:10:36] So, among these 3, which one is highest? [00:10:38] So, among these 3, this 20 is highest. [00:10:41] That is 4. [00:10:43] 4, 20 will proceed upward. [00:10:46] Similarly, for this, we will get likewise this. [00:10:48] And similarly, for this one. [00:10:53] So, just check it out. [00:10:54] Maybe some mistake is there. [00:10:56] Okay. [00:10:56] so what basically we are doing we are doing what we are calculating the cross [00:11:03] sum so this is was shown to get the lowest index from the left one and [00:11:08] highest index from the right one yes okay highest index from the I guess I'm [00:11:20] audible okay now there's some issue I'm audible okay okay I'm audible there was [00:12:04] some issue. My screen will have stopped shared. Okay. Let me continue. Okay. So, now what [00:12:10] we are basically doing. Okay. And there was one more confusion yesterday before going [00:12:14] proceed. Further, I was just doing it. So, one more confusion is there. So, for identifying [00:12:52] the mid, here we are taking what? Ceiling of low plus high by 2. Floor of low plus high [00:13:05] by 2. That is low plus higher index by 2. So, that you can use. And median, median you [00:13:14] can use n by 2 for even n, n by 2 plus 1 for odd. Okay. So, just check out these two, then [00:13:24] your problem can be solved. Okay. Now, here it is saying how the time complexity is calculated. [00:13:34] Okay. So, this one and this one we can ignore. And every time we are trying to do what? We [00:13:46] are trying to get two sub-problems and the cross sum that required order of n computational [00:13:54] complexity. And if you witness the recurrence relation, the recurrence relation is as similar [00:14:00] as merge sort and therefore the computational complexity reaches to n of log of n. [00:14:06] Now, we have seen two algorithms. One is brute force whose computational complexity [00:14:28] we have identified n square, then we have divide and conquer whose computational complexity [00:14:33] is n of log of n. The good thing about this maximum subarray is that there exists also [00:14:39] a dynamic programming algorithm. Okay, so before starting the dynamic programming, I [00:14:44] will just briefly say about what is dynamic programming. We will see separately other [00:14:51] problems as well in the dynamic programming, but the dynamic programming variants of algorithms [00:14:57] are faster. Second thing is these algorithms are faster and we know that what we have did [00:15:07] in divide and conquer big problem is splitted into smaller then is splitted into much smaller. [00:15:14] So, this is basically a top down approach or problem solution will be from top to down this [00:15:25] is divide and conquer okay and i am talking about dp dp are faster but in case of dynamic programming [00:15:34] we are primarily following what bottom to up okay so here basically divide and conquer what we were [00:15:43] doing dividing a larger problem into smaller sub problems and subsub problems then solve them and [00:15:50] go ahead. DP say that I will solve smaller variant of problems, aggregate them to get [00:15:57] the final variant and lastly I will aggregate to get the final result. So, though they look [00:16:03] like similar, one more important thing is that at each stage, it preserves the outcome [00:16:09] of the previous state. [00:16:12] So, at each step, it stores the outcome of previous results. [00:16:33] Now, it is storing the outcome of the previous results. [00:16:38] So, what will happen? [00:16:39] Let us say at step 1, it store O1 operation, O2, O3, O4 output. [00:16:50] So in step 2, it will automatically reach to a solution where it need only O2 and O3. [00:16:58] Means that it will curtail down the insignificant value at each step. [00:17:02] or we can say the dynamic programming, identify or get the best value possible at each step, [00:17:11] best value, best result possible at each step. So on each step, if you check, you will find [00:17:22] available and as it proceeds, the results are proceeding. So in each step, you will find the [00:17:27] resultant will be the best one. So we will also see in detail how this is working. So there is [00:17:33] one thing that they are faster. Dynamic programming are faster. And one thing is that [00:17:38] memory inefficient. Memory inefficient because it stores the result of all the previous outcome [00:17:50] or all the optimized outcome in each step. Now, one more question arises. Sir, you are saying [00:18:01] in divide and conquer also, we are, when we are proceeding upward, we are storing these results. [00:18:08] Okay, now think about a situation when we are solving a problem different. [00:18:14] Okay, we are following bottom-up approach. [00:18:18] So, I store this result, this result, this result, this result, then I will change the label. [00:18:25] Okay, now I will store this result, this result, then I will change the label. [00:18:31] So, we are having all the outcomes of the sub-problem saved. [00:18:36] or in each step. So, that's why on cost of memory, we are getting a faster algorithm [00:18:49] and if we compare with the processing speed and the memory, so we are now having sufficiently [00:18:55] large amount of memory. Thus, we can say that dynamic programmings are more viable in current [00:19:01] word scenario. And you will find that this DP variant will impose a computational complexity [00:19:08] of order of n. Again, I am saying I will explain this dynamic programming algorithm in a detailed [00:19:14] one after some time. So, let us begin the problem. So, the cadence algorithm, this famous algorithm [00:19:24] that is a dp variate for solving the maximum subarray problem. [00:19:28] So, that is cadence-ergonic. [00:19:35] This is the only simplified algorithm. [00:19:43] So, we have to initialize two variables, [00:19:46] that is current sum, I am writing as cs, [00:19:49] and max sum, that is m. [00:19:52] These two values, we have to do an initialization. [00:19:55] Some initial value, let us say, [00:19:57] let us say, I am taking first index, [00:19:59] or any of the index. So, this is the initialization on the first index. [00:20:12] So, as if you remember in case of insertion sort also, we were taking the first value, [00:20:18] okay, as a reference point, similarly here we are taking the first index as the decisive point [00:20:27] and we are identifying, we are taking current sum and max sum as the first value. So, what we have [00:20:35] it cs is equivalent to ms is equivalent to the array first index element that we have stored. [00:20:45] Now what we will do for starting from the second position iterate throughout the array so of course [00:20:51] it will be a for loop or a while loop whatever you want. So for each element what we are doing [00:20:57] current sum is nothing but maximum of current element. Current element means that the element [00:21:07] as index number 2 comma current element plus current sum. Then we are updating max sum [00:21:14] equal to max of current sum at max sum. So these two steps you have to remember then [00:21:19] you can easily solve any problem via cadence algorithm. So simplified version I am writing [00:21:25] for 2 to n. What I am doing? Current sum is nothing but max of current element comma current [00:21:38] element plus current sum and max sum is nothing but max of current sum comma max sum. So, these [00:21:51] two steps you have to remember and surprisingly if you see there is a single for loop that is [00:21:57] running for n minus 1 time and thus the computational complexity of this variant of the [00:22:04] maximal saveria or dp variant or the cadence algorithm will reach to only order of n because [00:22:10] here we are not making any more complicated multiple for loops or recursive division. [00:22:17] So that is the great thing about the cadence that it imposes only a computational complexity [00:22:23] of order of n. [00:22:24] So, if you remember, this you have to say, current sum, maximum of current element, current sum plus current element. [00:22:36] So, what I will do, I will try to solve this problem via the cadence. [00:22:43] Just remember these two looping steps. [00:22:46] So, just give me a minute, I will write down the problem. [00:22:49] Then we will start the solution. [00:22:51] Afterward, I will take the queries. [00:23:40] I am writing. [00:23:40] So, here the algorithm that is or 2 to n or 2 to n what I have to do, current sum will [00:23:57] be replaced by max of current element comma current sum plus current element and max sum [00:24:13] will be updated as max of current sum and max sum. These two things we have to update otherwise the [00:24:23] algorithm remain intact. And we have a problem that is minus 2, 1, minus 3, 4, minus 1, 2, 1, [00:24:39] 1 minus 5 and 4. So, let us solve. So, you know that in initialization current sum and max sum [00:25:04] will be the value stored as the first index. So, I have initialized. So, current sum equal to max [00:25:12] sum equal to minus 2 initialization. Now, we are starting with for i equal to 2 first condition. [00:25:20] so what we will do current sum is equal to max of what max of current element so if you see [00:25:28] second index we have current element 1 comma 1 minus 2 which one is highest of course the value [00:25:38] will be 1 because this will be minus 1 now max sum is equal to what max of max sum and current sum [00:25:47] So, this and 1, of course, we will get a value of, I guess you understand, it is current [00:25:53] sum 1, okay, I have just written reciprocal. [00:25:57] So, current sum is 1 and max sum was earlier, if you know, its value was minus 2. [00:26:03] So, what we will basically get 1 as the resultant, okay. [00:26:06] So, step number 1 is over, then we will do what? [00:26:11] i equal to then i equal to 3. So, current sum equal to max of current element. Now, [00:26:29] the cursor is shifted here. So, current element is minus 3 and current element, [00:26:36] current sum that is 1 minus 3. So, what we will get? Minus 2 as the current sum and max sum is [00:26:46] equal to max of current sum that is minus 2 and max sum was 1. What is the maximum? 1 and if you [00:26:55] see for these three part the maximum possible value is 1. So, that we are getting. Now cursor [00:27:01] has shifted here and we have shifted i equal to 4. So, current sum is equal to max of [00:27:09] max of current element that is 4, then 4 that is current element plus current sum. So, 4 plus [00:27:22] minus 2. So, what we will get? We will get 4 as the resultant. Then max sum equal to max of [00:27:30] what? Max of current sum that is 4 and this one is 1. So, what we will get? 4 as the resultant. [00:27:40] Okay. Now, i equal to 5. So, cursor shifted here to minus 1. So, current sum equal to max of [00:27:50] current element that is minus 1, current element minus 1 plus current sum 4. So, what we will get? [00:27:58] 3 as the current sum and max sum equal to max of current sum that is 3 and max sum that is 4. [00:28:12] So, we will get 4 as the resultant. Now, at i equal to 6, we will get the pointer shifted here. [00:28:21] So, current sum equal to max of current element and current element plus current sum that is 5. [00:28:33] What we will get? 5 and max sum equal to max of 5 from a 4 then we will get what? 5. [00:28:42] Okay. Now, the next element is 1. So, i equal to 7, current sum equal to max of current element [00:28:56] that is 1 and both addition will be 6. So, we will get 6 as the current sum and max sum equal to [00:29:03] max of 5, 6. So, obviously, it will be 6. Okay. So, then we will shift to this one [00:29:12] that is minus 5 okay so I am just trying to do if I can [00:29:20] so i equal to 8 what we will get current sum equal to max of what current element that is minus 5 [00:29:32] and when we will add minus 5 with the current sum what we will get 1 so it will be 1 and max sum [00:29:38] will be what? Maximum of 1 comma 6. So, obviously, the resultant will be 6. Then, i equal to 9. The [00:29:49] pointer is 4. That will be max of 4 comma 4 plus 1 5. So, obviously, it will be 5 and max sum will [00:30:03] be 5, 6, the resultant will be 6. So, for this sub-array, the maximum value is possible [00:30:10] when we are getting these sub-array, that is 4, minus 1, 2, and 1. And the value is [00:30:21] 6. Okay. So, but the good thing is that this algorithm is taking order of n computational [00:30:28] complexity. Now, I will take the queries. So, Rakesh, you can enable mic for those who [00:30:35] raising hand and then we will proceed i hope rakesh you are there just give me i'm enabling [00:31:04] one by one just rakesh you can intervene uh yes uh anuja uh sir good morning sir good morning [00:31:14] so just wanted to understand two things uh like how this 2 to n is being implying here and second [00:31:20] thing is the initialization step like when we have this right this error so i'm just trying to [00:31:27] get there if you can just give a dance actually actually if you see the algorithm so what it is [00:31:35] saying this time we're doing this we are starting from the second position and initialization is [00:31:41] nothing but we are declaring current sum and max sum equal to the value stored on the index number [00:31:47] one or zero whatever you are using at the first index okay so i have just used that value and then [00:31:53] moving ahead so what is the maximum values stored in the first element itself so nobody so your max [00:32:00] sum will not change here it is the max sum is max of current sum and max sum so your current sum [00:32:05] change but max sum remain intact so let's say initial 20 is there and others are negative [00:32:10] watch something so so maximum will remain intact okay still if you have problem because let's say [00:32:23] your doubt is there now so others doubt will automatically resolve okay yeah i mean i'm just [00:32:29] trying to make a version again if you can go back to the l you can say the array that will help [00:32:33] so if i say that i have to initialize this so how should i proceed like is it like the minus 2 [00:32:43] and then minus 2 is your first index that we are taking as current sum that is equal to max sum [00:32:49] equal to minus so let's say here we have taken 200 plus 200 so never this max sum will change [00:32:54] so that will be of course first value will be the result and iteratively when we go from this 200 [00:33:02] to the next index [00:33:04] sorry [00:33:04] the next indices [00:33:05] so automatically [00:33:05] it is the third index [00:33:07] right [00:33:07] yes [00:33:09] okay [00:33:10] and [00:33:10] is there is any [00:33:12] like a specific [00:33:13] like relationship [00:33:15] say [00:33:15] I'm just trying to understand [00:33:16] more here [00:33:17] like [00:33:17] how it could be [00:33:19] more [00:33:20] more in terms of [00:33:21] 2 to 1 [00:33:22] is it just because [00:33:23] we are saying [00:33:24] it is starting [00:33:24] from the second index [00:33:26] that's why [00:33:26] okay [00:33:27] yes [00:33:27] or because [00:33:28] if you are having [00:33:29] a zero index thing [00:33:30] so you can do [00:33:31] 1 to [00:33:31] and minus 1 [00:33:33] yeah yeah [00:33:35] like any list [00:33:36] we have that [00:33:38] as in 0 [00:33:38] so that's where it is [00:33:40] okay [00:33:40] thank you so much [00:33:43] yes Rohit [00:33:50] yeah good morning sir [00:33:53] sir can you go to that [00:33:55] the example [00:33:55] you were just [00:33:57] okay [00:33:58] so I understood the step [00:34:00] but how you identified [00:34:02] the subarray [00:34:03] like it's starting from [00:34:06] like 4 [00:34:06] as the value [00:34:08] and it goes to 1. [00:34:11] So, for this algorithm, [00:34:14] you will get the maximum sum value. [00:34:17] Okay, maximum sum value. [00:34:18] But the index, if you specifically want, [00:34:21] so you have to add some points to store. [00:34:24] For example, when I am getting 6 here, [00:34:27] okay, when I am getting 6 here, [00:34:29] so I have to look back the previous value. [00:34:31] So, it was 5. [00:34:32] So, it was 4. [00:34:33] Earlier, it was 4. [00:34:34] So, whenever there is a higher positive value, [00:34:38] i store this index and whenever there is increment in that value that i will store that so from this [00:34:43] to this will be the sub array getting what i am saying for this algorithm okay whenever the [00:34:51] maximum value is there a maximum i am also preserving the index so i preserve the index of [00:34:59] 4 i preserve the index of 6 and then use those index to identify the sub array but in this [00:35:06] algorithm there is no such mechanism of directly identifying the indices but what we will do when [00:35:11] the we are storing the maximum we are we also store the maximum the indices okay and whenever [00:35:19] and the for for example i have stored i equal to four okay so here if you go so i will store i [00:35:27] equal to four in some additional array okay and i will store i equal to six seven n so what we [00:35:34] identified that from where to where there was an increment in the value that will be your third [00:35:39] subarray so but there is no direct linkage of identifying that subarray in this algorithm okay [00:35:47] so that we have to explicitly add some steps here so uh so would you would you mind like uh just [00:35:56] like using the indices as such and then expecting it so it would be more clear let's say i initializes [00:36:03] a list okay or that is i or i and i am writing initially it is empty so here the index will [00:36:15] be what 1 then what we will do because that is holding the max value then index is 1 next [00:36:27] Next one is 2 and correspondingly you have to also maintain an output. [00:36:34] So we are maintaining 1, 1, 2 arrays we are simultaneously doing. [00:36:40] So there is output array. [00:36:43] Then here we are using in that is 1, 2, 3 and the output is what 1, 1, 4. [00:36:55] we are storing in that is 1, 2, 3, 4 and the output is how much? 1, 1, 4, 4. Okay. And [00:37:09] similarly, we will store for this one that is 1, 2, 3, 4. Now, after evaluating all what [00:37:16] we have declared the sum is 6. So, we will immediately check into this array where the [00:37:21] 6 was first appearing. So, 4, 4, let us say 5 and 6. So, we identified that its index value was [00:37:29] 6, let us say. So, we identify its index value was 6, where 6 was the maximum sum. [00:37:36] Then we will go back and see that from where the increment was already started. So, we identified [00:37:42] the first increment that we have encountered was 4. So, that is an, you can say, [00:37:47] The assumptive algorithm not exactly exists in this cadence. [00:37:51] So you have to modify the algorithm accordingly. [00:37:54] Getting. [00:37:55] So that is not there in cadence. [00:37:57] You can store the values in two surveys and accordingly take your decision. [00:38:02] Okay. [00:38:03] Getting. [00:38:04] Yeah, I got it, sir. [00:38:06] Sir, I have the question related to the divide and conquer. [00:38:10] Can I ask that, sir? [00:38:12] Yeah, please. [00:38:12] so so in that strategy like you you have said like we divide the array like in two from the [00:38:20] median value right yeah so like if if like when we reach the top and if we have the the left sum [00:38:29] and the right sum that that are equal so how do we identify that like which sub array we'll have [00:38:37] to take like in any case like if just see this if left sum is greater than or equal to right sum or [00:38:44] left sum is greater than or equal to cross sum so obviously it will be left sum so this equality sign [00:38:50] is always there so we will solve either if or else if or as getting equality we can take any [00:38:58] any somewhere you are saying like or it has to be always left sum i'm saying if you go with [00:39:04] strictly with the algorithm [00:39:05] so always the left sum [00:39:06] will be taken up. [00:39:08] Okay. [00:39:09] Otherwise you are free [00:39:10] to take any [00:39:11] because ultimately [00:39:12] you have to give the [00:39:13] output, [00:39:15] highest output. [00:39:16] Either it is appearing [00:39:17] in left side or right side [00:39:18] that is, [00:39:19] both are correct. [00:39:21] Both are correct. [00:39:21] Okay. [00:39:22] Got it, sir. [00:39:23] Thank you, sir. [00:39:23] But if you strictly [00:39:24] follow the algorithm [00:39:25] then you have to [00:39:25] choose the left one. [00:39:27] Okay. [00:39:27] Thank you. [00:39:35] Yes, Suraj. [00:39:38] Good morning, sir. [00:39:39] my question is similar to the last question [00:39:42] can you [00:39:44] re-explain the [00:39:45] problem with the for variable [00:39:48] as we used to do [00:39:49] current [00:39:50] sum, subarray, maximum subarray [00:39:54] and start and end point [00:39:55] so it will help me to understand [00:39:57] how the subarray will be created [00:39:59] as we maintain the state on start [00:40:01] and end variable [00:40:02] if time allows sir [00:40:05] no no so I am not getting exactly [00:40:08] what so you want that how to identify the indices yeah if you maintain in start and so just simply [00:40:15] simply understand it whenever there is change in value we store the index okay or whenever there [00:40:22] is increment in value we store the index so from one to four there was a change i store that index [00:40:28] and every time we are saying what then it is five then it is six and from six to again it is reducing [00:40:34] to 5 if you see in a maximum so now 6 status is maintained because we are never getting [00:40:40] a maximum value so whenever there is an increment and we store that index and whenever there [00:40:48] is change in value that is 5 to 6 we store the index so this index and this index will [00:40:53] be the subarray now what i am saying sir can you can you if time allows can you re-explain [00:41:00] with the four variables so it will it will better for visualization and understanding yeah yeah [00:41:06] so what i will do just give me a moment we have minus 2 1 minus 3 4 minus 1 2 and 1 i am just [00:41:25] taking okay not going beyond 1 2 3 4 5 6 7 so current sum equal to max sum equal to minus 2 [00:41:34] we are starting with the i equal to 2 let's say current sum equal to max of current element that [00:41:46] is 1 and 1 minus 2 that is minus 1 so we are getting 1 as this max sum as 1 okay not calculated [00:41:54] i equal to 3 so here we have stored index what this is the index variable i equal to 2 okay [00:42:02] now in the here the next step what we are doing current sum equal to max of [00:42:11] minus 3 comma 1 so of course it is 1 max sum again 1 then i equal to 4 we are storing what [00:42:24] current sum equal to max of 4, 4 plus [00:42:31] Sir, sorry to interrupt you. [00:42:34] Can we initialize two more variables so we can manage the start and end variables? [00:42:40] One is index and one is the sum value. [00:42:44] So here index was 2 and the max sum already we are storing. [00:42:52] no need to store here index is 3 and here we will get 4 comma current element and current sum that [00:43:03] is 5 so we will get 5 and max sum is equal to max of current sum and this one so we will get 5 I [00:43:11] guess I am skipping something so here also we are storing so what basically happening there is change [00:43:17] in the value. So, that is from 1, we are getting 5. So, that index I have stored as flag 1 or [00:43:23] something in index array I have marked as 3. Okay, where there was a change in the value. So, [00:43:30] I preserved this value. Earlier, it was 2, then 3 and now we are storing the index number 4. [00:43:36] Similarly, i equal to 5, we will go and at that point, whenever there is change in the value, [00:43:41] we are storing those two values so for example here i was storing index 2 3 4 5 so i will just [00:43:49] store 2 2 because the value is not changing okay simply understand i and t is 2 i and t is 2 because [00:43:57] value is not changing but here when we whenever we get 4 so i and t become that index that is 4 [00:44:02] okay and i have stored it okay now we are moving ahead moving ahead when we are getting 6 first [00:44:08] time then also the value is stored so two values we have stored four and six because these are the [00:44:14] two point where there was change in the value and then we will declare that is the severity [00:44:18] getting okay sir got it still confused then i will because other may be having same problem [00:44:25] so what i will do whenever there is change in value i will store that index so whatever the [00:44:31] mechanism you apply that is totally up to you whenever there is change in the value of max sum [00:44:36] then we will store the value so just i am writing one logic whenever whenever there is [00:44:46] so whatever logic you write that is up to there is change in max sum we will store the [00:45:03] index okay or we can say that in start there will be a value that hold the [00:45:12] that is index start [00:45:14] that is the starting point of the [00:45:16] subarray [00:45:17] point of [00:45:20] subarray and there [00:45:22] will be end finish that is the [00:45:24] end point of [00:45:26] subarray and this is nothing but this [00:45:28] is change in the value [00:45:29] and this two index will treated [00:45:32] as the start and end of the [00:45:34] subarray whose sum is 6 or something [00:45:36] getting it? [00:45:39] yes I got it [00:45:40] next is [00:45:42] Sreya [00:45:44] Sreya I have enabled your mic [00:45:46] hello sir good morning [00:45:49] yes yes you are [00:45:51] so my doubt is that [00:45:53] for the dynamic programming [00:45:55] approach the result that we are getting [00:45:57] is a maximum sum [00:45:58] and you told [00:46:01] if we have to get the [00:46:03] summary of that maximum sum [00:46:04] we will have to store the indices [00:46:06] but that is not provisioned [00:46:09] in cadence [00:46:09] okay so but if our main aim is to find the subarray of that maximum sum will the dynamic program [00:46:17] approach still be better if we are storing the here our target is to identify the max sum sum of [00:46:26] the subarray every time of the sum of the subarray we have to identify it so this cadence is doing [00:46:34] and we can store key if there is change in the sum then that is a start if there is change [00:46:39] in sum, that is the end. So, the two comparison will max to max come. So, that will not hamper [00:46:46] this performance. Okay. So, even if we have a separate algorithm in this, if we add in [00:46:54] the cadence algorithm to find the sub-L. So, that will not impact the computational complexity. [00:46:59] Okay. So, but in each step, what we are seeing is four conversions are making. So, the computational [00:47:05] complexity will what 4n getting 1 1 1 1 1 and for larger value of n the 4n becomes n [00:47:15] yes sir so for its model let's say n is 10 or 6 or 4 so obviously you will find a [00:47:23] bigger value but when n become very large then it will tend towards order of n [00:47:28] okay [00:47:30] yes sir [00:47:33] good morning sir [00:47:37] so basically I have a question [00:47:40] regarding the dynamic programming [00:47:42] and divide and conquer I don't know [00:47:44] might be this is the good time to take that question [00:47:46] just ask [00:47:48] so basically in divide [00:47:50] and conquer we know that we divide [00:47:52] the problem into sub problem basically [00:47:54] for solving the problem we [00:47:56] used to do the bottom up approach right [00:47:58] yeah [00:47:58] and in the dynamic programming it is also the same we are following the bottom up approach [00:48:04] yes and in divide and conquer if we see we have the extra spacing that we take every time we [00:48:10] try to solve a problem this is what happens in the dynamic programming as well so sir i don't [00:48:15] so how can it become faster and memory inefficient in comparison to divide and conquer [00:48:24] That's my question sir. [00:48:26] Good, good. Now, if you see faster is clear, I guess from the last example, you need not to worry about it is n, it is n of log n. [00:48:36] Now, in dynamic program, what we are doing, we are solving this problem, storing the result in temporary storage, solving this right half, temporary storage then. [00:48:46] So, what we are basically doing, this problem I solve, this problem I solve, now this is, [00:48:53] so these results are gone. [00:48:55] Then I will solve these two problem, then this, the temperature is gone and here we [00:49:00] are getting what? [00:49:01] We are getting the result. [00:49:02] Or if I want to explain you a simple example, that will be good to differentiate, so in [00:49:14] divide and conquer we are having this problem. And we are solving like this one. We are going [00:49:21] ahead storing the result in temporary, storing the result in temporary and aggregating here. [00:49:27] Then this, this, aggregating here. Then this, this and aggregating here. So that I hope you [00:49:34] agree. But in DP if I solve this, this, this, this. So what I will do? I will solve for this [00:49:42] label, all the outcome, O1, O2, O3, O4, then I will go to O5, O6, then I will solve O5, [00:49:51] O6, then I will go up O4. [00:49:53] So, at every time, what we have, we are storing all four output, then we are storing all two [00:49:58] output, then we are storing last final output. [00:50:02] So, how the difference is arising? [00:50:04] Here, we solve one part, then we will shift to next part, solve it, store in temporary [00:50:08] and go ahead. [00:50:09] Here we will solve all the sub-parts simultaneously, then we will go. [00:50:13] Getting, first time we solve this, then this, then this, then this, then among these, which is the best case, then that will be propagated upward. [00:50:21] And here what we are doing, we are solving one half, other half and getting back the solution, then this half, this half getting. [00:50:28] So at each instance, what we are doing, we are taking one part and here it is what it is doing, it is solving all sub-parts, then moving ahead. [00:50:36] I guess you got the difference. [00:50:39] But we are moving label by label, label by label, label by label in dynamic. [00:50:43] And in divide and conquer, we are solving one left half. [00:50:47] Then we are shifting to the right half. [00:50:49] Deference, I guess you agree. [00:50:51] I will go like this. [00:50:52] I will go like this. [00:50:54] And here we are going this, this, this, this, this. [00:50:58] So every time we are storing the previous result, [00:51:01] that's created the memory in FSC. [00:51:03] But here we need not to store the result [00:51:05] because we are already getting a solution at each step. [00:51:08] okay so basically if i get it properly it is like dynamic programming is managing the whole [00:51:13] set of the backward uh like yeah yeah yeah yes and while the divide and conquer used to like [00:51:21] forget it of what has done it's just previous operation yeah yes yes yes okay okay so thank [00:51:26] you sir that was my doubt about so we'll take the doubt in another two three minutes [00:51:32] taking a break and then we will start [00:51:34] the next part of this [00:51:36] I am taking your doubt [00:51:41] yes [00:51:42] sir can you [00:51:46] please go back to that first example [00:51:48] yeah [00:51:49] here in this case we considered the starting [00:51:56] point of the subarray as i equal to [00:51:58] fourth index [00:51:58] because there is a shift from ms [00:52:01] from 1 to 4 right [00:52:03] similarly we have [00:52:06] a shift from i equal to 1 to i equal [00:52:08] to 2 right from the initialization to i equal to 2 minus 2 to 1 why are we not considering that [00:52:14] so we have just started with the first index now where the maximum this is the first maximum this [00:52:22] was just the you can say just the previously stored value and here so that is again i'm saying [00:52:29] that is not the cadence you can you can use your mechanism what you can develop for storing the [00:52:34] indices okay that was one of the assumption i was considering okay and another mechanism you can [00:52:40] take of of getting this value so that is not the part of dynamic programming that i was supposed [00:52:45] to provide so you can use any of the mechanism of the thing that you can adopt for identifying the [00:52:51] index but as such cadance does not have any provision of storing the indices of the server [00:52:56] it just give the answer of the maximum value getting okay okay uh yes rithika now you can [00:53:11] enable your mic if your doubts are clear so those who have raised hand can down their hand as well [00:53:22] and if they someone has genuine doubt then i will take it up uh yes rithika i have enabled your mic [00:53:36] you can speak okay uh yes because you can say good morning sir good morning sir i have a [00:53:57] question around time complexity so since we we are trying to find out the max sum [00:54:05] for that we have the time complexity of order of n which i understood but if we want to retrieve [00:54:13] the indices to get the sub array so isn't it the time complexity will change because we have to [00:54:21] compare each index with the prior index so that the that i'm saying key in each step we are getting [00:54:27] more comparison so it will be let's say 4n or 8n okay but if n become very large then that 8n will [00:54:35] shifted to n so that i'm saying i'm not saying it is always n when we try to store the index so it [00:54:41] will also impose some comparisons okay and that will not be the you can say a for loop is running [00:54:49] some if statements are running so that will impose let's say one complexity in each step [00:54:54] so it will be four and five and six and or something but ultimately it will be n [00:55:00] okay so for each comparison it will be order of one yeah and if in each step yeah [00:55:08] yeah but if let's say n tends to infinity or if we have a huge array in that case then then [00:55:15] 4n will become the yeah n okay okay got it thank you okay i hope the doubts are clear now sir i [00:55:25] think rithika have a doubt she posted in chat uh her mic is not working so she was asking how [00:55:30] cadence follow bottom-up approach so uh in uh cadence what basically we are doing we are moving [00:55:38] from one this to this so we are solving sub problems like first two index so if you see [00:55:44] first two index so you will find maximum value is one then first three index maximum value is one [00:55:49] first four index maximum value is four so that's why incremental steps it is identifying step one [00:55:57] step two is we are getting the value of maximum so dynamic programming uh if you see in a different [00:56:05] form or a different angle so what basically we are doing we are storing the previous value [00:56:10] okay so we are storing the result of third we are storing first second and third to get the [00:56:19] result of four and so on so every time we are adding one by storing the previous result so [00:56:24] that is how it is working so because this hierarchical arrangement is only possible in [00:56:29] tree-like problems okay but here we are considering a problem where we are getting we have to identify [00:56:34] the max sum value and that max sum value we are getting iteratively by step by step. [00:56:41] In each step we are getting the max sum, if we consider 2 element max sum is this, if [00:56:45] we consider 3 element max sum is this, 4 element max sum is this likewise, so that we are moving. [00:56:51] So by using the previous result we are moving. [00:56:57] So I guess we can go ahead and no worries when dynamic programming come in its full [00:57:04] fluid form then you will the more clarity will come okay don't confuse so two three [00:57:09] thing important importantly i want to convey one is this cadden algorithm will just give [00:57:15] you the maximum value if you want to get the indices you have to perform some retrofitting [00:57:21] over it second thing is that the dynamic programming is itself a complicated or bigger topic so [00:57:27] when we will go with the dynamic programming we will discuss again these definition and [00:57:32] other aspects. So, at that time, it will be more clearer. So, do not worry about that, [00:57:37] I will surely cover all those things. Now, there is one more interesting thing and I [00:57:46] hope everyone understands that is matrix multiplication and there is one known algorithm [00:57:52] that is called illustration algorithm. So, that we will see how it reduces the computational [00:58:00] complexity from n to the power 3 to n to the power 2.81. Okay, so though it looks very [00:58:07] less value, but in a longer run or a bigger computation, even this much decrement matters. [00:58:14] Okay, so if we perform basic matrix multiplication, we are using primarily three loops, that is loop [00:58:23] inside loop for, then inside that there is another for, inside that there is another for. [00:58:30] So, basically n into n into n, n cube is there and if I take an example, I had a space, okay, [00:58:49] simple matrix multiplication if I perform, if I take two array, one is this one, a11, [00:59:07] a12, a21, a22 and next array I am taking b11, b12, b21 and b22. [00:59:21] If we simply go for a cross b or a into b, then what we will get? [00:59:28] a11 into b11 plus a12 into b21 and here we will get, I hope everyone understand matrix multiplication. [00:59:50] If not, then just see what I am doing. [00:59:53] A11 plus B12, A12 into B22, okay. [01:00:01] Similarly, here we have A21 into B11 plus A22 into B21, A21 into B22. [01:00:26] So, this is how we will get a matrix C that will hold the value of multiplication and in [01:00:33] multiplication we know that n into m and m into k is allowed where row and column should [01:00:40] be matched. [01:00:46] So, what we find the number of multiplication if you count, multiplication you count that [01:01:34] is 1, 2, 3, 4, 5, 6, 7, 8. So, total multiplication is 8 and here with the matrix order was 2 [01:01:43] cross 2, 2 cross 2. So, it is basically n into m into k, that is the total number of [01:01:50] multiplication we follow that is 2 into 2 into 2, that is 8. And therefore, its computational [01:01:58] complexity will be order of n cube, that is 2 cube is 8. Similarly, if we have 4 cross [01:02:04] 4 matrix, then what we will get? 4 into 4 into 4, that is 4 to the power 3 and so on. [01:02:13] So, if this could be the scenario, then we will get the computational complexity in order [01:02:27] of n to the power 3, that is n cube. So, for simple matrix chain matrix multiplication, [01:02:36] we will get always the computational complexity of n cube. So, stressors introduce a mechanism [01:02:43] that says, despite of getting 8 product for 2 cross 2 matrix, what I will do, I will perform [01:02:52] these operations in 7 products, 7 products by increasing addition and subtraction, by increasing [01:03:01] addition and subtractions. So, what he has done, he had defined some steps, he has defined some [01:03:13] steps. Just a minute, there is a small doubt in this or we can say there is a small change in, [01:03:25] So, what he say, if you have to multiply A and B, so rather than directly going for [01:03:31] A's multiplication, perform these 7 steps, then these 4 steps and ultimately you will [01:03:38] get the result. [01:03:39] So, now you can see number of addition and subtraction has increased, but number of multiplication [01:03:45] has reduced by 1 and so total number of multiplication here required is 7. [01:03:50] okay now understand one more thing so here is this is a plus sign okay [01:04:14] so I have corrected because let's say you start solving then you will not start so what what is [01:04:21] the issue here rather than doing this eight product I will do seven product so now one [01:04:28] question is sir how this is a divide and conquer why we are studying here so now I will show one [01:04:34] more example, if I had a 2 matrix of order 4 x 4. The important consideration in stresses [01:04:44] multiplication is that the matrix should be square matrix and they should of order 2, [01:04:49] 4, 8, 16 and so on. 2, 4, 8, 16, 32, 64 and so on. So, now what we can say that a 4 x [01:05:01] 4 matrix is nothing but it is 2 x 2, 2 x 2, 2 x 2, 2 x 2 and similarly another one can [01:05:13] be what? 2 x 2, 2 x 2, 2 x 2 and 2 x 2. So, this is how any bigger, so 8 x 8 will be [01:05:26] combination of 4 x 4, 4 x 4 that is ultimately a combination of 2 x 2, 2 x 2. [01:05:31] So, every time when we get a 2 matrix, let us say we get the 16 cross 16, we will first convert into 8 cross 8, then 4 cross 4, then 2 cross 2. [01:05:40] And when we reach to a multiplication of 2 cross 2, so rather than going a normal multiplication, we will choose these 4 steps. [01:05:47] So, let us do one problem on this and how to check whether this algorithm is working or not. [01:05:54] okay so let me add one slide and then we will solve okay already there is one slide equal to [01:06:14] one two three five one matrix i am taking and v equal to three two one three simple taking [01:06:27] Then I will do a cross or a dot b that is what it is 1 into 3, 1 into 3 plus 2 into 1, [01:06:41] 1 into 2 plus 2 into 3. Then here we have 3 into 3 plus 5 into 1 and 3 into 2 plus 5 into 3. [01:07:02] So, what ultimately we will get? 3 plus 2 that is 5. Here we will get 2 plus 6, 8. Here we will [01:07:12] get 9 plus 5, 14 and here we will get 6 and 15, 21. So, this is the resultant. So, let [01:07:21] us solve this problem via stressors. So, we will calculate P11, you can refer. So, that [01:07:31] is A11 into B12 minus B22. What we will get? A11 is 1 into B12. B12 if you see 2 minus [01:07:49] 3. So, here we will get minus 1. P2, sorry, this is P1, not P11. P1. Now, product 2 is [01:07:58] what? A11 plus A11 plus A12 into B22. So, what is the value? A11 is 1, A12 is 2, that [01:08:18] is 3 into b22 is 3 that is 9. Now p3 we are calculating so that is a21 plus a22 into b11 [01:08:34] So, A21, A21 is 3, A22 is 5 that is 8 into B11 is 3 then we will get 24. Now, P4, P4 is A22 [01:08:47] into B21 minus B11. So, what we will get A22 is 5, B21 is 1, B11 is 3. So, minus 2 minus 10 we [01:09:04] are getting P5 equal to A11 plus A22 into B11 plus B22. So, what we will get? A11 and A22 is [01:09:20] 6 into B11 and B22 is 9. Sorry, 6 again 3 plus 3 is 6. So, 36 we are getting. Okay. [01:09:31] Then P6 is equal to A12 minus A22 into B21 plus B22. [01:09:47] So, what we will get? [01:09:48] A12 is 2, A22 is 5. [01:09:51] So, minus 3 into B21. [01:09:54] B21 is 1 plus B22 is 4. [01:09:57] So, we will get minus 12. [01:10:00] Now P7, the last one. [01:10:02] p7 we will get a11 minus a21 into b11 plus b12. So, let us check. So, a11 is 1 minus a21 is 3 [01:10:20] minus 2 into b11 is 3, b12 is 2 that is 5 then we will get minus 10. If you now calculate c11, [01:10:30] C11 is nothing but P5 plus P4 minus P2 plus P6. So, what is the value? P5 is 36, P4 is [01:10:42] minus 10, P2 is minus 9 plus P6 is minus 12. So, if you calculate also 36, 19 minus 31, [01:10:56] So, we will get what? 5. C12 is P1 plus P2. So, that is minus 1 plus 9. So, we are getting 8. [01:11:08] C21 is P3 plus P4. So, what we are getting? 14. And C22 is P5 plus P1 minus P3 minus P7. [01:11:24] So, what we will get? P5 is 36 plus P1 is minus 1, P3 is 24 and this is P7. P7 is minus 10. [01:11:40] So, it will become plus 10 because minus minus will be equalized. So, this is 25 and that is 46. [01:11:48] so ultimately we will get 21 as the resultant and if you calculate all then then what we will get [01:11:54] 5, 8, 14, 21 that is the resultant and this is as equivalent to what we have done. [01:12:02] So now a question arises here the number of computations seems to be more than that what [01:12:07] it is performed in the simple matrix multiplication but here the dominating operation that is [01:12:13] multiplication is reduced to only 7 and that is the beauty of this approach and when we will [01:12:20] solve the recurrence relation, then we will identify how the computational complexity reaches [01:12:27] to n to the power 2.81. One more thing that we should remember that in Strasson's algorithm, [01:12:34] if a problem Tn is given, then what we are doing basically, we are breaking into 7 subproblem [01:12:43] of n by 2 size. Okay. And n square will be the number of, because we are multiplying it. Okay. [01:12:50] So, where we are getting n square as the multiplication aspect 2. So, this is the [01:12:57] recurrence relation for stress and logarithm. Okay. And here it is written. So, via master's [01:13:05] theorem, we will try to obtain how it is n to the power 2.81. Okay. So, if anyone has query, [01:13:11] i'm ready to help so rakis just helping me out in taking the queries and then we will go ahead [01:13:18] so for saharab i'm enabling the mic saharab your mic is already enabled so you can ask [01:13:23] so basically my question was about this i think it is a divide and conquer algorithm right yes yes [01:13:32] so so anything that would be a large matrix would be uh ultimately bring down to two cross two and [01:13:37] yes yes yes and sir there is one more question that i have i want to just get the logic of it [01:13:45] like in normal multiplication we know that row and column wise we will be doing the multiplication [01:13:51] to get the first element so i want to get the logic behind this the formula derivation of like [01:13:56] t1 how it is what is the logic behind it how it is derived to this okay so that okay these seven [01:14:04] steps were given by the mathematician Strassens. That's why its name is called Strassens algorithm. [01:14:11] So what was the logic? What is the proof? So in this Corman, I have tried to identify [01:14:18] but I don't get it. But if you get it, then that is good. But Strassens has somehow do [01:14:23] this, these seven step if I perform, then I perform this C1 and C2, then I will get [01:14:28] the result. So that was the logic behind it. So now you can prove it because both the things [01:14:33] are available but at that time how he has done that is great so we are studying now oh no yes [01:14:40] sir so only my question was like the as we know how to derive like in normal multiplication we [01:14:46] know it is like row and column what we have to do similarly i just want to know if there is any [01:14:50] logic that is sitting behind it where we can get like p1 how it is derived or p2 how it is derived [01:14:55] no no so the derivation part you can just look back in the core man okay if i get i will share [01:15:01] you in as well but primarily this is why this is this a p11 p22 is coming this is has been [01:15:10] researched out by stress only okay so and there is one another last part of it like i want to get [01:15:17] that recurrence relation you have told like plus order of n square that is the last portion i'm [01:15:21] not getting about how that is multiplication when we when we do the multiplication component of of [01:15:27] of this one so that will result into the order of n square because if you remember in case [01:15:32] of merge sort quick sort and last algorithm maximum summary we were doing a comparison [01:15:37] and whenever we do a multiplication then there will be the multiplication of two entity a [01:15:42] and b rather than comparison so it will always result into the square term and from where [01:15:47] it is coming so you have to again refer to the algo part of this station so these are [01:15:52] the steps only and whenever we perform multiplication it is order of n square [01:15:57] always okay sir thank you sir so rakis provide access to other as well [01:16:03] good morning sir good morning sir in this straw's algorithm number of row n's [01:16:17] columns should be equal is it the mandatory condition this is this is [01:16:20] mandatory the order should be 2 4 8 16 and so on and and then only we can [01:16:26] apply this okay so that's the second question that whatever we are doing and now uh maximum [01:16:31] sub array now this dynamic programming before that whatever i think we are doing for space [01:16:36] uh complexion deduction time and all those things yes or or we are doing this so that [01:16:42] the problem can be solved faster yes kind of so so do we have some means slide or some [01:16:51] document where we can see that the comparison means with this maximum sub array this complexity [01:16:56] has reduced to this order and so actually what happened dynamic programming cannot be applied [01:17:02] everywhere okay or even divide and conquer cannot be applied everywhere so there are some set of [01:17:06] algorithms that's why i was saying maximum sub array is the you can say very good approach [01:17:11] because all maximum paradigms are existing simultaneously but you will find no none of [01:17:17] the algorithm that is so we later on we will see greedy and dynamic programming so in that we will [01:17:22] find algorithms are comparable but here for example there is closest pair problem so their [01:17:28] dynamic programming cannot be applied so there are some set of problem where dp is not applied so [01:17:34] we have to go with the divide and conquer if both are not applying then we will see the mechanism [01:17:38] of brute force so that that is the thing yeah yes sir that is my answer so whatever limitation you [01:17:46] for this approach we can divide and [01:17:48] conquer with this approach we go brute and force [01:17:50] with this approach we go this all about [01:17:52] do have some any link or [01:17:54] something so that we can miss at least [01:17:56] I go through and able to kill your [01:17:58] this is the condition come I will go with [01:18:00] the brute and force this is the condition come I will [01:18:02] go with the divide and conquer so that's [01:18:04] the thing and if I be the divide and conquer [01:18:06] this is the complexity come so this is the [01:18:08] ask yeah so [01:18:10] one thing is that when [01:18:12] you identify a problem where there [01:18:14] is a provision of divide [01:18:16] into sub problem if there is a problem where we cannot go in the division mode [01:18:21] okay where we cannot break the problem okay so in that situation we will never [01:18:24] go with the divide and conquer okay similarly when there is a provision that [01:18:29] we can solve smaller smaller problems at each level and concatenate them to get [01:18:34] back the or in the we are in a situation if we store the half solve problem [01:18:39] result and we will get the full result then their DP can be applied but if [01:18:44] there is no chance of storing the previous result or if still we store the previous result that is [01:18:50] not fruitful for in the next step then we will not apply dynamic programming there so that kind [01:18:55] of things are there so a problem that can be solved by divide and conquer should hold or even in dp [01:19:02] so two important if we can make recur recurrence relation for or a recursive variant then then [01:19:09] only we can apply divide and conquer and dynamic if we unable to make this recurrence and [01:19:14] structure then we cannot apply dynamic programming or dp now in dp if it is possible [01:19:20] for storing the previous result to taking the next step decision then dp is applicable if it [01:19:25] is not possible to store the result or or or breaking the problem likewise then we cannot [01:19:29] apply dynamic programming that so these are the studies so if you make recurrence relation [01:19:35] fine so you can apply dynamic as well as dp if you store previous result to get the next value [01:19:42] so that is dp if it is not then you have to go to dynamic programming both are not applicable [01:19:46] then we have to use brute force which kind of