# DAA 13 Sep Lab

- **Course:** 5101 - Design & Analysis of Algo
- **Recorded:** 2026-09-13 00:00
- **Transcript:** 730 segments, 8893 words
- **Made by:** deepdml/faster-whisper-large-v3-turbo-ct2

---
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. So, I think insertion short is already completed. Okay, but I'll repeat the part. I will complete something in 10 minutes. So you are given an array integer, array of integers. Your task is to sort the array using the insertion short algorithm, print the sorted array. So insertion short hotha gaya, like, so I'll come to the queue also, okay, we'll study circular priority, okay, those things, so 4, 3, 2, 9, 5, okay, so what is insertion short? One sorted part is there, another one is the unsorted part is there, correct, sorted part. Another one is unsorted part. So our algorithm will take the first element as a sorted. It will think in the mind that I will take the first element as a 4. I think it a sorted one then remaining element will be there as it is correct correct then

first element will come as a three it will compare with the sorted part okay see there is a sorted part and there is an unsorted one okay he pura unsorted he pura sorted so i will take one element and compare with this four okay i want to take from the unsorted part and put it in a sorted part. So, for that what I need to do? Sorted part should be sorted. So, I need to compare with the existing element whether it is a sorted or not. So, I will compare with the 3, with the 4. 3 is a less than 4. So, I need to keep three first then four okay then right then one sorted part will be two nine five okay then another element will come okay two two will first compare with the three okay now two will compare with the three okay two is less than three okay it will again compare with the four and it will say okay it's the lesson okay ll if here only okay then comes to nine okay nine will compare to the two okay okay it's a greater something kind of then it will compare with the three okay okay it's

okay so when we are comparing with uh two with these two elements first it will compare with three okay if it is a like a something kind of a lesser element it will not go for the another greater element which is already greater than the uh it's compared recently correct so when it's compare nine compare with the two okay it will say like a nine is a greater okay i'll push okay now it's compared with the three okay it's a greater i'll push it's compared with the four okay it's also a greater so i'll push forward and keep it here in the last finally the last element okay it will compare with the two okay okay two is a greater something i'll push three is later okay five is greater than the three i'll push forward then four okay four kind of a greater also like a five uh sorry nine nine is kind of a greater than the five okay so it will keep here okay and then nine as it is correct so this is only the insertion only okay so this is the only

insertion short algorithm nothing just you are inserting one element into the sorted part you are comparing with uh the uh elements okay which is uh which is whether it is a greater or like a whether it is a smaller okay and then you are placing the uh blessing it with the right place correct right positions that's only the instructions okay what happened in the part short it will first find the correct divide point okay then it will divide divide divide okay like a british so like british's what they did divide and conquer right so like that mushroom will also work okay so it will divide divide divide then it will compare okay so it will compare with the other uh elements okay then it will merge okay okay so i am dividing with uh so imagine this okay i divide it okay this is the divided part some somewhere in between we are okay so now it will compare with this element with this this this okay now it will place here okay

so something like that it will merge okay so this is only the much short algorithm okay so i'll i'll tell you the algorithm part also okay so i'll try and also the insertion part ticket so there is no need to worry um so let me take the input okay and input okay sorry it and input array list of map root or split okay so i already uh like it told you uh that why we are mapping with int and string okay here we are taking how many elements are there okay and here we are taking uh the array list okay correct and then what we will do we will uh pattern for loop which will loop uh in this and an elements okay and it will check whether the j part okay like a uh whether this part okay is uh compare with this part okay something like that will uh check and then it will do the operations we'll we'll see okay for i in range of one to n there is a reason behind why i'm taking one okay not from only m okay Okay and then I will take one key. Okay key value will be the current element you can say okay

