1 00:00:01,380 --> 00:00:06,240 Hello, everyone, so in the last video, we discussed the algorithm for implementing in place observed, 2 00:00:06,600 --> 00:00:10,420 and I told you guys to just give it a shot, try to write the code yourself. 3 00:00:11,010 --> 00:00:13,800 So what is the time, complexities or the time? 4 00:00:13,800 --> 00:00:18,060 Complexity is actually in Logan and the space complexity. 5 00:00:18,070 --> 00:00:20,280 So as the name suggests in place. 6 00:00:20,580 --> 00:00:25,800 So the meaning of in place is that it will actually constrain time so that space is going to be big 7 00:00:25,800 --> 00:00:26,410 of one. 8 00:00:27,030 --> 00:00:28,080 Now as discussed. 9 00:00:28,110 --> 00:00:29,870 So what we will also consider this area. 10 00:00:30,300 --> 00:00:35,210 So let's say the array elements are five, eight, three, one and six. 11 00:00:35,610 --> 00:00:36,860 And what was our approach? 12 00:00:37,110 --> 00:00:39,390 So I will divide the array into two parts. 13 00:00:40,110 --> 00:00:46,620 So the first part is actually containing the hip element and the second part is actually containing 14 00:00:46,620 --> 00:00:47,640 our unsorted area. 15 00:00:48,540 --> 00:00:49,470 And we discussed it. 16 00:00:49,470 --> 00:00:52,920 But we will also I will start reversing the area from the next one. 17 00:00:52,950 --> 00:00:57,690 So this is an this is an X zero, so I will start traversing the area from the next one. 18 00:00:58,440 --> 00:00:59,910 And our approach is very simple. 19 00:00:59,920 --> 00:01:02,680 So one by one, I will push the elements into my hip. 20 00:01:03,120 --> 00:01:07,960 So what will happen to the hip range will increase and the unsorted range will decrease. 21 00:01:08,310 --> 00:01:13,850 So you can insert elements and obviously the next zero is one. 22 00:01:13,890 --> 00:01:15,480 So this is my child index. 23 00:01:15,810 --> 00:01:20,510 And again, you have to find out the pain index, which is simply index minus one by two. 24 00:01:20,910 --> 00:01:28,260 And this loop is actually it is containing the child makes such an index value when then its value will 25 00:01:28,260 --> 00:01:28,900 become three. 26 00:01:28,950 --> 00:01:30,030 It will become two. 27 00:01:30,030 --> 00:01:30,990 And then it's three. 28 00:01:30,990 --> 00:01:32,220 And then it will become four. 29 00:01:32,700 --> 00:01:35,490 So simply you have to compare it in five and nothing will happen. 30 00:01:35,940 --> 00:01:39,030 Then you will take elementary inside your heap. 31 00:01:39,660 --> 00:01:43,490 Then heap sizes increase and assorted sizes will decrease. 32 00:01:43,490 --> 00:01:44,810 So similarly, three will come. 33 00:01:45,030 --> 00:01:46,470 So the index will become two. 34 00:01:46,470 --> 00:01:50,250 You can see child index will become two, then you can swap that image. 35 00:01:50,320 --> 00:01:52,170 Three will come here, five will come here. 36 00:01:52,470 --> 00:01:54,320 And similarly then you will take one. 37 00:01:54,630 --> 00:01:57,090 So basically one will be in this position. 38 00:01:57,090 --> 00:01:58,680 So the child index is three. 39 00:01:58,680 --> 00:02:00,330 You can see the child index is three. 40 00:02:01,080 --> 00:02:05,130 Again, you will do the comparison to one and it will get stabbed. 41 00:02:05,280 --> 00:02:07,650 So this is when then one in three will get stabbed. 42 00:02:07,710 --> 00:02:09,180 So this is one and this is three. 43 00:02:09,570 --> 00:02:12,450 And similarly, you will take the element forward into consideration. 44 00:02:12,690 --> 00:02:17,840 So finally, I he will increase and the state will that elements. 45 00:02:17,850 --> 00:02:19,380 There are no certain elements left. 46 00:02:20,400 --> 00:02:25,550 So you will push six at this position, so finally, what is my hip? 47 00:02:25,590 --> 00:02:32,940 So this is one, then it is three, then it is five, then it is containing eight and this is six. 48 00:02:33,690 --> 00:02:34,250 Simple. 49 00:02:34,710 --> 00:02:40,050 So basically, if you will convert it into an area again to the level of traversal. 50 00:02:40,050 --> 00:02:40,800 So this is one. 51 00:02:40,800 --> 00:02:41,530 This is three. 52 00:02:41,550 --> 00:02:42,570 This is five. 53 00:02:42,600 --> 00:02:43,400 This is it. 54 00:02:43,410 --> 00:02:44,310 And this is six. 55 00:02:44,820 --> 00:02:45,890 So very, very simple. 56 00:02:45,930 --> 00:02:49,620 But we have to do we will just reverse from index one. 57 00:02:49,620 --> 00:02:56,190 We will start reversing from the next one and we can copy paste our old code, our old insert function 58 00:02:56,190 --> 00:03:03,810 called now one thing we cannot directly use our one triadic because our own priorities create a vector. 59 00:03:04,110 --> 00:03:06,680 So we cannot just blindly copy our code. 60 00:03:06,690 --> 00:03:08,710 So we just have to do minor, minor changes. 61 00:03:09,180 --> 00:03:10,980 Now let's start writing the code. 62 00:03:14,550 --> 00:03:21,540 So this is my file and the place he ordered CPV, so let us create a function so that the function will 63 00:03:21,540 --> 00:03:25,200 be void because it will just sort Meyera, it will not do anything else. 64 00:03:25,630 --> 00:03:26,920 It will not return anything. 65 00:03:27,510 --> 00:03:29,340 So the name of the function is inbuilt. 66 00:03:29,340 --> 00:03:29,940 He sort. 67 00:03:31,240 --> 00:03:36,340 So what this function will take, so this function will take two things as input to first, one is actually 68 00:03:36,340 --> 00:03:36,810 the Eddie. 69 00:03:38,910 --> 00:03:44,820 And let's say the name of that is in and the second one is actually the size of the ADL and. 70 00:03:47,410 --> 00:03:49,090 So what is the first step? 71 00:03:49,120 --> 00:03:54,410 So first step is very simple, but we are going to do it so we will build keep inside the area. 72 00:03:55,330 --> 00:03:56,860 So first step is very simple. 73 00:04:00,460 --> 00:04:01,810 We will build deep. 74 00:04:02,820 --> 00:04:03,740 In prudery. 75 00:04:04,780 --> 00:04:10,970 We will not use any extra space for building the ship, I told you, we have to start our trading from 76 00:04:10,990 --> 00:04:15,010 next one because we can assume that index zero is already in a heap. 77 00:04:15,670 --> 00:04:16,480 So you can see. 78 00:04:18,420 --> 00:04:26,190 So the value at index zero is already inside the heap, we have to start premising from index one and 79 00:04:26,190 --> 00:04:29,100 then we will take element in to help one by one. 80 00:04:29,100 --> 00:04:29,670 Simple. 81 00:04:31,830 --> 00:04:35,910 So I will start from one and then I listened and I placeless, simple. 82 00:04:36,950 --> 00:04:39,470 So what they have to do, we have to copy paste of something called. 83 00:04:40,860 --> 00:04:46,140 So this is my Plotka class, this is insert function now what we are doing, so this is our elemental 84 00:04:46,140 --> 00:04:47,260 I was pushing elements. 85 00:04:47,670 --> 00:04:49,260 Now, this thing is not required. 86 00:04:51,770 --> 00:04:54,070 We have to copy paste only this much amount of gold. 87 00:05:12,380 --> 00:05:13,790 So after copy pasting the code. 88 00:05:13,820 --> 00:05:14,870 So this is the situation. 89 00:05:16,120 --> 00:05:20,950 Now we have to do some changes, for example, because nothing peculiar to say so. 90 00:05:22,300 --> 00:05:27,310 This is my child index, so what is child index, you can see so the index is nothing. 91 00:05:27,310 --> 00:05:32,230 It is just the index of the area, so it will start from one, then it'll become two, then it will 92 00:05:32,230 --> 00:05:33,280 become three and so on. 93 00:05:33,580 --> 00:05:35,860 So first, I have to update my child index. 94 00:05:35,860 --> 00:05:38,230 Which index is actually the index of the area. 95 00:05:38,260 --> 00:05:39,370 So this is simply a. 96 00:05:41,260 --> 00:05:42,070 So first thing. 97 00:05:43,400 --> 00:05:49,310 So this is very simple, very minor change, so child indexes, a and one more thing. 98 00:05:50,830 --> 00:05:57,100 So here, the name of the is input, but we are actually using Piku everywhere, so let's change the 99 00:05:57,100 --> 00:06:00,770 name to the name of the input that is Piku. 100 00:06:01,350 --> 00:06:05,540 So first I am finding out the child index, which is correct, then this is the standard code. 101 00:06:05,980 --> 00:06:10,860 So while Calix is good then it'll find the index, then do the comparison. 102 00:06:11,500 --> 00:06:17,370 If the child index is Milovan, so do the part then update the child index as to the break. 103 00:06:19,030 --> 00:06:20,660 So this break is actually. 104 00:06:20,680 --> 00:06:23,800 So this statement actually makes the inner most loop. 105 00:06:23,800 --> 00:06:25,400 So the innermost loop is by loop. 106 00:06:25,690 --> 00:06:28,120 So this big statement can only break by loop. 107 00:06:28,120 --> 00:06:29,480 It cannot break for loop. 108 00:06:30,040 --> 00:06:34,450 So this thing you should remember now after doing this. 109 00:06:35,880 --> 00:06:40,880 So actually, our help is right now, our help is ready then what we have to do. 110 00:06:40,890 --> 00:06:44,760 So basically now we have to call the remove minimum function and times. 111 00:06:46,470 --> 00:06:54,240 So what we have to do, we have to call remove minimum function and times now what we are doing here. 112 00:06:58,530 --> 00:07:07,210 So after this cold, so let's say my input at is actually, let's say five eight, one, two and zero. 113 00:07:07,230 --> 00:07:11,240 So let's say this is my input area five it one to zero. 114 00:07:11,760 --> 00:07:14,730 So after passing through this code, what will happen to. 115 00:07:16,190 --> 00:07:20,750 This is the value of I, so I will vary from index one to the last index. 116 00:07:21,200 --> 00:07:22,450 So index is nothing. 117 00:07:22,460 --> 00:07:23,120 It is just. 118 00:07:24,730 --> 00:07:28,740 The value of the added, just the index of the area, so first five elements. 119 00:07:29,080 --> 00:07:32,610 So this element, five inside our heap, so take element. 120 00:07:33,700 --> 00:07:34,740 So nothing will happen. 121 00:07:34,960 --> 00:07:39,320 So this condition will become false and we will break. 122 00:07:39,730 --> 00:07:45,600 So I have element one Satake element one, then compared element one with element five. 123 00:07:45,610 --> 00:07:50,500 So we will do the stripping then you will take element to so element to it. 124 00:07:50,530 --> 00:07:52,820 So then you will find out your paint index. 125 00:07:53,320 --> 00:07:56,650 So this is element to the index is basically. 126 00:07:56,650 --> 00:07:59,140 So this is index zero one, two and three. 127 00:07:59,360 --> 00:08:01,800 Again you have to do the slapping part of this is it. 128 00:08:01,810 --> 00:08:04,270 And this is to again take the elements. 129 00:08:04,270 --> 00:08:05,530 And also this is element zero. 130 00:08:05,860 --> 00:08:06,820 You will do the slapping. 131 00:08:06,820 --> 00:08:07,810 Part of this is two. 132 00:08:07,810 --> 00:08:08,350 This is. 133 00:08:10,040 --> 00:08:14,570 So this is zero, then you will slap one in zero, so when will come in and zero will come here? 134 00:08:14,600 --> 00:08:17,820 So finally, this is your area. 135 00:08:17,850 --> 00:08:24,190 So this is 01, then I have five here, then I have it here and then I have two here. 136 00:08:24,860 --> 00:08:26,270 So this is your. 137 00:08:27,530 --> 00:08:30,380 Minimum heap, so this school is actually for minimum. 138 00:08:30,650 --> 00:08:36,500 We are trying to implement our minimum priority queue and if you convert converted into an area. 139 00:08:36,530 --> 00:08:39,370 So this is zero, then I have one, then I have five. 140 00:08:39,380 --> 00:08:40,400 Then I have it. 141 00:08:40,909 --> 00:08:42,059 And then I have two. 142 00:08:42,080 --> 00:08:43,700 So 015 eight two. 143 00:08:44,480 --> 00:08:46,620 Now, this is our input area. 144 00:08:47,090 --> 00:08:52,250 So this area has now been converted into this area and now we have to do so. 145 00:08:52,250 --> 00:08:55,520 We just have to call the remove minimum function and times. 146 00:08:58,610 --> 00:09:05,060 Or you can also call and sometimes both will be correct, because if you recall, and minus one times, 147 00:09:05,060 --> 00:09:08,060 so what will happen, only this element will be left. 148 00:09:08,240 --> 00:09:10,490 So it is your choice whether to. 149 00:09:10,730 --> 00:09:11,990 So this is not irrelevant. 150 00:09:12,020 --> 00:09:15,170 So basically, the size will be one, size will be one. 151 00:09:15,170 --> 00:09:19,940 And it is your choice because the element is going to establish itself. 152 00:09:20,570 --> 00:09:22,220 So it doesn't make any sense to call. 153 00:09:22,220 --> 00:09:26,840 And times you can also call and minus one times, let's say we will call and times. 154 00:09:30,950 --> 00:09:38,010 So if you remember how they removed minimum function, Wilberg, so this was my area zero, then one. 155 00:09:38,480 --> 00:09:44,120 So this was my minimum 015 eight and do so I have to call the minimum function. 156 00:09:44,130 --> 00:09:48,350 So it will going it will Sub-Zero and also zero will come here and two will come here. 157 00:09:48,800 --> 00:09:55,040 Then actually in the original code we were trying to delete element zero, but here we will not delete 158 00:09:55,040 --> 00:09:55,330 zero. 159 00:09:55,340 --> 00:09:58,340 We will just assume that element zero has been removed. 160 00:09:58,790 --> 00:09:59,840 We just have to adjust. 161 00:09:59,870 --> 00:10:05,950 So what we will do, I will take a variable size and instead of doing B good artpop back. 162 00:10:07,130 --> 00:10:13,340 So work bob back function do so it also decrease the size it removed the elemental back function, do 163 00:10:13,340 --> 00:10:18,710 two things so it will remove the element and it would also decrease the size by one. 164 00:10:19,050 --> 00:10:21,730 So we will not use proper function material. 165 00:10:21,740 --> 00:10:24,170 So we will just reduce size minus minus. 166 00:10:24,440 --> 00:10:28,100 So size minus minus indicates that the element has been removed. 167 00:10:29,900 --> 00:10:35,420 Because we do not have to actually remove the element, we just have to assume so for assumption, we 168 00:10:35,420 --> 00:10:41,600 will just take a variable size and we will lose size minus minus and size minus minus indicates that 169 00:10:41,600 --> 00:10:42,700 the element is removed. 170 00:10:43,790 --> 00:10:44,360 Simple. 171 00:10:45,290 --> 00:10:46,300 So let's do this. 172 00:10:46,310 --> 00:10:52,320 And also, after stepping, we have to put two added side operations here compared to with one in five. 173 00:10:52,340 --> 00:10:55,120 And again, I will say absolutely will come here. 174 00:10:55,130 --> 00:11:02,750 And when will commercial now to compare to with it, but do not compare two with zero because this is 175 00:11:02,750 --> 00:11:04,630 removed, this element has been removed. 176 00:11:05,480 --> 00:11:07,760 So that's why I will lose size minus. 177 00:11:07,760 --> 00:11:08,180 Minus. 178 00:11:10,810 --> 00:11:18,010 So what we have to do, so let's take a variable size, so initially my initial my area is containing 179 00:11:18,010 --> 00:11:18,650 N elements. 180 00:11:19,420 --> 00:11:24,850 So what we have to do so first thing is basically we have to swab the first element with the last element. 181 00:11:25,840 --> 00:11:31,870 Because I want to remove medium function and time so that the first element, which is zero with the 182 00:11:31,870 --> 00:11:38,350 last element to what is the last element, so I will use size minus one to size minus one will give 183 00:11:38,350 --> 00:11:41,800 me the index of the last element and then if you will see. 184 00:11:45,160 --> 00:11:52,210 So here's what I was doing, so I was calling the function back, but here I will just write says minus 185 00:11:52,210 --> 00:11:53,310 minus Simbel. 186 00:11:53,920 --> 00:12:00,970 So this indicates that the element has been removed, but this is only assumption to element is removed. 187 00:12:03,840 --> 00:12:05,970 Now you can just copy paste the code. 188 00:12:06,960 --> 00:12:08,780 Because we have to don epiphytes. 189 00:12:10,820 --> 00:12:12,170 It's down here, Biffy. 190 00:12:29,820 --> 00:12:32,130 OK, so this is the code for down here, Biffy. 191 00:12:33,180 --> 00:12:34,740 So let me check the loops first. 192 00:12:34,770 --> 00:12:35,760 OK, so this is correct. 193 00:12:36,790 --> 00:12:38,710 So, again, we have to do down here. 194 00:12:38,740 --> 00:12:41,650 If I saw the paint index zero, correct. 195 00:12:42,130 --> 00:12:48,430 While Drew, I am finding out the left index, right index, then the index is actually the paint index, 196 00:12:48,430 --> 00:12:52,610 then left index is less than I should be good outside. 197 00:12:52,650 --> 00:12:54,630 So here I will not use peculiarities. 198 00:12:54,640 --> 00:12:56,370 I will simply use the size variable. 199 00:12:57,730 --> 00:12:58,840 So the size variable. 200 00:12:59,590 --> 00:13:00,520 Now this is correct. 201 00:13:00,550 --> 00:13:07,060 So again, instead of peculiar because we do a simple vector here, so simple simply I will use the 202 00:13:07,060 --> 00:13:07,720 same variable. 203 00:13:07,730 --> 00:13:08,650 So this variable. 204 00:13:09,840 --> 00:13:10,950 Then this is correct. 205 00:13:12,070 --> 00:13:17,510 So I'm scrapping and then Bendix is getting ablated with the index, so correct. 206 00:13:17,890 --> 00:13:23,360 So this is one time I have to perform it and times I have to call remove Menom function and times. 207 00:13:23,920 --> 00:13:24,830 So let's do it. 208 00:13:25,390 --> 00:13:27,870 So now to call the function and times what I will do. 209 00:13:27,880 --> 00:13:31,480 So while size is guerdon or goes to one. 210 00:13:33,650 --> 00:13:35,670 We have to call the movement function and. 211 00:13:59,470 --> 00:14:01,080 So, yes, everything seems fine. 212 00:14:02,470 --> 00:14:07,810 So as discussed, how many times we have to remove minimum function, so we have to remove minimum function 213 00:14:07,810 --> 00:14:14,320 and times, so the size, the value of sizes and while size is bigger than order, close to one end 214 00:14:14,320 --> 00:14:15,470 size, minus minus. 215 00:14:15,700 --> 00:14:17,410 So let me save this loop. 216 00:14:18,420 --> 00:14:25,290 So this law will run and time's simple, this loop is going to run and times are good, then are close 217 00:14:25,290 --> 00:14:26,790 to one end size, minus minus. 218 00:14:27,420 --> 00:14:33,390 And see what I was trying to tell you, that instead of using this condition, says the Noriko's to 219 00:14:33,390 --> 00:14:36,480 one, you can also write the condition, says guerdon one. 220 00:14:36,990 --> 00:14:37,320 Why? 221 00:14:37,320 --> 00:14:41,100 Because see if the value of sales is one, then what is happening here. 222 00:14:41,110 --> 00:14:42,500 So the value is one. 223 00:14:42,810 --> 00:14:45,940 So one minus one that is zero and this is also zero. 224 00:14:46,110 --> 00:14:50,910 So what you are doing, you're swapping AOF zero with zero. 225 00:14:50,910 --> 00:14:51,990 Where is the eddy? 226 00:14:52,350 --> 00:14:54,490 So you are swiping the same two elements. 227 00:14:54,510 --> 00:14:59,550 So that's why I told you that you can also write is lower than when both are correct if you will is 228 00:14:59,550 --> 00:15:00,170 good then one. 229 00:15:00,420 --> 00:15:08,070 So the least value of sales will be to and in that case you will be swapping the element of zero with 230 00:15:08,100 --> 00:15:10,320 each to both are correct. 231 00:15:10,320 --> 00:15:11,190 It is your choice. 232 00:15:12,360 --> 00:15:13,920 So this is our standard called. 233 00:15:14,920 --> 00:15:21,010 We do not have to do anything here, we just have to right size here instead of peculiarities, you 234 00:15:21,010 --> 00:15:24,070 will use the size, variable and similarly size. 235 00:15:24,670 --> 00:15:26,140 So everything will remain the same. 236 00:15:29,540 --> 00:15:34,560 So afraid of the cold, we have to test whether our goal is working, correct or not. 237 00:15:35,300 --> 00:15:38,330 So let's make our input very. 238 00:15:41,630 --> 00:15:49,610 So let's say the elements are five one, two zero and eight, so this is zero and eight. 239 00:15:50,300 --> 00:15:54,880 So I have five elements then I have to call the function in place. 240 00:15:55,880 --> 00:16:00,500 So let's copy the name I have to pass to I have to pass booting the area. 241 00:16:00,500 --> 00:16:01,070 And this is. 242 00:16:04,820 --> 00:16:06,500 So the name of the ad is and put. 243 00:16:08,020 --> 00:16:09,670 And there are five elements. 244 00:16:10,830 --> 00:16:13,440 And now let's try to pin down our elements. 245 00:16:27,720 --> 00:16:32,640 So this is my input today, I am calling the function in place, he observed, and we know it is advised 246 00:16:32,640 --> 00:16:33,300 by a defense. 247 00:16:34,270 --> 00:16:38,960 And in C++, that is our best bet, if it's by default and then I'm bending the elements. 248 00:16:39,280 --> 00:16:40,750 So what will be my output? 249 00:16:42,920 --> 00:16:50,150 So basically, we have written the code for implementing minimum prior queue, so virtually all parts 250 00:16:50,150 --> 00:16:55,520 of my output should be it, then it should be five, then it should be two, then it should be one, 251 00:16:55,520 --> 00:16:56,610 and then it should be zero. 252 00:16:56,930 --> 00:16:59,600 So basically our output will be in decreasing order. 253 00:17:00,910 --> 00:17:06,339 Why it is in decreasing order, because if you will see the last video, so in the last video, I already 254 00:17:06,339 --> 00:17:09,819 explained to you that the output is coming out to be in decreasing order. 255 00:17:11,099 --> 00:17:17,579 So you can see if we are going to implement the minimum protocol, then basically our output is going 256 00:17:17,579 --> 00:17:19,130 to be sorted in descending order. 257 00:17:20,670 --> 00:17:24,990 There are is going to be in descending order if you want Iraq to be in ascending order. 258 00:17:25,290 --> 00:17:31,890 So you have two options first implemented prior to go and then apply the reverse function, you can 259 00:17:31,890 --> 00:17:32,910 just reverse the error. 260 00:17:33,180 --> 00:17:36,870 And the second way is just write the code for the maximum priority queue. 261 00:17:38,930 --> 00:17:41,280 So this should be my output, eight five two one zero. 262 00:17:41,630 --> 00:17:42,380 So let's see. 263 00:17:53,270 --> 00:17:56,430 So you can see the output is coming out in descending order. 264 00:17:56,780 --> 00:17:58,560 So eight five two one zero. 265 00:17:59,840 --> 00:18:01,390 So our goal is working fine. 266 00:18:02,090 --> 00:18:07,610 Now, again, if you want, we can analyze the time and the space complexity. 267 00:18:07,880 --> 00:18:10,710 So, first of all, the space complexity and this is very simple. 268 00:18:10,790 --> 00:18:13,090 We are just creating very few variables. 269 00:18:13,580 --> 00:18:15,370 So the space complexity is constrained. 270 00:18:15,980 --> 00:18:17,680 If you want to analyze the time complexity. 271 00:18:18,170 --> 00:18:19,640 So let me do that. 272 00:18:21,120 --> 00:18:26,510 So we have to function first inside function and then we have removed minimum function, so we are using 273 00:18:26,510 --> 00:18:27,060 to loop. 274 00:18:27,080 --> 00:18:28,590 So this is the first loop. 275 00:18:28,610 --> 00:18:34,220 So this loop will run and times and this is the insert function called insert at the right place. 276 00:18:34,220 --> 00:18:36,200 And we know insertion takes longer in time. 277 00:18:36,560 --> 00:18:42,730 So this is a login so and login for building the heap and login for building the heap in the input area. 278 00:18:43,250 --> 00:18:46,090 And then we have to call remove minimum function and times. 279 00:18:46,490 --> 00:18:49,970 So I am calling the function and times and each time removal. 280 00:18:50,000 --> 00:18:57,980 So we are doing down here biffy and here we are doing up by so end times and each time login time so 281 00:18:58,220 --> 00:18:58,930 and login. 282 00:18:59,780 --> 00:19:06,870 And if you will add these two to the time complexities and login and the space complexity is very simple. 283 00:19:06,890 --> 00:19:08,370 This is big of one. 284 00:19:09,560 --> 00:19:12,020 So this is the code for the minimum priority queue. 285 00:19:12,970 --> 00:19:15,500 And the output is going to be in descending order. 286 00:19:16,960 --> 00:19:22,510 So if you want to implement maximum protocol, so what changes you have to do? 287 00:19:22,810 --> 00:19:30,080 So first of all, you have to change this code, building the heap so you will just change a few variables. 288 00:19:30,100 --> 00:19:32,350 So, for example, instead of less than you will. 289 00:19:32,350 --> 00:19:33,150 Right, good. 290 00:19:33,190 --> 00:19:39,760 Then then similarly, you have to do minor minor changes in remove function, for example, where you 291 00:19:39,760 --> 00:19:41,020 are writing the condition less. 292 00:19:41,020 --> 00:19:42,640 You will write the conditions there then. 293 00:19:43,150 --> 00:19:48,880 So these are very few minor changes that you have to do for implementing maximum protocol. 294 00:19:49,240 --> 00:19:54,150 And I have confidence in you guys that you can definitely implement, mix and protect yourself. 295 00:19:54,850 --> 00:19:58,710 So if you will implement makes improved, you are getting the time and the space complexity. 296 00:19:58,720 --> 00:20:03,460 So they will be same time is going to be and Logan and the space is going to be big often. 297 00:20:03,460 --> 00:20:06,610 And basically your input array will be started in ascending order. 298 00:20:08,510 --> 00:20:10,030 So I will share this quote with you. 299 00:20:10,880 --> 00:20:12,140 You can analyze this called. 300 00:20:13,340 --> 00:20:15,030 So I will see you in the next one. 301 00:20:15,380 --> 00:20:15,800 Bye bye.