[00:00:05] I think group based, I'll take your doubt and with their eyes also, we'll take a window. We'll start with the insertion short, then much short. [00:01:02] So, I think insertion short is already completed. Okay, but I'll repeat the part. [00:01:11] I will complete something in 10 minutes. [00:01:24] So you are given an array integer, array of integers. [00:01:27] Your task is to sort the array using the insertion short algorithm, print the sorted array. [00:01:36] So insertion short hotha gaya, like, so I'll come to the queue also, okay, we'll study [00:01:57] circular priority, okay, those things, so 4, 3, 2, 9, 5, okay, so what is insertion short? [00:02:12] One sorted part is there, another one is the unsorted part is there, correct, sorted [00:02:21] part. Another one is unsorted part. So our algorithm will take the first element as a [00:02:38] sorted. It will think in the mind that I will take the first element as a 4. I think it [00:02:48] a sorted one then remaining element will be there as it is correct correct then [00:03:00] first element will come as a three it will compare with the sorted part okay see there [00:03:06] is a sorted part and there is an unsorted one okay he pura unsorted he pura sorted [00:03:13] so i will take one element and compare with this four okay i want to take from the [00:03:20] unsorted part and put it in a sorted part. So, for that what I need to do? Sorted part should [00:03:25] be sorted. So, I need to compare with the existing element whether it is a sorted or not. [00:03:32] So, I will compare with the 3, with the 4. 3 is a less than 4. So, I need to keep [00:03:39] three first then four okay then right then one sorted part will be two nine five okay then [00:03:53] another element will come okay two two will first compare with the three okay now two will compare [00:04:01] with the three okay two is less than three okay it will again compare with the four and it will say [00:04:07] okay it's the lesson okay ll if here only okay then comes to nine okay nine will compare to the [00:04:20] two okay okay it's a greater something kind of then it will compare with the three okay okay it's [00:04:27] okay so when we are comparing with uh two with these two elements first it will compare with [00:04:33] three okay if it is a like a something kind of a lesser element it will not go for the another [00:04:40] greater element which is already greater than the uh it's compared recently correct so when it's [00:04:48] compare nine compare with the two okay it will say like a nine is a greater okay i'll push okay [00:04:55] now it's compared with the three okay it's a greater i'll push it's compared with the four [00:05:01] okay it's also a greater so i'll push forward and keep it here in the last finally the last element [00:05:08] okay it will compare with the two okay okay two is a greater something i'll push three is later [00:05:16] okay five is greater than the three i'll push forward then four okay four kind of a greater [00:05:24] also like a five uh sorry nine nine is kind of a greater than the five okay so it will keep here [00:05:32] okay and then nine as it is correct so this is only the insertion only okay so this is the only [00:05:41] insertion short algorithm nothing just you are inserting one element into the sorted part you [00:05:48] are comparing with uh the uh elements okay which is uh which is whether it is a greater or like a [00:05:56] whether it is a smaller okay and then you are placing the uh blessing it with the right place [00:06:03] correct right positions that's only the instructions okay what happened in the [00:06:12] part short it will first find the correct divide point okay then it will divide divide [00:06:19] divide okay like a british so like british's what they did divide and conquer right so like that [00:06:30] mushroom will also work okay so it will divide divide divide then it will compare okay so it [00:06:37] will compare with the other uh elements okay then it will merge okay okay so i am dividing with uh [00:06:45] so imagine this okay i divide it okay this is the divided part some somewhere in between we are okay [00:06:53] so now it will compare with this element with this this this okay now it will place here okay [00:07:02] so something like that it will merge okay so this is only the much short algorithm okay so i'll i'll [00:07:09] tell you the algorithm part also okay so i'll try and also the insertion part [00:07:17] ticket so there is no need to worry um so let me take the input okay and input okay sorry [00:07:28] it and input array list of map root or split okay so i already uh like it told you uh that [00:08:00] why we are mapping with int and string okay here we are taking how many elements are there [00:08:08] okay and here we are taking uh the array list okay correct and then what we will do [00:08:20] we will uh pattern for loop which will loop uh in this and an elements okay and it will check [00:08:29] whether the j part okay like a uh whether this part okay is uh compare with this part okay [00:08:38] something like that will uh check and then it will do the operations we'll we'll see okay [00:08:46] for i in range of one to n there is a reason behind why i'm taking one okay not from only m okay [00:08:57] Okay and then I will take one key. Okay key value will be the current element you can say okay [00:09:08] current element from the unsorted part and then I'll take j as a i-1. Okay because we need to [00:09:21] check with this one. So while j is greater than 0 and array of j is greater than p then you [00:09:41] perform the operations array of j plus 1 equals to array of j then j equals to j minus 1. [00:10:01] j equals to j minus 1 and then i'll i'll place the key value also okay like a [00:10:11] key value will j plus 1 will be the key value and then we'll print the whole array [00:10:26] okay i'll print the whole array okay so in the first line we will take the input okay [00:10:43] so let's say ashish umar and take that out okay so let's say we are taking n as a five okay [00:10:54] then we'll read the array okay uh indeed the array okay so let's say we are taking [00:11:05] areas of four three two and twelve okay something like that [00:11:11] then my array value is like this okay if you want in an index manner okay i'll tell like uh zero one [00:11:22] two three four something like that then uh we are taking we taken the n as a fight right so for i in [00:11:41] range of a one two five it means like a i'll i will starting from the one two till four okay [00:11:53] because range is taking i minus one so that's why now what is that t value will be array of a ith [00:12:02] okay so array of a one okay three value okay so it means value of a three okay t value will be [00:12:15] t value will be here three okay if you want i'll explicitly write as a array of one okay [00:12:23] which is three okay i value will be one okay uh j value okay i value here is a one okay [00:12:35] and j value will be i minus one uh one minus one one minus one which is zero okay so now [00:12:46] it is pointing to j value is pointing to 4 and key value will be pointing to 3 okay now we will [00:12:52] compare okay now while while loop will be start okay now while j is greater than zero okay so why [00:13:06] j is greater than zero i'm writing okay because uh uh malaki minus one main because it will not [00:13:14] go to the minus one something kind of okay so that's why till the zero i'm checking okay not [00:13:20] less than that okay so that's why i'm checking uh this one again so uh and [00:13:31] array of a j is greater than the key value okay [00:13:39] okay and value means okay so if you studied the uh coa something computer organization architecture [00:13:44] so and will check both conditions both conditions to be true okay [00:14:01] and ko true honne ke liye kya sahi rye and true honne ke liye true and true chahi right [00:14:12] to result in true right so both conditions have to be true to become this whole condition true [00:14:30] okay if one condition will be false then whole the condition will be false right so that's a [00:14:36] and and check okay so yeah uh then this will pass because zero is less than sorry zero is greater [00:14:49] than equals to zero and this one okay so i'll copy this okay and write it here so array of a zero [00:14:58] array of a zero means four okay so now it will check four is greater than three okay four is [00:15:05] greater than 3 which is coming as a true okay is coming as a true so both conditions will be true [00:15:13] so uh it will enter the while look correct okay the condition so array of a j plus one [00:15:21] will be this one so array of j plus one will be uh equals to array of a j okay so array of [00:15:39] j means 0. 0 plus 1 will be array of 0. Okay so array of a 1 will be the array of a 0. Okay so now [00:15:51] array of a 1 will be now array of a 0. Okay now array of a 1 will be [00:16:00] equals to array of a 0 means 4. Okay so it will swap. Okay now array becomes what? [00:16:10] see uh absolutely okay so you're thinking like the it will swap the value and four will become [00:16:17] the three okay now three will become the four no not like that under the hood okay it is [00:16:25] something like this still something like this okay so under the hood it is still something [00:16:33] like this 4 4 2 10 12 okay understand this okay so we did not enter this we did not enter this one [00:16:46] correct so till then that okay our array is something like this so let's say in a competitive [00:16:54] questions okay so competitive website so uh so something after this so what will be the [00:17:08] array value okay so don't like something uh three four [00:17:16] don't write right like this okay so there will be a option like this also okay [00:17:22] Okay, so it will not change, got it, so now the j value would be j minus 1, okay, now [00:17:45] j equals to 0 minus 1, okay, so j value will be minus 1, okay, j is now pointing to the [00:17:54] minus 1 take care now it will check again okay now it will check again with the same condition [00:18:03] okay now it will check with the same conditions okay like a uh minus 1 is greater than equals to [00:18:11] 0 so it will again false okay it will again false so one condition is false okay it will not check [00:18:18] this condition okay so again uh something like in exam it will uh tell you like if this condition [00:18:27] is checked and is this also gonna check no it is not gonna check it in the and operator okay [00:18:34] until this one is it true okay so uh this is not going to be checked okay so once it is true [00:18:43] then it is also going to be checked so once it is false it is not going to check the second [00:18:48] conditions okay got it so j value will be minus one so that that's condition gonna false okay so [00:18:57] loop will be stopped okay loop will be stopped and tell you like something like a false okay [00:19:07] we are getting false due to false one while you will be stopped because uh this gives you false [00:19:20] okay okay now what happened uh huh either hum log or a condition like that right so array of a j [00:19:30] plus one okay array of j plus one will be the key okay i'm popping this okay array of j plus one [00:19:39] which is minus one plus one okay array of minus one plus one will be your key so now what what [00:19:50] is the key value a value is three okay now it is going to be changed okay did i tell you okay [00:20:04] so when i see this condition sorry maybe my mistakenly aapko is conditions ko leke many [00:20:12] iska point out but there is a swap kind of things okay so area of a zero will be the three correct [00:20:25] now it uh the error will become three two two ten twelve water so this is how it is going to be [00:20:34] changed correct so for the simplification purpose for the simplification purpose i [00:20:48] told you like yeah there you will insert okay so some if you will see something like this [00:20:55] only happening okay under the hood okay but why the insertion uh the name part is there so i [00:21:03] tell you like yes i portrait like this correct so now this loop will run again uh for the iteration [00:21:13] one okay so uh yeah for the iteration zero it uh sorry first iteration is done okay so it will [00:21:23] run for the second iteration now key value will be the area of i okay so if i will tell you okay [00:21:33] p value will be the area of i we are taking like this correct now p value will be array of [00:21:41] one is one is already done right so it will come as a two okay so p equals to two now [00:21:50] Now, i equals to 2 and key value will be array of a 2, 0, 1, 2, which is also 2. [00:22:05] Let me also, so the indexing, so that it will not confuse. [00:22:14] So, this one already run, right? [00:22:17] One part. [00:22:18] So, now we are going to the two part. [00:22:20] So, two part value is 2, correct? [00:22:22] Now, our array is like a 3, 4, 2, 10, 12, which is an updated array. [00:22:32] Now, we are checking what? j equals to j minus 1. [00:22:40] Now, we are taking j equals to j minus 1, which is 2 minus 1 is 1. [00:22:52] 2 minus 1 is 1 okay j equals to 1 okay now while loop will be checked okay so easily pass [00:23:04] okay because uh this is 1 1 is already bigger than 0 okay and and value is like an array of a j [00:23:17] array of a j is like a key okay so array of which is one key value key value will be two okay [00:23:33] you are imagining like this so array of a one so array of a one is what this one correct [00:23:46] to 4 okay again it is gonna say okay area of 1 equals to 4 now 4 is already greater than 2 [00:24:04] which is 2 so the both conditions are 2 okay it will enter in the group okay it will enter [00:24:14] in the loop sorry and what's inside the loop j plus one equals to j right we will write the j plus [00:24:24] one is j uh what is j plus one j kya tha one tha so area of a one plus one one plus one is [00:24:33] 2. Correct. So, area of a 1 plus 1. Correct. Equals to area of a 2 and now area of a 1. [00:24:45] Okay. So, area of a 2 equals to area of a 1. We are swapping. Okay. So, we can have the area of a 2 [00:25:02] so now we are surfing the value of a 2 with the 4 correct [00:25:13] the updated array will be 3 4 4 10 12 correct 3 4 10 12 okay now j will become j minus 1 [00:25:29] okay j minus one this one minus one okay one minus one will be zero okay now it will again [00:25:43] check for the loop okay while zero is greater than zero okay it is true while zero is greater [00:25:51] than zero which is first condition is true area of a zero is greater than two it will again check [00:25:59] so array of a zero is what three okay so is three is greater than two okay again i'm writing here [00:26:09] array of a zero is three so three is greater than two which is coming as a [00:26:15] two okay it will again enter enter in the loop okay it will again enter in the loop [00:26:24] and it will say like area of a j plus one equals to area of a j okay area of a j is like now zero [00:26:33] plus one okay so area of a j is like a zero okay area of a one will be like sorry one will be like [00:26:42] area of a zero okay area of a one is what uh sorry area of a one is now become three [00:26:53] correct so area of one becomes now three so now the updated loop will be like three comma three [00:27:05] comma four comma ten comma one okay now it will check j equals to j minus one okay [00:27:20] condition will be failed okay hope you are understanding how it is because [00:27:24] j is now 0 minus 1 which is coming as a minus 1. So condition will be failure in the in the while [00:27:38] loop. So it will come out of the loop and it will say like j plus 1 is like a key. [00:27:57] okay their condition right so over j plus one will be the key correct so now what is my j value [00:28:07] j value will be my minus one okay is one now the key value will be two okay so array of [00:28:20] 0 में क्या हो जाएगा अब का 2 चला जाएगा ठीक है so now my updated index [00:28:29] will be 2 sorry 2 3 4 10 12 got it itna part pura sort हो कहा है itna part unsorted [00:28:44] you can see it is a sorted ठीक है but although it will check ठीक है for the [00:28:48] the iteration thing okay so this is how the loop will run and check got it then uh hope this is [00:29:06] flat fried okay and also like a scope with hand if you're preparing for the competitive something [00:29:14] so it's just got behind that now okay it's just for or like many kind of thought or [00:29:23] now comes to the [00:29:34] oh [00:29:39] yeah [00:29:53] wait a second [00:30:07] sorry [00:30:11] hi [00:30:12] hi sir good morning [00:30:15] morning [00:30:16] this is the place [00:30:20] So basically, when we studied insertion, basically we said that it's in place sorting. [00:30:29] It means that it will repeat a pattern every time. [00:30:39] That's why it was in place sorting. [00:30:44] I can't understand. [00:30:45] I have to tell you that the [00:30:49] insertion sorting is nothing just [00:30:52] you can understand [00:30:54] sorted part [00:30:55] I have to tell you what I did [00:30:58] I have to start with 1 [00:31:01] because I have to compare [00:31:04] value [00:31:05] 3 [00:31:06] compare [00:31:07] okay [00:31:08] but I'm like this [00:31:10] J value I'm minus one [00:31:13] so I'm seeing this [00:31:15] J value sorted [00:31:18] J value I'm sorted [00:31:20] means that [00:31:21] if you can understand this [00:31:22] one part I'm sorted [00:31:25] and the other part I'm sorted [00:31:30] now I'm going to [00:31:33] one-one value [00:31:35] so I'm going to compare it [00:31:38] something you can invest [00:31:40] so [00:31:44] you [00:31:49] know [00:31:51] definition [00:31:53] is [00:31:55] sorting [00:31:57] specific place [00:31:59] sorting [00:32:01] in place [00:32:03] sorting [00:32:05] in place [00:32:07] sorting [00:32:28] I'm sorry [00:32:30] if you understand [00:32:31] that it's different [00:32:32] you can tell [00:32:33] that it's different [00:32:34] I didn't know [00:32:35] what I did [00:32:36] insertion [00:32:37] I didn't know [00:32:38] what I did [00:32:39] this is different [00:32:40] this is different [00:32:41] okay [00:32:45] thank you [00:32:48] Asis [00:32:54] hello Asis [00:32:58] hello [00:33:00] hi [00:33:02] good morning sir [00:33:03] good morning [00:33:05] hope you are good sir last week we had a news that you were not well so sir my question is that [00:33:14] sir you have shared couple of links for the assignments in lab lab sessions so it is good [00:33:21] to see that we have a couple of exercises to do so my question is that are these compulsory or [00:33:28] we can practice it later and get it done because something okay fine noted sir thank you so much [00:33:36] and it is showing us six days so i missed i think the first one so no no no all the assignments i [00:33:44] have opened okay it is no any context timings like for a week or something but uh i'll i'll [00:33:55] again like a close this on next 20 okay like a 20 i'll close all the assignments if you didn't [00:34:04] submit it yeah okay i'll surely submit sir thank you so much sir and sir one more question is that [00:34:11] among all the sorting algorithms which one is more effective which one is more effective [00:34:18] or which one is more prominently used in most of the yes sir thank you vidyaraj [00:34:39] hello sir my assignment my doubt is related to assignment three [00:34:49] for the first question there were no marks it's just showing zero even after solving [00:34:54] i already told you like it's having some problem i even don't know what is happening [00:35:00] maybe glitch so it's also not showing to me it's also showing to me zero mass even if you [00:35:07] solve or something [00:35:08] I can't do anything [00:35:12] so keep it as a submitted [00:35:14] I'll take the [00:35:16] I'll take from there [00:35:17] okay [00:35:17] so the marks will be allotted to us [00:35:21] even when it's not showing [00:35:22] okay [00:35:23] thank you [00:35:34] Kunil Kumar [00:35:46] hi sir [00:35:50] so my question is [00:35:52] I'm a bit confused with [00:35:54] the time complexity [00:35:55] I can see that merge is better but I can see that there are more comparisons done so [00:36:00] when we were discussing in the class in the theoretical class it was told that the number [00:36:06] of comparison is directly proportional okay for an efficiency of an algorithm so if I'm when I'm [00:36:13] seeing the merge sort I can see you're dividing the area you're comparing once within the area [00:36:17] and again again we are comparing it with different arrays and so I can see that number of comparisons [00:36:23] are more here but still i can see that the type of complexity is better than binary search [00:36:31] so i'm a bit i mean binaries uh sorry um the um the other sort i mean mud sort i mean um [00:36:43] what was the insertion sort so no no no no no i am that's [00:36:49] I am reading the insertion sort, so do you compare the insertion sort to insertion sort? [00:36:56] No, this is merge sort. [00:36:59] Merge sort, we divide it first. [00:37:02] No, insertion sort. [00:37:07] Okay, so you are still... [00:37:14] Okay, I thought it's merge. [00:37:16] You can continue. [00:37:20] okay i'm okay i'm maybe i'm maybe wrong which i was of the opinion that you have to discuss [00:37:27] okay if it is insertion it's fine sorry no no no i just completed insertion right [00:37:33] but i didn't continue i didn't take a question [00:37:38] okay okay thank you okay [00:37:42] Saurabh Kumar Pandey [00:37:56] Am I Audeva? [00:37:58] Yeah, you are Audeva [00:38:00] Just a simple question [00:38:02] Or you can say the doubt is that [00:38:05] Can we not use two of the four loops regardless of while? [00:38:09] I didn't understand [00:38:13] What do you have done now? [00:38:15] One for loop and one for loop [00:38:17] So I'm asking that we can do this with two for loops [00:38:21] is [00:38:23] a [00:38:47] I love you for a look at me like I say hello for I in a range of one-two length of error [00:38:55] okay and for J in a range of I do zero minus one minus one step count minus one [00:39:05] foreign [00:39:35] You can use it, it's easy, so you don't have to use it. [00:39:39] Okay. [00:39:40] That's it. [00:39:43] Thank you. [00:39:44] No, both of them. [00:39:45] Okay. [00:39:47] Thank you so much. [00:39:49] Shraddha Kamath. [00:39:59] Hello. [00:40:04] Yeah. [00:40:05] I had a doubt in time complexity. [00:40:08] In general, in time complexity, if there is a for loop, it's n. [00:40:12] If there is a for loop, it is n into n minus 1, so it is O of n square. [00:40:17] So how do we calculate the time complexity in this? [00:40:19] So, in the insertion short, basically, we calculate three types. [00:40:27] So, in the insertion short, the worst time complexity is big of n square. [00:40:34] And if you look at extra s time complexity, it is big of n. [00:40:41] Okay. [00:40:43] And... [00:40:45] I think... [00:40:47] ...Abdulwari is a video. [00:40:49] You can see it. [00:40:53] You can calculate it. [00:40:55] You can refer it. [00:40:57] Okay, okay. [00:40:59] But in general, [00:41:01] we can say it's N. [00:41:03] But inside there's a while. [00:41:05] So then how do we calculate? [00:41:07] Okay, okay. [00:41:09] first if I have to [00:41:10] speak a little like [00:41:11] I'll explain [00:41:13] better [00:41:14] maybe [00:41:15] I can't explain [00:41:16] what's the problem [00:41:16] no [00:41:16] okay [00:41:18] okay thank you [00:41:21] Aditya Puma [00:41:27] maybe he's not there [00:41:37] Kahlib Puma [00:41:47] hi sir [00:41:51] actually I have [00:41:54] done the insertion [00:41:54] chart but [00:41:55] my taste coverage [00:41:57] is failing [00:41:57] taste coverage [00:41:59] yeah I mean [00:42:00] example was there [00:42:03] so I am able to run the instance short [00:42:05] and I am getting the sorted array [00:42:06] but when I am trying to submit the code [00:42:09] the test coverage is failing [00:42:11] the coverage was failing? [00:42:15] yeah exactly I did the same [00:42:17] pseudo code [00:42:17] the same way I put [00:42:20] there [00:42:21] which test basis is failing? [00:43:03] it's all actually [00:43:04] it's all [00:43:07] like all of the all these cases yeah well submit the code i'm not possible man i submitted it [00:43:14] two times like something wrong [00:43:18] but run to run to hora sir [00:43:23] i don't think so [00:43:38] i will check i will check on this yeah [00:43:55] thank you yeah okay we'll move to the next question [00:44:08] so next question is like around much short take them so much short is a shorting algorithm only [00:45:03] okay based on the divide and conquer technique it works in uh like a simple two steps okay [00:45:13] First divide, which means like you break the array into smaller halves until each part [00:45:21] contains the only one element, correct. [00:45:26] And then it will conquer and merge. [00:45:30] It's like merge the smaller sorted arrays together to produce the, to produce one sorted [00:45:38] area take it so it will produce one sorted area uh which will include the smaller sorted areas [00:45:46] which is a even one one one one elements like a one element is like a two only one element is [00:45:53] three only so that is even sorted right so it will include that and it will compare okay so something [00:45:59] like so if i will give you the example same example we are taking okay four three two [00:46:08] 10, 12. So it will divide as a left half and it will divide as a right half, 4, 3, 2, [00:46:33] 10, 12. Then it will again keep divide. It will again divide 4, 3 and it will divide [00:46:48] like a 10, 12. Again it will divide like a 4. So it will divide the array until it reaches [00:47:04] to one one element and well okay now it will merge okay so now it will merge like a three four okay [00:47:24] It will first merge like 2,10, then for like 12, then it will 3,4 again, 2,10, then it [00:47:53] will merge, so like 3,4, here 2 will come, and then, correct. [00:48:12] so there is an important thing like a merge shot doesn't sort everything by comparing the [00:48:19] adjacent element it divides the array and sorts the smaller past and merges to merges those parts [00:48:28] in a order okay so there is a two function okay so one is a merge function and another is one for the [00:48:39] uh find another one is for like a sorting function okay [00:48:47] set it so so there is a two functional uh much what you can see okay so so one is like a merge [00:49:02] so in the merge uh it will take an array first okay then it will take the left part [00:49:09] then it will take the right part then it will take the mid part correct and then [00:49:20] will assign i value will be the left if j value will be the mid plus one okay [00:49:30] so something like you can imagine um i value will be the something around left part [00:49:38] j value will be the i plus one okay sorry the mid plus one so this is the middle value okay [00:49:47] plus one so starting from here okay i value will be starting from here take care okay [00:49:56] now it will take the now we will take the temporary array limit okay i'll tell you why [00:50:06] okay i will compare like a if it will come there later [00:50:23] uh i to this one okay make okay i made the one oh so better right after this okay [00:50:47] i will comment this okay it is very confusing [00:50:52] better first we will divide okay so so something like first array there is no part okay so there [00:51:05] is no mid part okay we'll simply take like a uh array left or right okay then i will compare [00:51:19] if left part okay is greater than the right part okay part is better than the right part [00:51:31] then return uh it means like a if something uh it's like a swapped already okay [00:51:48] it compared compare and it's swept something like you can imagine [00:51:52] okay i'll try and then you can see okay what do i mean by this okay [00:51:58] so we will find first mid value okay so mid value left plus right divided by okay this is how we [00:52:14] divide okay then i will write like a again call this function okay more short array then i will [00:52:25] again divide okay this is the first division okay so so this is the first division okay [00:52:33] then i'll again divide right again divide so for that i'll write again another function correct so [00:52:41] that one is left to mid okay why left to mid because once you divided the first one okay goal [00:52:50] array then you will divide the sub parts also correct sub parts so for that i need to find the [00:52:58] middle value correct so left to mid we have to go correct so for that i am writing left to mid [00:53:07] then another part i will divide array mid plus one two mid plus one two right here [00:53:25] then i will merge okay then i will write the merge function so for the merge function what [00:53:32] what do i need array value left value meta value and the right value okay correct so this is where [00:53:45] we divide it okay now we will write the merge function okay so for the merge function here it [00:54:00] Yes, all the parts are divided now. Okay, now we will merge. Okay, so we will make this merge. [00:54:10] Copy this, paste it here. Okay, so I value I am taking as a left one, J value I am taking as a [00:54:25] a hit plus one. Now I am taking one temporary array, then I will come there. While i is [00:54:49] less than the middle. So i is less than the mid. [00:55:03] i is less than the mid, this is checking the positions only, okay, the positions check [00:55:13] current and j is greater than right, okay, so this all you've seen, okay, the positions [00:55:24] check current, only the positions, not the values, okay, j is less than the right, if [00:55:41] array of elements i is array of j then temp and array of i and i equals to i plus one [00:56:10] okay if it is not lesser then what we will do we will like a plus our first let me write okay [00:56:28] then drive and then i can understand [00:56:36] then i is less than the mid and j is also less than the right [00:57:03] okay i is less than equals to mid i is less than equals to mid [00:57:15] I am so [00:57:18] I am [00:57:30] but she got your [00:57:36] and [00:57:46] I am [00:57:47] and I think we've got [00:57:55] to say [00:57:57] and [00:58:02] like leftovers. Leftovers ke lhe, or a truth chalega. For k in a range. For k in a range. [00:58:17] Length of temporary third. K of a left plus k. [00:58:38] Okay. So, abhi we make it lehke dhekna hai. Array 4, 3, 2, [00:58:54] then 12 okay then much short much short of l8 0 1 2 3 4 right so first this function will be called [00:59:15] take it uh so first we are uh like n minus one like if you are taking the end as a [00:59:26] uh for it then we will go uh n minus one um in the mod shot then it will check yeah then it will [00:59:45] check like a other uh left okay evil conditions check right so if left is like something greater [00:59:57] okay so left one is a greater right because we are passing [01:00:05] no sorry left one is not a greater okay so it will not go inside this loop because [01:00:12] condition will fail okay then it will go to this one again [01:00:18] now this condition will be angry okay just wait for a second it will go to this okay [01:00:28] or the left goes to 0 and the right goes to 4. The mid value will be simply 2. [01:00:43] So, 2 means the left part will be 4, 3, 2. Why this is? Because 0, 1, [01:01:04] oh okay two to divide okay okay now rest will go to the right part okay 10 and 12 [01:01:20] so rest it will go to the right part 10 and 12 okay now uh [01:01:32] so conditions are correct right so if uh zero is greater than four then uh it's not satisfying right [01:01:40] so i'm talking about this one okay so this one okay so it will not go to the blue it will not return [01:01:51] okay now it will divide right or divide the reader then again it will divide uh [01:02:03] zero comma two not short of not short of any past here left okay what is the left value [01:02:14] that will be will be zero zero comma two okay and then now mark short of [01:02:28] area mid plus one mid plus one okay then right so then again it will check [01:02:45] if i may this condition to include karta ho [01:02:50] so then it will say it will false okay then don't go to the loop okay [01:03:09] so it will not go to this one okay so then it will calculate the mid okay so then again [01:03:23] the left part will be four comma three because the mid how the mid mid is calculated [01:03:33] zero plus two divided by two okay one okay that's why i'm dividing zero till one okay [01:03:45] then rest right part right part two right because four three two [01:03:52] thaw so one tak divide kya minne so the right part will be two then again it will call the [01:04:03] much short zero comma one okay then again it will divide again left goes to zero right will be one [01:04:16] okay then mid value calculated is zero zero plus one divided by two [01:04:23] which is zero okay why zero not 0.5 okay because [01:04:31] we are going to take an integer explicitly that's why it will not come as a 0.5 okay it will come [01:04:44] as a zero okay ceiling value right right so left part will [01:04:56] will be 4 and right part will be 3 okay because my 0 divided [01:05:07] mid value 0 to 0 so that's why one value will become [01:05:13] again it will go and check again it will go and check [01:05:23] so again it will call array 0 left part is 0 mid part is 0 [01:05:32] if left is better than the right [01:05:42] It will going as a mid value, but as a right value, so it will say yes, 0 is greater than [01:06:07] 0, which is coming as a true. [01:06:12] So once it come as a do, what is the value? Return. [01:06:16] So it will return. The function will stop here. [01:06:23] And the element, a single element is already sorted. [01:06:27] Like the single element is always sorted. [01:06:31] So it will return again. [01:06:34] So first recursive call is finished. [01:06:37] Okay, we can say, so this is the, all calls are recursive calls only, taken. [01:06:43] So first recursive call is finished. [01:06:46] Okay, then it will go to the next one. [01:06:49] Okay, next one means the merge array mid plus 1. [01:06:59] Okay, the right value. [01:07:02] Let me show you the function. [01:07:05] Okay, so what happened? [01:07:07] So this function is calling itself until this condition is satisfied. [01:07:16] So once it is satisfied, what it says return. [01:07:20] So where to return? [01:07:22] Where you are coming from? [01:07:23] There you return. [01:07:24] Where I am coming from? [01:07:26] From this function I am coming from. [01:07:28] So this will return to here. [01:07:31] Once it is finished, then it will jump to next line. [01:07:35] right so this is how programming works right so once the line one finished then it will go to the [01:07:41] second line right so once this recursive call is finished because this condition is satisfied [01:07:46] okay now it will go to the this function okay so now it will call as a recursive trigger [01:07:57] so now i'm calling this function hope you are getting now abhi area so what's the [01:08:06] the mid value, mid value will be now zero. So what is the last mid value is like a zero. [01:08:16] And what is my right value also? Now we will call the second recursive. So what is my right [01:08:32] value it is 1 right so now much short okay much short of i am writing again writing as a mid value [01:08:54] as a 0 okay now right part will be as a 1 okay right part will be as a 1 uh so much short [01:09:11] area of 0 plus 1 plus 1 jayega. Now I'm not sure of the area of 1,1. So it will again [01:09:40] see as a condition I have. So if 1 is greater than 1, then you return. [01:10:15] i'm always confused in a recursive post [01:10:23] so one is uh greater than one so return for us go so condition will be satisfied it will return [01:10:32] okay now both halves are sorted so both of us are sorted means like a four comma three is sorted [01:10:39] and the next time when they run wait second mid plus one mid plus one is [01:10:52] so mid value is zero but right value for one [01:10:57] so one you know one higher [01:11:00] okay so four comma three [01:11:04] okay guys so now what will happen [01:11:18] okay it will say as a 4,3 okay like individual value so first of all it will uh divide okay [01:11:27] divide divide divide then it will get merge only will take the what is divided okay purely divided [01:11:35] what is purely divided now four and three okay now it will take to uh both of the halves okay [01:11:42] it's like a as a sort it okay now it will run left as a fourth okay uh right as a [01:11:57] so something like that it's there right now it will merge okay [01:12:06] we'll call again okay the left mid and the right okay we are calling [01:12:15] then it will [01:12:18] now we will substitute the value [01:12:22] so now array is like an array [01:12:26] and then left part is like a left part value is [01:12:30] index is like a 0 [01:12:32] and then mid part is also like a 0 [01:12:37] right part will be as a 1 [01:12:40] now we will merge [01:12:47] okay the values are like a left uh mid right 0 0 1 okay algorithm this will take okay so i [01:13:07] equals to left value oh i equals to left value which is a zero value okay and j equals to [01:13:17] mid plus 1 value, which is 0 plus 1 is a 1. Okay. Then we are taking one temporary array. [01:13:33] Temporary. Now we are checking other while i is less than the mid. Okay. And j is less than the [01:13:47] right which means zero is less than the zero okay and one is less than the one [01:13:55] then if both of the two then we are what we are doing [01:14:06] area of i is greater than the area of j we are checking the values which means four is [01:14:14] greater than three four is greater than three then condition will be false [01:14:20] okay it will come to the else okay else value will be like here append the j value j value [01:14:33] means like a three value append the three value and j plus one okay i mean i see um [01:15:01] What you do guys, I will try it, I will try it, I will try it, I will try it, I will try it a little bit confusing. [01:15:47] No, Murshort is never confused, okay, Murshort is never confused, Murshort is never confused. [01:16:11] I have a recursive partner confused. [01:16:25] Once again, we will try. [01:16:49] It's not clear, then 0p2.1, or short, or so on, so, it's not clear, I think, so, correct. [01:18:28] where my shirt is coming as a zero comma zero [01:18:33] okay [01:18:33] I can tell you [01:18:58] it's taken [01:19:15] you [01:19:22] okay [01:19:24] so [01:19:28] I'm [01:19:30] saying [01:19:32] short value [01:19:34] 0,4 then we are calling this function array left and right then we are checking the condition [01:19:56] if left part is so what what is our left okay let's make a password [01:20:04] 0 from a 4 password. If left part is greater than equals to right, then 0 which is 4, then [01:20:30] condition will be return. Return the function which is not here possible because it's never [01:20:37] possible which is false then we calculate 0 plus 4 divided by 2 equals to 2 then [01:20:52] mid equals to 2 okay so left part left part will be will go to the 0 to 2 okay and right part will [01:21:06] will be 4, 2, 3, 2, 4. So, how do I divide? 4, 3, 2, because 0, 1, 2 and then 3, 4. Now, again, [01:21:36] the function will be called, right? So, much short of kya call hura? Array of 0, 2, 2. [01:21:48] divided this one okay now we will divide zero one and two okay so now it will uh take zero to two [01:22:00] so my left value will be zero right value will be two okay again it will check zero is [01:22:08] less than two or not okay which is not false okay it will not return we'll find the mid value [01:22:16] which is 0 plus 2 divided by 2 which is 1 okay now the left part will be 4 3 [01:22:26] 4 3 right part will be okay then again most sort will be called most sort will be called [01:22:40] as a array 0 comma 1 okay because kisko bhi divide karna hai 0 comma 1 that's why [01:22:47] okay so why here zero of all conditions left value only four and right value only three [01:23:04] correct so what short call 0,0 0,0 0,0 0,0 0,0 0,0 call [01:23:25] call ho ga, keep condition jayega, left, right, zero, zero which is true, so ye return ho [01:23:38] jayega, return ho gaya, now the function will is return, now execution returns to the previous [01:23:52] call which is which is 0 to 1 means this will return to this one so this will return to this [01:24:08] one this will return to this one so next line is there right it's like [01:24:18] what is there the next line which is much short of mid plus one mid plus one [01:24:29] and right value no worries so since mid value is mid value is now what [01:24:39] zero is left to mid we pass left to mid to divide [01:24:46] so either zero pass to zero right value will be one okay this one now [01:25:13] one shot of one more one okay array zero plus one [01:25:27] can i say one hand take a minute plus one to zero plus one okay and then one okay so array okay uh [01:25:36] one comma one so uh again it will check the condition left equals to one right equals to one [01:25:43] if left again right one is less than one okay so two i am now both part are individually sorted [01:26:03] the left part is sorted which is four right but is also sorted which is three okay [01:26:10] since it is also checking if there is any mid plus one or like a onto the right again [01:26:21] so the values will be like a like a merge now the merge function will be called okay [01:26:38] which we are taking left mid right okay [01:26:41] left may zero have made maybe zero now right by one again and then okay i equals to left [01:26:54] i equals to left again [01:26:58] if you are confused [01:27:03] i equals to zero because left is zero mid is zero zero plus one is gone which is j equals to one [01:27:12] okay now i will take the temporary value okay [01:27:18] now the current error is four three two ten twelve take it so it will say it while i is [01:27:28] less than mid or the j is less than right okay which is uh zero or there'll be zero [01:27:40] the causal and the j value will be gone and this condition is true okay then it will go and check [01:27:55] out if area of a i equal j area of a zero which means area of a i means area of a zero and area [01:28:13] okay yeah [01:28:19] oh [01:28:29] is [01:28:33] yes [01:28:37] yeah [01:29:05] and then you can add one and then you can check [01:29:15] so j plus one two is less than condition fail [01:29:22] I will check guys. [01:29:35] In the blue cross, there is a shorter area. [01:29:44] I will take a longer area. [01:29:48] I will check. [01:29:54] Wait as a thing. [01:30:11] PKS Kumar Tiwari, without it. [01:30:14] Hello. [01:30:16] Good afternoon. [01:30:17] If you could scroll down, if you could go down, scroll down, not here, you have calculated [01:30:44] the midpoint. [01:30:45] and in midpoint, yes exactly, at this place, you have 4 and 3, can't we do it like this, [01:30:55] we have a single element in the left, and the right side we can have 3 and 2, left [01:31:02] left, you just take a single element, 4, and right side you can have 3 and 2, can we [01:31:11] do that [01:31:13] but [01:31:15] divide [01:31:17] at this division itself [01:31:19] can we have this [01:31:21] I mean [01:31:23] segregate [01:31:25] single element [01:31:27] only left [01:31:29] like you have divided [01:31:31] 4 and 3 [01:31:33] I am saying that we do not do 4 and 3 [01:31:35] here [01:31:37] left side [01:31:39] 4 and right side we can have 3 and 2 can we do that right side 3 and 2 3 and 2 and the left side 4 [01:31:48] this is what I wanted to understand yes okay zero and one fine [01:32:19] No, this is easily understandable, but when you go to the recursive function, you will [01:32:27] get lost. [01:32:29] So that's the main point here. [01:32:33] No worries. [01:32:34] I'll take another example. [01:32:36] Okay. [01:32:37] I'll tell you another thing, okay? [01:32:40] You've understood the merge shot overally. [01:32:43] I think so. [01:32:46] I think Elgo is fine when it comes to implementation using this Python code. [01:32:51] Otherwise, I got the Elgo, yes. [01:33:03] I want to tell you what's in this one, smart print top scheduler, so this is a circular queue, so as I told you, there is a linear queue, [01:33:17] linear linear q follows the p4 value okay first in first off okay so why the circular q came okay [01:33:27] so hope you understand the most short okay i'll take the another example i'll i'll get you [01:33:34] understand in the next class for the bigger one okay so circular q is like why it is came [01:33:42] When you are dequeuing some value, 1, 2, 3, 4, 5, when you are dequeuing some value, like [01:33:58] say 1 for many dequeue, so 2, 3, 4, 5, okay, so 2, 3, 4, 5 value is there, okay, I take [01:34:10] this space is intentionally okay because still memory is there okay because in the queue we are [01:34:22] taking the static part let's say you want to make a queue for the 10 people okay so you made a queue [01:34:29] for the 10 okay here it is here i made a queue for the five people okay so intentionally one space [01:34:36] is then now if i want to insert one value it cannot able to insert because it will say like [01:34:43] a uh q is full something like that okay in the linear queue i'm talking about okay so that's why [01:34:49] the circular queue is came in the circular queue what will happen it will check first okay if the [01:34:56] queue is full or no if the queue is not full okay it will like a [01:35:04] double uh space but i take it it will it will create the space for the new value okay and it [01:35:11] will let's say i mean i want to insert the six do something like that six will insert here okay [01:35:18] something like that that's a circular qv scam so something um it will like a post the element [01:35:28] in the last ticket and it will like a position to last my vocal table something like that will do [01:35:38] so that's why circular qv scam and then uh again another question is there for the [01:35:45] emergency hospital so as it's saying emergency okay so it will implementing the priority one [01:35:53] okay so the priority so here if you see okay this is the value of a three one two okay so [01:36:01] arrival of a one question okay is like a arrival of a one zero one okay is prior time is a three [01:36:10] okay and arrival of a one zero two is like a one okay so first it will uh consider one zero two [01:36:21] and then it will consider one zero three then it will consider this one zero one okay [01:36:26] so this is the priority so in the priority one you will go and insert the value okay [01:36:34] okay so where we can use in a real life okay so this is used in a os okay uh operating systems [01:36:44] there we are using okay and then uh the jobs are coming okay and jobs are coming with the [01:36:55] priority one okay so it will execute according to that so there we are using these things okay [01:37:06] correct so this is very good i'm sorry this class is i think you feel totally wasted so [01:37:18] maybe i'll take the next class till then you can solve this question and understand [01:37:31] uh sir i have another question uh around q uh so when we talk about [01:37:39] let's say in the big data point of i mean in in in the context of big data we have a lot of data [01:37:48] and then we talk about multi-threading multi-processing yes yes it's correct so [01:37:56] when it comes to q in q we are uh if you see uh for for example this uh where we have to process [01:38:05] set each each of the tasks one by one so i mean is it really scalable i mean can we use it in the [01:38:14] real-time use cases or business huge cases because we are not able to scale it since we are talking [01:38:21] about so inside the job only they are using q part okay so um so when you when you are importing the [01:38:29] thread if they import thread or import some async function dot async okay so yeah and under that [01:38:38] code they are using this type of things like a priority queue something like that so they are [01:38:43] abstracting those layers they already implemented those things and they're showing only this part [01:38:50] that so it will search uh the google uh the google it will show like that okay uh sir uh i have [01:39:00] another question not related to this but i can tell you uh one of the components that we use [01:39:05] in our data processing is kafka so we publish messages to kafka topic and when uh basically [01:39:15] when all the messages gets accumulated to kafka topic it basically gets stored into [01:39:21] something called message broker which internally uses queue right so is it the same queue or [01:39:30] it's a i mean and i i think under the hood it it's usually the queue that we are talking here [01:39:37] right [01:39:38] message processing happens one by one [01:39:41] in the fashion [01:39:43] of like we have [01:39:45] in this case [01:39:46] maybe the same few but [01:39:51] I didn't know about [01:39:53] oh okay [01:39:54] but I knew [01:39:56] until the async part [01:39:59] and [01:39:59] the [01:40:02] synchronization the threading [01:40:05] so those kind of [01:40:07] things I knew as a part of [01:40:09] this OS. I didn't [01:40:11] know about the scalable system [01:40:13] like your name. [01:40:16] Okay. [01:40:17] I'm not able to tell you, sorry. [01:40:19] I think so, they are using the fundamentals [01:40:21] only to scale [01:40:23] this. [01:40:25] Because you told me that [01:40:27] under the hood, there is a wrapper [01:40:28] on the stack, on the queue. [01:40:31] So, I think it's all the wrapper [01:40:33] that's basically [01:40:35] parallelizing. It's possible. [01:40:36] Yeah, it's possible. [01:40:37] Yes, but low level [01:40:39] per jayenge to stack you. [01:40:41] He use ho rhea. [01:40:48] Okay. [01:40:48] Thank you. [01:40:49] We guess. [01:40:55] Okay. [01:40:55] See you guys in the next class. [01:40:57] I'm sorry. [01:40:58] Right.