current element from the unsorted part and then I'll take j as a i-1. Okay because we need to check with this one. So while j is greater than 0 and array of j is greater than p then you perform the operations array of j plus 1 equals to array of j then j equals to j minus 1. j equals to j minus 1 and then i'll i'll place the key value also okay like a key value will j plus 1 will be the key value and then we'll print the whole array okay i'll print the whole array okay so in the first line we will take the input okay so let's say ashish umar and take that out okay so let's say we are taking n as a five okay then we'll read the array okay uh indeed the array okay so let's say we are taking areas of four three two and twelve okay something like that then my array value is like this okay if you want in an index manner okay i'll tell like uh zero one two three four something like that then uh we are taking we taken the n as a fight right so for i in

range of a one two five it means like a i'll i will starting from the one two till four okay because range is taking i minus one so that's why now what is that t value will be array of a ith okay so array of a one okay three value okay so it means value of a three okay t value will be t value will be here three okay if you want i'll explicitly write as a array of one okay which is three okay i value will be one okay uh j value okay i value here is a one okay and j value will be i minus one uh one minus one one minus one which is zero okay so now it is pointing to j value is pointing to 4 and key value will be pointing to 3 okay now we will compare okay now while while loop will be start okay now while j is greater than zero okay so why j is greater than zero i'm writing okay because uh uh malaki minus one main because it will not go to the minus one something kind of okay so that's why till the zero i'm checking okay not

less than that okay so that's why i'm checking uh this one again so uh and array of a j is greater than the key value okay okay and value means okay so if you studied the uh coa something computer organization architecture so and will check both conditions both conditions to be true okay and ko true honne ke liye kya sahi rye and true honne ke liye true and true chahi right to result in true right so both conditions have to be true to become this whole condition true okay if one condition will be false then whole the condition will be false right so that's a and and check okay so yeah uh then this will pass because zero is less than sorry zero is greater than equals to zero and this one okay so i'll copy this okay and write it here so array of a zero array of a zero means four okay so now it will check four is greater than three okay four is greater than 3 which is coming as a true okay is coming as a true so both conditions will be true

so uh it will enter the while look correct okay the condition so array of a j plus one will be this one so array of j plus one will be uh equals to array of a j okay so array of 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 array of a 1 will be now array of a 0. Okay now array of a 1 will be equals to array of a 0 means 4. Okay so it will swap. Okay now array becomes what? see uh absolutely okay so you're thinking like the it will swap the value and four will become the three okay now three will become the four no not like that under the hood okay it is something like this still something like this okay so under the hood it is still something like this 4 4 2 10 12 okay understand this okay so we did not enter this we did not enter this one correct so till then that okay our array is something like this so let's say in a competitive questions okay so competitive website so uh so something after this so what will be the

array value okay so don't like something uh three four don't write right like this okay so there will be a option like this also okay Okay, so it will not change, got it, so now the j value would be j minus 1, okay, now j equals to 0 minus 1, okay, so j value will be minus 1, okay, j is now pointing to the minus 1 take care now it will check again okay now it will check again with the same condition okay now it will check with the same conditions okay like a uh minus 1 is greater than equals to 0 so it will again false okay it will again false so one condition is false okay it will not check this condition okay so again uh something like in exam it will uh tell you like if this condition is checked and is this also gonna check no it is not gonna check it in the and operator okay until this one is it true okay so uh this is not going to be checked okay so once it is true then it is also going to be checked so once it is false it is not going to check the second

conditions okay got it so j value will be minus one so that that's condition gonna false okay so loop will be stopped okay loop will be stopped and tell you like something like a false okay we are getting false due to false one while you will be stopped because uh this gives you false okay okay now what happened uh huh either hum log or a condition like that right so array of a j plus one okay array of j plus one will be the key okay i'm popping this okay array of j plus one which is minus one plus one okay array of minus one plus one will be your key so now what what is the key value a value is three okay now it is going to be changed okay did i tell you okay so when i see this condition sorry maybe my mistakenly aapko is conditions ko leke many iska point out but there is a swap kind of things okay so area of a zero will be the three correct now it uh the error will become three two two ten twelve water so this is how it is going to be

changed correct so for the simplification purpose for the simplification purpose i told you like yeah there you will insert okay so some if you will see something like this only happening okay under the hood okay but why the insertion uh the name part is there so i tell you like yes i portrait like this correct so now this loop will run again uh for the iteration one okay so uh yeah for the iteration zero it uh sorry first iteration is done okay so it will run for the second iteration now key value will be the area of i okay so if i will tell you okay p value will be the area of i we are taking like this correct now p value will be array of one is one is already done right so it will come as a two okay so p equals to two now Now, i equals to 2 and key value will be array of a 2, 0, 1, 2, which is also 2. Let me also, so the indexing, so that it will not confuse. So, this one already run, right? One part.

So, now we are going to the two part. So, two part value is 2, correct? Now, our array is like a 3, 4, 2, 10, 12, which is an updated array. Now, we are checking what? j equals to j minus 1. Now, we are taking j equals to j minus 1, which is 2 minus 1 is 1. 2 minus 1 is 1 okay j equals to 1 okay now while loop will be checked okay so easily pass okay because uh this is 1 1 is already bigger than 0 okay and and value is like an array of a j array of a j is like a key okay so array of which is one key value key value will be two okay you are imagining like this so array of a one so array of a one is what this one correct to 4 okay again it is gonna say okay area of 1 equals to 4 now 4 is already greater than 2 which is 2 so the both conditions are 2 okay it will enter in the group okay it will enter in the loop sorry and what's inside the loop j plus one equals to j right we will write the j plus 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

2. Correct. So, area of a 1 plus 1. Correct. Equals to area of a 2 and now area of a 1. 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 so now we are surfing the value of a 2 with the 4 correct the updated array will be 3 4 4 10 12 correct 3 4 10 12 okay now j will become j minus 1 okay j minus one this one minus one okay one minus one will be zero okay now it will again check for the loop okay while zero is greater than zero okay it is true while zero is greater than zero which is first condition is true area of a zero is greater than two it will again check so array of a zero is what three okay so is three is greater than two okay again i'm writing here array of a zero is three so three is greater than two which is coming as a two okay it will again enter enter in the loop okay it will again enter in the loop 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

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 area of a zero okay area of a one is what uh sorry area of a one is now become three correct so area of one becomes now three so now the updated loop will be like three comma three comma four comma ten comma one okay now it will check j equals to j minus one okay condition will be failed okay hope you are understanding how it is because j is now 0 minus 1 which is coming as a minus 1. So condition will be failure in the in the while loop. So it will come out of the loop and it will say like j plus 1 is like a key. okay their condition right so over j plus one will be the key correct so now what is my j value j value will be my minus one okay is one now the key value will be two okay so array of 0 में क्या हो जाएगा अब का 2 चला जाएगा ठीक है so now my updated index will be 2 sorry 2 3 4 10 12 got it itna part pura sort हो कहा है itna part unsorted

you can see it is a sorted ठीक है but although it will check ठीक है for the the iteration thing okay so this is how the loop will run and check got it then uh hope this is flat fried okay and also like a scope with hand if you're preparing for the competitive something so it's just got behind that now okay it's just for or like many kind of thought or now comes to the oh yeah wait a second sorry hi hi sir good morning morning this is the place So basically, when we studied insertion, basically we said that it's in place sorting. It means that it will repeat a pattern every time. That's why it was in place sorting. I can't understand. I have to tell you that the insertion sorting is nothing just you can understand sorted part I have to tell you what I did I have to start with 1 because I have to compare value 3 compare okay but I'm like this J value I'm minus one so I'm seeing this J value sorted J value I'm sorted means that

if you can understand this one part I'm sorted and the other part I'm sorted now I'm going to one-one value so I'm going to compare it something you can invest so you know definition is sorting specific place sorting in place sorting in place sorting I'm sorry if you understand that it's different you can tell that it's different I didn't know what I did insertion I didn't know what I did this is different this is different okay thank you Asis hello Asis hello hi good morning sir good morning hope you are good sir last week we had a news that you were not well so sir my question is that sir you have shared couple of links for the assignments in lab lab sessions so it is good to see that we have a couple of exercises to do so my question is that are these compulsory or we can practice it later and get it done because something okay fine noted sir thank you so much and it is showing us six days so i missed i think the first one so no no no all the assignments i

have opened okay it is no any context timings like for a week or something but uh i'll i'll again like a close this on next 20 okay like a 20 i'll close all the assignments if you didn't submit it yeah okay i'll surely submit sir thank you so much sir and sir one more question is that among all the sorting algorithms which one is more effective which one is more effective or which one is more prominently used in most of the yes sir thank you vidyaraj hello sir my assignment my doubt is related to assignment three for the first question there were no marks it's just showing zero even after solving i already told you like it's having some problem i even don't know what is happening maybe glitch so it's also not showing to me it's also showing to me zero mass even if you solve or something I can't do anything so keep it as a submitted I'll take the I'll take from there okay so the marks will be allotted to us

even when it's not showing okay thank you Kunil Kumar hi sir so my question is I'm a bit confused with the time complexity I can see that merge is better but I can see that there are more comparisons done so when we were discussing in the class in the theoretical class it was told that the number of comparison is directly proportional okay for an efficiency of an algorithm so if I'm when I'm seeing the merge sort I can see you're dividing the area you're comparing once within the area and again again we are comparing it with different arrays and so I can see that number of comparisons are more here but still i can see that the type of complexity is better than binary search so i'm a bit i mean binaries uh sorry um the um the other sort i mean mud sort i mean um what was the insertion sort so no no no no no i am that's I am reading the insertion sort, so do you compare the insertion sort to insertion sort?

No, this is merge sort. Merge sort, we divide it first. No, insertion sort. Okay, so you are still... Okay, I thought it's merge. You can continue. okay i'm okay i'm maybe i'm maybe wrong which i was of the opinion that you have to discuss okay if it is insertion it's fine sorry no no no i just completed insertion right but i didn't continue i didn't take a question okay okay thank you okay Saurabh Kumar Pandey Am I Audeva? Yeah, you are Audeva Just a simple question Or you can say the doubt is that Can we not use two of the four loops regardless of while? I didn't understand What do you have done now? One for loop and one for loop So I'm asking that we can do this with two for loops is a I love you for a look at me like I say hello for I in a range of one-two length of error okay and for J in a range of I do zero minus one minus one step count minus one foreign You can use it, it's easy, so you don't have to use it.

Okay. That's it. Thank you. No, both of them. Okay. Thank you so much. Shraddha Kamath. Hello. Yeah. I had a doubt in time complexity. In general, in time complexity, if there is a for loop, it's n. If there is a for loop, it is n into n minus 1, so it is O of n square. So how do we calculate the time complexity in this? So, in the insertion short, basically, we calculate three types. So, in the insertion short, the worst time complexity is big of n square. And if you look at extra s time complexity, it is big of n. Okay. And... I think... ...Abdulwari is a video. You can see it. You can calculate it. You can refer it. Okay, okay. But in general, we can say it's N. But inside there's a while. So then how do we calculate? Okay, okay. first if I have to speak a little like I'll explain better maybe I can't explain what's the problem no okay okay thank you Aditya Puma maybe he's not there Kahlib Puma hi sir actually I have done the insertion

chart but my taste coverage is failing taste coverage yeah I mean example was there so I am able to run the instance short and I am getting the sorted array but when I am trying to submit the code the test coverage is failing the coverage was failing? yeah exactly I did the same pseudo code the same way I put there which test basis is failing? it's all actually it's all like all of the all these cases yeah well submit the code i'm not possible man i submitted it two times like something wrong but run to run to hora sir i don't think so i will check i will check on this yeah thank you yeah okay we'll move to the next question so next question is like around much short take them so much short is a shorting algorithm only okay based on the divide and conquer technique it works in uh like a simple two steps okay First divide, which means like you break the array into smaller halves until each part contains the only one element, correct.

And then it will conquer and merge. It's like merge the smaller sorted arrays together to produce the, to produce one sorted area take it so it will produce one sorted area uh which will include the smaller sorted areas which is a even one one one one elements like a one element is like a two only one element is three only so that is even sorted right so it will include that and it will compare okay so something like so if i will give you the example same example we are taking okay four three two 10, 12. So it will divide as a left half and it will divide as a right half, 4, 3, 2, 10, 12. Then it will again keep divide. It will again divide 4, 3 and it will divide like a 10, 12. Again it will divide like a 4. So it will divide the array until it reaches to one one element and well okay now it will merge okay so now it will merge like a three four okay It will first merge like 2,10, then for like 12, then it will 3,4 again, 2,10, then it

will merge, so like 3,4, here 2 will come, and then, correct. so there is an important thing like a merge shot doesn't sort everything by comparing the adjacent element it divides the array and sorts the smaller past and merges to merges those parts in a order okay so there is a two function okay so one is a merge function and another is one for the uh find another one is for like a sorting function okay set it so so there is a two functional uh much what you can see okay so so one is like a merge so in the merge uh it will take an array first okay then it will take the left part then it will take the right part then it will take the mid part correct and then will assign i value will be the left if j value will be the mid plus one okay so something like you can imagine um i value will be the something around left part j value will be the i plus one okay sorry the mid plus one so this is the middle value okay

plus one so starting from here okay i value will be starting from here take care okay now it will take the now we will take the temporary array limit okay i'll tell you why okay i will compare like a if it will come there later uh i to this one okay make okay i made the one oh so better right after this okay i will comment this okay it is very confusing better first we will divide okay so so something like first array there is no part okay so there is no mid part okay we'll simply take like a uh array left or right okay then i will compare if left part okay is greater than the right part okay part is better than the right part then return uh it means like a if something uh it's like a swapped already okay it compared compare and it's swept something like you can imagine okay i'll try and then you can see okay what do i mean by this okay so we will find first mid value okay so mid value left plus right divided by okay this is how we

divide okay then i will write like a again call this function okay more short array then i will again divide okay this is the first division okay so so this is the first division okay then i'll again divide right again divide so for that i'll write again another function correct so that one is left to mid okay why left to mid because once you divided the first one okay goal array then you will divide the sub parts also correct sub parts so for that i need to find the middle value correct so left to mid we have to go correct so for that i am writing left to mid then another part i will divide array mid plus one two mid plus one two right here then i will merge okay then i will write the merge function so for the merge function what what do i need array value left value meta value and the right value okay correct so this is where we divide it okay now we will write the merge function okay so for the merge function here it

Yes, all the parts are divided now. Okay, now we will merge. Okay, so we will make this merge. Copy this, paste it here. Okay, so I value I am taking as a left one, J value I am taking as a a hit plus one. Now I am taking one temporary array, then I will come there. While i is less than the middle. So i is less than the mid. i is less than the mid, this is checking the positions only, okay, the positions check current and j is greater than right, okay, so this all you've seen, okay, the positions check current, only the positions, not the values, okay, j is less than the right, if array of elements i is array of j then temp and array of i and i equals to i plus one okay if it is not lesser then what we will do we will like a plus our first let me write okay then drive and then i can understand then i is less than the mid and j is also less than the right okay i is less than equals to mid i is less than equals to mid

I am so I am but she got your and I am and I think we've got to say and like leftovers. Leftovers ke lhe, or a truth chalega. For k in a range. For k in a range. Length of temporary third. K of a left plus k. Okay. So, abhi we make it lehke dhekna hai. Array 4, 3, 2, then 12 okay then much short much short of l8 0 1 2 3 4 right so first this function will be called take it uh so first we are uh like n minus one like if you are taking the end as a uh for it then we will go uh n minus one um in the mod shot then it will check yeah then it will check like a other uh left okay evil conditions check right so if left is like something greater okay so left one is a greater right because we are passing no sorry left one is not a greater okay so it will not go inside this loop because condition will fail okay then it will go to this one again now this condition will be angry okay just wait for a second it will go to this okay

or the left goes to 0 and the right goes to 4. The mid value will be simply 2. So, 2 means the left part will be 4, 3, 2. Why this is? Because 0, 1, oh okay two to divide okay okay now rest will go to the right part okay 10 and 12 so rest it will go to the right part 10 and 12 okay now uh so conditions are correct right so if uh zero is greater than four then uh it's not satisfying right so i'm talking about this one okay so this one okay so it will not go to the blue it will not return okay now it will divide right or divide the reader then again it will divide uh zero comma two not short of not short of any past here left okay what is the left value that will be will be zero zero comma two okay and then now mark short of area mid plus one mid plus one okay then right so then again it will check if i may this condition to include karta ho so then it will say it will false okay then don't go to the loop okay

so it will not go to this one okay so then it will calculate the mid okay so then again the left part will be four comma three because the mid how the mid mid is calculated zero plus two divided by two okay one okay that's why i'm dividing zero till one okay then rest right part right part two right because four three two thaw so one tak divide kya minne so the right part will be two then again it will call the much short zero comma one okay then again it will divide again left goes to zero right will be one okay then mid value calculated is zero zero plus one divided by two which is zero okay why zero not 0.5 okay because we are going to take an integer explicitly that's why it will not come as a 0.5 okay it will come as a zero okay ceiling value right right so left part will will be 4 and right part will be 3 okay because my 0 divided mid value 0 to 0 so that's why one value will become again it will go and check again it will go and check

so again it will call array 0 left part is 0 mid part is 0 if left is better than the right It will going as a mid value, but as a right value, so it will say yes, 0 is greater than 0, which is coming as a true. So once it come as a do, what is the value? Return. So it will return. The function will stop here. And the element, a single element is already sorted. Like the single element is always sorted. So it will return again. So first recursive call is finished. Okay, we can say, so this is the, all calls are recursive calls only, taken. So first recursive call is finished. Okay, then it will go to the next one. Okay, next one means the merge array mid plus 1. Okay, the right value. Let me show you the function. Okay, so what happened? So this function is calling itself until this condition is satisfied. So once it is satisfied, what it says return. So where to return? Where you are coming from? There you return.

Where I am coming from? From this function I am coming from. So this will return to here. Once it is finished, then it will jump to next line. right so this is how programming works right so once the line one finished then it will go to the second line right so once this recursive call is finished because this condition is satisfied okay now it will go to the this function okay so now it will call as a recursive trigger so now i'm calling this function hope you are getting now abhi area so what's the the mid value, mid value will be now zero. So what is the last mid value is like a zero. And what is my right value also? Now we will call the second recursive. So what is my right value it is 1 right so now much short okay much short of i am writing again writing as a mid value as a 0 okay now right part will be as a 1 okay right part will be as a 1 uh so much short area of 0 plus 1 plus 1 jayega. Now I'm not sure of the area of 1,1. So it will again

see as a condition I have. So if 1 is greater than 1, then you return. i'm always confused in a recursive post so one is uh greater than one so return for us go so condition will be satisfied it will return okay now both halves are sorted so both of us are sorted means like a four comma three is sorted and the next time when they run wait second mid plus one mid plus one is so mid value is zero but right value for one so one you know one higher okay so four comma three okay guys so now what will happen okay it will say as a 4,3 okay like individual value so first of all it will uh divide okay divide divide divide then it will get merge only will take the what is divided okay purely divided what is purely divided now four and three okay now it will take to uh both of the halves okay it's like a as a sort it okay now it will run left as a fourth okay uh right as a so something like that it's there right now it will merge okay

we'll call again okay the left mid and the right okay we are calling then it will now we will substitute the value so now array is like an array and then left part is like a left part value is index is like a 0 and then mid part is also like a 0 right part will be as a 1 now we will merge okay the values are like a left uh mid right 0 0 1 okay algorithm this will take okay so i equals to left value oh i equals to left value which is a zero value okay and j equals to mid plus 1 value, which is 0 plus 1 is a 1. Okay. Then we are taking one temporary array. Temporary. Now we are checking other while i is less than the mid. Okay. And j is less than the right which means zero is less than the zero okay and one is less than the one then if both of the two then we are what we are doing area of i is greater than the area of j we are checking the values which means four is greater than three four is greater than three then condition will be false

okay it will come to the else okay else value will be like here append the j value j value means like a three value append the three value and j plus one okay i mean i see um 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. No, Murshort is never confused, okay, Murshort is never confused, Murshort is never confused. I have a recursive partner confused. Once again, we will try. It's not clear, then 0p2.1, or short, or so on, so, it's not clear, I think, so, correct. where my shirt is coming as a zero comma zero okay I can tell you it's taken you okay so I'm saying short value 0,4 then we are calling this function array left and right then we are checking the condition if left part is so what what is our left okay let's make a password 0 from a 4 password. If left part is greater than equals to right, then 0 which is 4, then condition will be return. Return the function which is not here possible because it's never

possible which is false then we calculate 0 plus 4 divided by 2 equals to 2 then mid equals to 2 okay so left part left part will be will go to the 0 to 2 okay and right part will 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, the function will be called, right? So, much short of kya call hura? Array of 0, 2, 2. divided this one okay now we will divide zero one and two okay so now it will uh take zero to two so my left value will be zero right value will be two okay again it will check zero is less than two or not okay which is not false okay it will not return we'll find the mid value which is 0 plus 2 divided by 2 which is 1 okay now the left part will be 4 3 4 3 right part will be okay then again most sort will be called most sort will be called as a array 0 comma 1 okay because kisko bhi divide karna hai 0 comma 1 that's why okay so why here zero of all conditions left value only four and right value only three

correct so what short call 0,0 0,0 0,0 0,0 0,0 0,0 call call ho ga, keep condition jayega, left, right, zero, zero which is true, so ye return ho jayega, return ho gaya, now the function will is return, now execution returns to the previous call which is which is 0 to 1 means this will return to this one so this will return to this one this will return to this one so next line is there right it's like what is there the next line which is much short of mid plus one mid plus one and right value no worries so since mid value is mid value is now what zero is left to mid we pass left to mid to divide so either zero pass to zero right value will be one okay this one now one shot of one more one okay array zero plus one can i say one hand take a minute plus one to zero plus one okay and then one okay so array okay uh one comma one so uh again it will check the condition left equals to one right equals to one

if left again right one is less than one okay so two i am now both part are individually sorted the left part is sorted which is four right but is also sorted which is three okay since it is also checking if there is any mid plus one or like a onto the right again so the values will be like a like a merge now the merge function will be called okay which we are taking left mid right okay left may zero have made maybe zero now right by one again and then okay i equals to left i equals to left again if you are confused i equals to zero because left is zero mid is zero zero plus one is gone which is j equals to one okay now i will take the temporary value okay now the current error is four three two ten twelve take it so it will say it while i is less than mid or the j is less than right okay which is uh zero or there'll be zero the causal and the j value will be gone and this condition is true okay then it will go and check

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 okay yeah oh is yes yeah and then you can add one and then you can check so j plus one two is less than condition fail I will check guys. In the blue cross, there is a shorter area. I will take a longer area. I will check. Wait as a thing. PKS Kumar Tiwari, without it. Hello. Good afternoon. If you could scroll down, if you could go down, scroll down, not here, you have calculated the midpoint. and in midpoint, yes exactly, at this place, you have 4 and 3, can't we do it like this, we have a single element in the left, and the right side we can have 3 and 2, left left, you just take a single element, 4, and right side you can have 3 and 2, can we do that but divide at this division itself can we have this I mean segregate single element only left like you have divided 4 and 3 I am saying that we do not do 4 and 3 here left side

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 this is what I wanted to understand yes okay zero and one fine No, this is easily understandable, but when you go to the recursive function, you will get lost. So that's the main point here. No worries. I'll take another example. Okay. I'll tell you another thing, okay? You've understood the merge shot overally. I think so. I think Elgo is fine when it comes to implementation using this Python code. Otherwise, I got the Elgo, yes. 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, linear linear q follows the p4 value okay first in first off okay so why the circular q came okay so hope you understand the most short okay i'll take the another example i'll i'll get you understand in the next class for the bigger one okay so circular q is like why it is came

When you are dequeuing some value, 1, 2, 3, 4, 5, when you are dequeuing some value, like say 1 for many dequeue, so 2, 3, 4, 5, okay, so 2, 3, 4, 5 value is there, okay, I take this space is intentionally okay because still memory is there okay because in the queue we are taking the static part let's say you want to make a queue for the 10 people okay so you made a queue for the 10 okay here it is here i made a queue for the five people okay so intentionally one space is then now if i want to insert one value it cannot able to insert because it will say like a uh q is full something like that okay in the linear queue i'm talking about okay so that's why the circular queue is came in the circular queue what will happen it will check first okay if the queue is full or no if the queue is not full okay it will like a double uh space but i take it it will it will create the space for the new value okay and it

will let's say i mean i want to insert the six do something like that six will insert here okay something like that that's a circular qv scam so something um it will like a post the element in the last ticket and it will like a position to last my vocal table something like that will do so that's why circular qv scam and then uh again another question is there for the emergency hospital so as it's saying emergency okay so it will implementing the priority one okay so the priority so here if you see okay this is the value of a three one two okay so arrival of a one question okay is like a arrival of a one zero one okay is prior time is a three okay and arrival of a one zero two is like a one okay so first it will uh consider one zero two and then it will consider one zero three then it will consider this one zero one okay so this is the priority so in the priority one you will go and insert the value okay

okay so where we can use in a real life okay so this is used in a os okay uh operating systems there we are using okay and then uh the jobs are coming okay and jobs are coming with the priority one okay so it will execute according to that so there we are using these things okay correct so this is very good i'm sorry this class is i think you feel totally wasted so maybe i'll take the next class till then you can solve this question and understand uh sir i have another question uh around q uh so when we talk about 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 and then we talk about multi-threading multi-processing yes yes it's correct so when it comes to q in q we are uh if you see uh for for example this uh where we have to process set each each of the tasks one by one so i mean is it really scalable i mean can we use it in the real-time use cases or business huge cases because we are not able to scale it since we are talking

about so inside the job only they are using q part okay so um so when you when you are importing the thread if they import thread or import some async function dot async okay so yeah and under that code they are using this type of things like a priority queue something like that so they are abstracting those layers they already implemented those things and they're showing only this part that so it will search uh the google uh the google it will show like that okay uh sir uh i have another question not related to this but i can tell you uh one of the components that we use in our data processing is kafka so we publish messages to kafka topic and when uh basically when all the messages gets accumulated to kafka topic it basically gets stored into something called message broker which internally uses queue right so is it the same queue or it's a i mean and i i think under the hood it it's usually the queue that we are talking here

right message processing happens one by one in the fashion of like we have in this case maybe the same few but I didn't know about oh okay but I knew until the async part and the synchronization the threading so those kind of things I knew as a part of this OS. I didn't know about the scalable system like your name. Okay. I'm not able to tell you, sorry. I think so, they are using the fundamentals only to scale this. Because you told me that under the hood, there is a wrapper on the stack, on the queue. So, I think it's all the wrapper that's basically parallelizing. It's possible. Yeah, it's possible. Yes, but low level per jayenge to stack you. He use ho rhea. Okay. Thank you. We guess. Okay. See you guys in the next class. I'm sorry. Right.

