[User] Please transcribe this text

[Assistant] So we need to understand what is happening at step number 3, 3.1 and 3.1.1.


[User] Please transcribe this text

[Assistant] Now, if you've seen the working, that is part 1 of RadixSort,


[User] Please transcribe this text

[Assistant] I said that if we have three digits, counting sort or you know, the process should be repeated three times. If it is four digits, it would be four times. So we need to have that mechanism programmatically also, right? So some kind of algorithm or some kind of arithmetic calculation should happen such that counting sort will be called only three times. So this is where this for loop condition comes into picture. So let's evaluate this for loop condition. Okay.


[User] Please transcribe this text

[Assistant] So coming inside this for loop we are saying int div equals to one. So initially div value is equal to one. Then we are saying m divided by div has to be greater than zero.


[User] Please transcribe this text

[Assistant] What is em here? We've decided that the max em over here is 802. That is the max value in the array. So now the condition is em.


[User] Please transcribe this text

[Assistant] Which is 802. So let me write it over here. 802. So m divided by div is equal to 802 divided by


[User] Please transcribe this text

[Assistant] One, because div has become one, initially. That is the first time div is one.


[User] Please transcribe this text

[Assistant] Now this m divided by div equals to 802 by 1 which is obviously gonna be 802. Now is 802 greater than 0? This is the condition. So this is the condition part. So 802 is obviously greater than 0. So we will go inside the for loop. So this is pass 1. Okay.


[User] Please transcribe this text

[Assistant] Let's not consider 3.1.1 as of now. Let's assume that we've done pass 1. So pass 1 is done.


[User] Please transcribe this text

[Assistant] Now we again come back to the for loop. Now the increment is happening as follows. It's saying div star equal to 10. What is the star equal to? Star equal to means div is equal to div star which is multiplication 10. So initially obviously div was 1. Okay. So now it would be 1 is equal to 1 star 10 which is gonna be 10.


[User] Please transcribe this text

[Assistant] But this condition I hope you have understood or this increment operation is happening in multiples of 10. So now second time div has become 10. Now again the condition will be checked. m by div. So this time div is 10.


[User] Please transcribe this text

[Assistant] So 802 divided by 10 is equal to 80.2, but since it is an integer.


[User] Please transcribe this text

[Assistant] M is also integer and this div is also integer. This.


[User] Please transcribe this text

[Assistant] Fractional part will be truncated, obviously it is not considered when we go ahead in programming part.


[User] Please transcribe this text

[Assistant] So is a t greater than zero? That's the condition. That is m by div greater than zero. Is a t greater than zero? Yes.


[User] Please transcribe this text

[Assistant] Again, let's not consider 3.1.1 as of now. Let's see this counting sort is called second time. And now again, we are coming at the for loop.


[User] Please transcribe this text

[Assistant] So coming back at the for loop for the third time, now div again becomes div star equal to 10. div is already 10. So 10 star equal to 10 means 10 into 10 that is 100.


[User] Please transcribe this text

[Assistant] And that is what is stored in div variable. So div becomes 100. So now div value is gonna be 100. Okay. Again m value is obviously gonna be 802. So this time the condition again is gonna check m by div which is gonna be 802 divided by 100. So this time it would be 8.02. And as I mentioned the fractional part will be truncated. Now 8 is still greater than 0.


[User] Please transcribe this text

[Assistant] Obviously, that is the condition, m by 2 should be greater than 0. So this is true, so we will have pass 3. Right?


[User] Please transcribe this text

[Assistant] And now let's say again the counting sort is called, we again come back at the for loop. This time div becomes 1000. Because div star equal to 10 would be 100 into 10. So 100 into 10 would be 1000. So div now becomes 1000. And now when we do m by div, it would be 802 divided by 1000, which is 0.802.


[User] Please transcribe this text

[Assistant] And since fractional part is truncated, we are left with zero. So is zero greater than zero? No. This time zero


[User] Please transcribe this text

[Assistant] Is not greater than zero. It is equal to zero, but it is not greater than zero. So this time the for loop condition will become false and the fourth round of counting sort will not happen. So now you can see that depending upon how many digits we have.


[User] Please transcribe this text

[Assistant] In the maximum number, that many times we are having passes. So we had 3 passes.


[User] Please transcribe this text

[Assistant] So this is how programmatically you can control the number of passes depending upon the number of digits in the maximum number.


[User] Please transcribe this text

[Assistant] Because if you see inside the counting sort, we are passing this div.


[User] Please transcribe this text

[Assistant] So why are we passing this div will be only understood when we take a look at this counting sort algorithm.


[User] Please transcribe this text

[Assistant] So now let's take a look at this counting sort algorithm. Okay, so I hope you understood how


[User] Please transcribe this text

[Assistant] Three times counting sort is called using this for loop and using this condition. Make a note of these values of div. Especially the first three values. That is one.


[User] Please transcribe this text

[Assistant] So let me write it above somewhere and then we'll go to counting sort pseudo code.


[User] Please transcribe this text

[Assistant] Things would be very similar except slight difference. So let's see what the difference is.


[User] Please transcribe this text

[Assistant] Okay, so this is the pseudocode for counting sort function. And if you remember the counting sort that we've seen in the original counting sort tutorial.


[User] Please transcribe this text

[Assistant] We were only considering array and the size of the array and the first step was to take the input. But over here we are passing the input as arguments in this counting sort function. So that first step is missing. Apart from that, we are using this extra div variable, which is coming from the for loop and every time


[User] Please transcribe this text

[Assistant] In the for loop, the div value changes from 1 to 10 to 100. Okay, so only three values are gonna be passed. That's why I've written it over here.


[User] Please transcribe this text

[Assistant] And now let's go step by step. A lot of things are gonna be similar. So first thing is obviously create the output array because in counting sort we create auxiliary array to store the output and then transfer all the values from the output array into the original array that is the input array.


[User] Please transcribe this text

[Assistant] So first things first, create output of the same size of the input array. So whatever size of the input array, we have to create an output array. So let's do that. Okay, so here we have the output array. This is also of size 8. Next step is to take the range or number of unique elements.


[User] Please transcribe this text

[Assistant] In Radix sort, what happens is counting sort is called on individual digits. So counting sort will be called for the unit's place once.


[User] Please transcribe this text

[Assistant] So ultimately, the range of unique numbers is always gonna lie between 0 to 9. Which means we only have 10 unique elements. Elements or numbers. Right?


[User] Please transcribe this text

[Assistant] So that's why the range in our case is always gonna be 10 because in a decimal number system,


[User] Please transcribe this text

[Assistant] 0 to 9 are the values that are single digit numbers. We don't go outside that range. So that's why range in our case is 10. Now why do we need this range?


[User] Please transcribe this text

[Assistant] Because as you remember in counting sort, we have to create a count array which will be of the size range. So this is what the step three is. We are saying for int i equals to zero to i less than range.


[User] Please transcribe this text

[Assistant] And we are creating a count array. I have not mentioned we have created a count array in, you know, after step two, but consider that we are creating a count array.


[User] Please transcribe this text

[Assistant] Of the size of range and we are making all the values initially zero. So let's create that.


[User] Please transcribe this text

[Assistant] So this is our count array of size 10 because that's our range.


[User] Please transcribe this text

[Assistant] And range is the number of unique elements. We have 0 to 9 which means we have 10 elements. So our count array also becomes size 10.


[User] Please transcribe this text

[Assistant] I've made one more count array, it is basically one and the same thing. That's because in next step, we will take the cumulative count just like what we did in the counting sort.


[User] Please transcribe this text

[Assistant] So yeaah, the first time, that is this first for loop in step 3, we are saying from 0 to the range, so from 0 till the range, that is from 0 to 9, we are making all the elements 0. So the count initially is gonna be 0. Okay?


[User] Please transcribe this text

[Assistant] Okay, so now next step is we have to increment the count in the count array depending upon which digit we are considering in the input array.


[User] Please transcribe this text

[Assistant] Now in plain counting sort, in the simple counting sort algorithm, it was an easy scenario because we were only considering digits.


[User] Please transcribe this text

[Assistant] Or numbers, which were single digit numbers. So our range itself was 0 to 9.


[User] Please transcribe this text

[Assistant] But in our array, in this input array, you can see that these numbers are not single digit.


[User] Please transcribe this text

[Assistant] These numbers are multiple digits having two digits or three digits and so on.


[User] Please transcribe this text

[Assistant] But in RadixSort, the concept is we are applying counting sort internally on individual digits and not the entire number, right? And another thing to remember is we will apply counting sort starting from the LSB.


[User] Please transcribe this text

[Assistant] That is least significant bit to the MSB. So that is from right to left.


[User] Please transcribe this text

[Assistant] So the LSB over here is the units place. So very first time we want to apply counting sort on this individual digit of these numbers and not the entire number, right? So how do you get


[User] Please transcribe this text

[Assistant] Just this digit from this number. So this is where this div variable that we've passed in this function is gonna help us


[User] Please transcribe this text

[Assistant] Get that individual digit. So in this for loop, you can see we are using this


[User] Please transcribe this text

[Assistant] Equation or you know this expression. Let's try to evaluate this expression what it is. So we are saying count of so we are accessing the count array and now we want the index position in the count array.


[User] Please transcribe this text

[Assistant] But we have a particular equation over here. We are saying ARR of i divided by div.


[User] Please transcribe this text

[Assistant] So first we have to calculate error of i. Of course we are starting from 0 to the size. What is the size of the array? 8.


[User] Please transcribe this text

[Assistant] So we are gonna go from 0 to 7 because it is i less than size.


[User] Please transcribe this text

[Assistant] So initially ARR of 0 is gonna be 170, right?


[User] Please transcribe this text

[Assistant] Divide by div first. Right? Because it is in brackets. You can see we have yellow brackets. Let me just show it to you. So this is the


[User] Please transcribe this text

[Assistant] First expression, which is there in the brackets, so we have to evaluate that first. What is error of i? As I mentioned, it is 170. What is the value of div?


[User] Please transcribe this text

[Assistant] Now for the first time when the counting sort is called, remember radix sort was calling counting sort three times in the for loop, that's what we saw previously in the pseudocode. And for the first time I have written the value of div which is 1.


[User] Please transcribe this text

[Assistant] You can see 1, 10 and 100. So for the first time it is gonna be 1. So, 170.


[User] Please transcribe this text

[Assistant] By 1 is obviously gonna be 170. Now the next part of this expression is this operator which is modulo operator. So we are saying 170 mod 10.


[User] Please transcribe this text

[Assistant] And the remainder in this case is gonna be zero because 170 is completely divisible by 10. So this entire expression is giving us zero. So ultimately we are saying count of zero plus plus. So this value in this count array will become one. So we took 170.


[User] Please transcribe this text

[Assistant] We evaluated this expression and we got this individual LSB, that is the unit's place, which is zero.


[User] Please transcribe this text

[Assistant] And we went to the 0th location in the count array and we incremented it by 1.


[User] Please transcribe this text

[Assistant] So if you remember the counting sort, this is pretty much the mechanism, right? The numbers in the input array are mapped to the indexes of the count array.


[User] Please transcribe this text

[Assistant] However, in this case, in our radix.sort situation where we have numbers having multiple digits, this number is not representing the index position.


[User] Please transcribe this text

[Assistant] This individual digit is now representing the index position in the count array.


[User] Please transcribe this text

[Assistant] Again, this 5 is gonna be mapped with the index position 5.


[User] Please transcribe this text

[Assistant] So let's evaluate this expression one more time for 45. So now i value becomes 1. i was initially 0, now i has become 1.


[User] Please transcribe this text

[Assistant] Because we're gonna go from 0 to 7, right? We're gonna completely iterate through this input array. So we are at this place.


[User] Please transcribe this text

[Assistant] So again, we are seeing count of arr of i divided by div mod 10. So again, arr of i


[User] Please transcribe this text

[Assistant] Divide by div. What is error of i now? Error of 1. Error of 1 is 45. So we take 45. We divide it by 1 because initially for the first time div value is 1. That would give us 45 only. Then we say mod 10.


[User] Please transcribe this text

[Assistant] When you do 45 mod 10, we get 5, because 45 is not completely divisible by 10. Obviously, it is divisible, we get a decimal point number, but


[User] Please transcribe this text

[Assistant] In modulo operation as I mentioned we only get the remainder and this remainder is gonna be 5. So ultimately it is saying count of 5 plus plus. So remember there is a plus plus over here.


[User] Please transcribe this text

[Assistant] So we take this number, we only take the LSB that is the units place for the first iteration of counting sort. We come to this find expression in the count array and we make it plus one. Now, similarly, we will go one element at a time in the input array. This expression will be evaluated every time.


[User] Please transcribe this text

[Assistant] The div value initially is gonna be 1 only, so it's not gonna change. So, we will take


[User] Please transcribe this text

[Assistant] These elements, so let's calculate this for, you know, the third position or third element. We take 75. We evaluate this expression. We get the LSB. It is mapped to this.


[User] Please transcribe this text

[Assistant] Index position in the count array, we increment it, we make it 2. Then we move forward. We take 90. We evaluate this expression, we get 0. 0 is mapped with the 0 index position in the count array. So we increment it by 1 again, so it becomes 2.


[User] Please transcribe this text

[Assistant] Similarly, I'm just gonna do it for all the other elements.


[User] Please transcribe this text

[Assistant] In the input array, I hope you've understood how this expression is working to get the particular index position. You guys can pause the video and dry run it yourself step by step for every element if you want because that will give you a little bit more practice.


[User] Please transcribe this text

[Assistant] But at the end of this for loop, after we iterate from 0 to 7,


[User] Please transcribe this text

[Assistant] In the count array, this is something that we have and this is the result of this for loop. So you will have.


[User] Please transcribe this text

[Assistant] Count of 0 as 2, which means the elements in the input array having zeros as the LSB are 2. That is 170 and 90.


[User] Please transcribe this text

[Assistant] Then we have two elements that have the LSB of 2. So you can see 802 and single digit number 2.


[User] Please transcribe this text

[Assistant] So that's the count we are storing over here. So we have applied counting sort on single digits that is the LSB of these numbers. Okay. Now next step in the counting sort algorithm is obviously to


[User] Please transcribe this text

[Assistant] Take a cumulative sum of the count. This is also similar to what we've seen in the counting sort. So we're saying count of i is equal to count of i plus count of i minus 1. And we start from i equals to 1 to the range. So we'll start from 1 to 9. Because range is from 0 to 9, right? So what we're doing, we're taking this number.


[User] Please transcribe this text

[Assistant] 0, where that is count of i plus 1, so you can see count of i.


[User] Please transcribe this text

[Assistant] So we take this value. We are starting from 1, right? So initially, count of i is gonna be count of 1.


[User] Please transcribe this text

[Assistant] So, to evaluate this, it would be count of 1 is equal to count of 1 plus count of i minus 1 is count of 0. So, count of 1 is 0, you can see over here and count of


[User] Please transcribe this text

[Assistant] That is zeroth element is gonna be as it is, but then we do 2 plus 0. We store it over here and then we do.


[User] Please transcribe this text

[Assistant] This element plus the previous element which is now modified to 2. So 2 plus 2, we get 4. Then we do this element that is 3 index position plus 2 index position that is 4.


[User] Please transcribe this text

[Assistant] Plus zero, we store it over here itself and this is happening in the same array. Okay, so these are same arrays only.


[User] Please transcribe this text

[Assistant] I've just written it two times so that I can show you how the sum is happening.


[User] Please transcribe this text

[Assistant] Then we take a sum of 4 index position and 3 index position and store it at 4 index position. So 4 plus 1 is 5. Then we do this. That is 5 plus 2 is 7. Then we do this. 7 plus 1 is 8.


[User] Please transcribe this text

[Assistant] Then we do this. 0 plus 8 is 8. And pretty much everything is gonna be 8. Okay?


[User] Please transcribe this text

[Assistant] So after this for loop that is 5 and 5.1.


[User] Please transcribe this text

[Assistant] We've got our cumulative count, so this is cumulative count.


[User] Please transcribe this text

[Assistant] And this is done to get the exact positions of the elements in the input array for the output array. So now the mapping has to be done from the input array.


[User] Please transcribe this text

[Assistant] Okay, so now coming to one of the most crucial for loops or steps in the counting sort.


[User] Please transcribe this text

[Assistant] Wherein the mapping is done with the output array, that is this array.


[User] Please transcribe this text

[Assistant] And the input array. So now we have to pick one element from the input array.


[User] Please transcribe this text

[Assistant] And place it in some location in the output array and that some location will come from


[User] Please transcribe this text

[Assistant] This cumulative count array that we've just calculated, okay?


[User] Please transcribe this text

[Assistant] And on the right hand side we have the input array. So let's evaluate this expression starting from i equals to size minus one to i greater than equal to zero. So here we are going in reverse order.


[User] Please transcribe this text

[Assistant] So we are going from i equal to size minus 1. What is the size of the array? 8. 8 minus 1 is 7. So we are gonna run from 7 to


[User] Please transcribe this text

[Assistant] I equals to greater than or equal to zero. So seven to zero. So starting from seven.


[User] Please transcribe this text

[Assistant] Now the reason why we go from right to left is because we want to place these individual elements in proper order.


[User] Please transcribe this text

[Assistant] In their LSB, in their units place for the first time the counting sort is called.


[User] Please transcribe this text

[Assistant] So 170 in the output array also has to come before 90. And to achieve this,


[User] Please transcribe this text

[Assistant] We have to go in reverse order. So what you can do is you can.


[User] Please transcribe this text

[Assistant] Change this order and start from 0 to 7 also to check if this condition is satisfied. If you go from 0 to 7, what will happen is 170 will be coming after 90 and that is not correct. So that's why we have to go in reverse order.


[User] Please transcribe this text

[Assistant] And if what I'm saying is not making sense, let's actually try to go.


[User] Please transcribe this text

[Assistant] And dry run this step by step and then you'll understand it will make more sense. Okay.


[User] Please transcribe this text

[Assistant] So starting off with the 7th element, we are taking arr of i, which is arr of 7. We are going in reverse order. So arr of i is 66. So for the RHS, we have 66. So 66 is going to be stored at


[User] Please transcribe this text

[Assistant] This expression that is count of arr of i by div mod 10 minus 1. So let's evaluate this.


[User] Please transcribe this text

[Assistant] So internally we have to first calculate error of i by div. What is error of i? Error of 7 because we started from 7 so it is 66.


[User] Please transcribe this text

[Assistant] So 66 divided by div. Div is 1. Obviously for the first time. So this is still first round of counting sort being called, right? From the radix sort. So div values are only gonna change from 1, 10 and 100. And right now we are at 1. So 66 by 1 is gonna be 66 obviously. Then we have mod 10. 66 mod 10 is gonna be 6. So, we are saying count of 6 minus 1.


[User] Please transcribe this text

[Assistant] Is gonna give us the index position of the output array. So count of six is what? In the cumulative count that we have counted, we come at the sixth index position, count of six. The count stored over here is eight. We are saying eight minus one. So now this count becomes seven. So this becomes seven.


[User] Please transcribe this text

[Assistant] And this is what we are interested in. So we are going to go in the output array at the seventh index position.


[User] Please transcribe this text

[Assistant] And store this RHS that is ARRFI that is 66. Okay?


[User] Please transcribe this text

[Assistant] So coming in the output array at the seventh index position, which is actually the last index position, we're going to take this 66 from the input array and transfer it over here. Okay.


[User] Please transcribe this text

[Assistant] So this is the first step that is 6.1 inside the for loop. Now again,


[User] Please transcribe this text

[Assistant] So now we will take this number. So let's evaluate this one more time for better understanding. So i is now 6. Arr of 6 is 2. So RHS is pretty easy.


[User] Please transcribe this text

[Assistant] Let's evaluate LHS. Error of I. Again, 2 divided by div. Div is 1. For the first time, this is div. Mod 10.


[User] Please transcribe this text

[Assistant] Now 2 mod 10 is obviously gonna give us 2 only, right? So this will give us 2. So we get 2. So we are getting count of 2.


[User] Please transcribe this text

[Assistant] But we also have this minus 1, we have to say minus 1. So what is count of 2?


[User] Please transcribe this text

[Assistant] Count of 2 in the cumulative count over here that we just calculated is 4. So we have to say 4 minus 1, which is 3. So this change will happen over here also. This will become 3.


[User] Please transcribe this text

[Assistant] And now this 3 is basically the output position that is the index position in the output array where we have to store this 2. So in the output array, we will go at position 3. We will store this number 2.


[User] Please transcribe this text

[Assistant] Okay, so let's quickly do it for other values also. So now I will become.


[User] Please transcribe this text

[Assistant] Five, right, so let me just write the i value over here also.


[User] Please transcribe this text

[Assistant] We just did this, we are going from 7 to 0, so now we are at 5, i is become 5. What is the value at 5?


[User] Please transcribe this text

[Assistant] 24 in the input array. So on the right hand side we have 24 as it is. On the left hand side we have 24 divided by 1 mod 10. So that will give us the count position.


[User] Please transcribe this text

[Assistant] So that would be 24 divided by 1 is 24, 24 mod 10 is 4. So count of 4 minus 1.


[User] Please transcribe this text

[Assistant] That would be, what is count of 4? Count of 4 is 5. So 5 minus 1 will become 4. Right? So 5 minus 1 will become 4. And this is the position of the output array where we have to store this 24. So output of 4 will have 24. Now i becomes 4.


[User] Please transcribe this text

[Assistant] So what is arr of 4, 802. So let's write that over here, 802.


[User] Please transcribe this text

[Assistant] So the left hand side equation becomes error of 5, it is 802 divided by 1 mod 10. Obviously this is also gonna give us 2 because 802 divided by 1 is 802 and 802 mod 10 will give us 2. So that is count of 2.


[User] Please transcribe this text

[Assistant] And then we also have this minus 1 over here. So we have minus 1. What is count of 2? Count of 2 over here has become 3. So that will become 2 because count of 2 is 3. 3 minus 1 will become 2. And that is the position in the output array where we have to store this 802. So at output location of 2 is where we store 802. Okay. So now i value becomes 3. Let's calculate it for 3.


[User] Please transcribe this text

[Assistant] What is the value of ARR of i, that is ARR of 3, it is 90. So I'm gonna write 90 over here.


[User] Please transcribe this text

[Assistant] For the right hand side, for the left hand side, we have 90 divided by 1 mod 10. This whole thing obviously is going to give us 0. So count of 0, which is 2. So 2, then we have minus 1. So it becomes 1. So I'll write 1 over here and that is the position in the output array where we have to store 90. So I'll store 90 over here.


[User] Please transcribe this text

[Assistant] ARR of 2 is ARR of this position that is 75. So we get count of 5 minus 1. I'm directly evaluating it now. So by now you must get the calculations. What is count of 5? Count of 5 is 7.


[User] Please transcribe this text

[Assistant] So seven minus one is six. So that new value becomes six at count of five. So in the output array.


[User] Please transcribe this text

[Assistant] At sixth location or sixth index position is where we store 75. So this is 75 coming over here. Then i becomes 1. Again, count of.


[User] Please transcribe this text

[Assistant] So count of 5 because when we take 45 so we have 45 divided by 1 which is div value mod 10 which gives us 5 so count of 5 minus 1 so this time count of 5 is 6 so it would be 6 minus 1 6 minus 1 is 5 so output position of 5 is where we store 45


[User] Please transcribe this text

[Assistant] And in the count array also it becomes 5. Right? So output of 5 is where we store 45.


[User] Please transcribe this text

[Assistant] That is 0th index. So after this entire 6 and 6.14 loop, we have applied counting sort on this array, but we have applied counting sort only on the least significant digit.


[User] Please transcribe this text

[Assistant] In the input array, 170 was coming first before 90. Both of them have zeros in their LSB, in their units place. So in the output array, 170 is obviously coming before 90. So this is why we had to go from right to left, that is from


[User] Please transcribe this text

[Assistant] Another example would be 802 and 2. So if 802 is coming before 2,


[User] Please transcribe this text

[Assistant] In the input array, it has to come before 2 in the output array also. And if you're wondering why this is still not sorted, it is because we still not reached the end. This is just the one iteration of counting sort, which is called 3 times.


[User] Please transcribe this text

[Assistant] In the radix sort pseudocode previously, we saw that counting sort is gonna be called three times with


[User] Please transcribe this text

[Assistant] The only change happening in the div value which is gonna go from 1 to 10 to 100. So I just showed you one entire iteration of counting sort where div was 1. Now we have to apply counting sort on this


[User] Please transcribe this text

[Assistant] So, if you see step 7, we still have to cover step 7, we are saying for i equal to 0 to size.


[User] Please transcribe this text

[Assistant] Output of i is now transferred into the original input array. So all these values 170, 90,


[User] Please transcribe this text

[Assistant] 024, 045, 075, 066. I've added these extra zeros because now we're gonna need them because now,


[User] Please transcribe this text

[Assistant] For the second time, when the counting sort is called, the div value is now become 10 and now


[User] Please transcribe this text

[Assistant] The least significant bit that we want to apply counting sort is gonna be the tens place because we've already applied counting sort based on the units place. So now we want to apply it to the tens place. Okay, so these are the digits on which we are going to apply counting sort for the second time. So how would the counting sort now be applied?


[User] Please transcribe this text

[Assistant] Just on this digit because I've already shown you how it applies on the units place. So let's quickly go step by step again for the second time and this time we'll go a little fast.


[User] Please transcribe this text

[Assistant] The only difference is gonna happen is in this expression, so let me just first erase this extra markings.


[User] Please transcribe this text

[Assistant] Okay, so for the second time, now the counting sort is called with the only difference being the div value is now equals to 10. Okay, so let me write it again over here, div equals to 10. Again, create the output array, we've created it. Take the range, range is obviously going to be 10. Again, for loop, the first for loop makes all the count element zero. Initially, it's going to be all zeros. The next for loop increments the count, but this time,


[User] Please transcribe this text

[Assistant] Since div is 10, let's see how the mapping is done. Now as I mentioned we want to take the


[User] Please transcribe this text

[Assistant] So let's evaluate for the zero position. So let's say i equals to zero. So because i is from zero to size, so i will go from zero to seven because size is eight. Size of the input array is eight. Now we are going from one element to another in the input array.


[User] Please transcribe this text

[Assistant] So we are taking the input array error of i. Initially i is 0. What is?


[User] Please transcribe this text

[Assistant] A error of 0 now, it is 170. So we take 170. Then it is divided by div. But this time, as I mentioned, div is 10. So 170 divided by 10. It is in brackets. So that would give us 17.


[User] Please transcribe this text

[Assistant] Outside this brackets, outside this, we have again a modulo operation. So 17 mod 10 will give us 7. So now you can see


[User] Please transcribe this text

[Assistant] We take this 170 and we perform this expression on it and we get this digit which is at the tens position which is 7. So at that position 7 we are saying count of 7 plus plus.


[User] Please transcribe this text

[Assistant] So count in the count array at the seventh index position, we say plus plus, we increment it by one. So this is how you are now getting the individual digits at the


[User] Please transcribe this text

[Assistant] So I'm not gonna repeat this over and over again. I hope you've got it. You can dry run it on every element from the input array.


[User] Please transcribe this text

[Assistant] And you'll get the, you know, digit from the tens place and then the respective count will get plus plus. I'm just going to quickly update it over here because it will become repetitive otherwise.


[User] Please transcribe this text

[Assistant] Okay, so after this step number 4 and 4.1 happens, that is after we take the count of these individual digits, so you can see 7 has happened 2 times over here and over here.


[User] Please transcribe this text

[Assistant] Hence at the index position in the count array, the count is 2. Then we have 9, so count is 1. For 0 we have 1 and 2.


[User] Please transcribe this text

[Assistant] So, at index position 0, we have the count of 2.


[User] Please transcribe this text

[Assistant] Similarly, we have all other counts at their appropriate index positions. So now this digit is mapped to its appropriate index position. Okay.


[User] Please transcribe this text

[Assistant] Then of course at step 5 and 5.1, we take the cumulative addition, so 0 plus 2.


[User] Please transcribe this text

[Assistant] So first element is gonna be as it is, then we have 0 plus 2, which is 2. Then we have 1 plus 2, which is 3. Then we have 0 plus 3, which is 3 again. Then we have 1 plus 3, which is 4. Again, 0 plus 4 is gonna be 4. 1 plus 4 is gonna be 5.


[User] Please transcribe this text

[Assistant] 5 plus 2 is gonna be 7, 0 plus 7 is gonna be 7, and 1 plus 7 is gonna be 8.


[User] Please transcribe this text

[Assistant] That's how this for loop will work. You can dry run it. We've already done it, so I'm not going ahead.


[User] Please transcribe this text

[Assistant] And now again the more important for loop where we are gonna take elements from the input array starting from i equal to size minus one which is seven because eight minus one is seven starting from seven to zero. So we will go from seven to zero again and now we have to pick one element.


[User] Please transcribe this text

[Assistant] From here and put it in the output array in such a way that it has to be mapped in a particular position.


[User] Please transcribe this text

[Assistant] So let's calculate that quickly. Taking the first element at 7th position, let's say i equals to 7.


[User] Please transcribe this text

[Assistant] In the output array at a particular position which is coming from this expression.


[User] Please transcribe this text

[Assistant] So count of error of i. What is error of i?


[User] Please transcribe this text

[Assistant] That is error of 7. Error of 7 is 066. So we say 066 divided by div. Div as I mentioned for this iteration is 10.


[User] Please transcribe this text

[Assistant] Is gonna give us 6.6. Now as I mentioned, this is an integer value. So the point part, the decimal part is gonna be truncated.


[User] Please transcribe this text

[Assistant] That is the fractional part is gonna be truncated. So we are gonna left out with 6. Okay?


[User] Please transcribe this text

[Assistant] So 066 divided by 10 is gonna give you 6. So that's happening inside these brackets. After that we have a mod 10.


[User] Please transcribe this text

[Assistant] So 6 mod 10 is obviously gonna give you 6 only because it is not directly divisible.


[User] Please transcribe this text

[Assistant] So ultimately we are getting count of 6.


[User] Please transcribe this text

[Assistant] And then we have a minus 1, so that's minus 1. So what is count of 6? We just calculated it as 5. So we are saying 5 minus 1. That would give us 4.


[User] Please transcribe this text

[Assistant] And this is where the entire expression evaluates. So at the position output of 4.


[User] Please transcribe this text

[Assistant] Is where we want to store error of 5 that is error of 7 that is 066.


[User] Please transcribe this text

[Assistant] So this count also first becomes less, that is count of 6 is 5 only, so it becomes 4. Let me just use another color. It becomes 4.


[User] Please transcribe this text

[Assistant] And output of 4, that is output of this position is where we have to store this 066. So I'll enter 066 over here. Okay.


[User] Please transcribe this text

[Assistant] Now if you move back, starting from, you know, we are going in the backward direction from 7 to 0. So for this element, we are gonna get the 7th index position in the cumulative count array. So,


[User] Please transcribe this text

[Assistant] When i becomes 6, let me just again write it over here. So when i becomes 6, the expression goes as follows. What is Arr of 6? Arr of 6 is 075, that is 75 basically.


[User] Please transcribe this text

[Assistant] So count of 7 is targeted as I mentioned. What is the count over here? It is 7. So we have to do minus 1. So it becomes 6. So 7 minus 1 becomes 6. And at this position of the output array because that's the outermost array. So output of 6 is where we have to put 75. So output of 6 is where we have to put 75. So similarly for 0, 4, 5,


[User] Please transcribe this text

[Assistant] We will target the index position 4 in the count array. We will decrement this by 1. So it will become 3. And at the third index position is where we have to store 045. Then we will go at this. We take 024. We will target the second index position in the count array. We will decrement it by 1. We will make it 2. And in the output


[User] Please transcribe this text

[Assistant] At the one index position in the output array is where we will put 002. We will go to 802, we will take


[User] Please transcribe this text

[Assistant] 0. We will come to 0 index position which has 1. We will decrement it by 1 so it becomes 0.


[User] Please transcribe this text

[Assistant] And at the 0th index position in the output array is where we will store 802. We will come to one index position in the input array. We will take this 9. We will go to the


[User] Please transcribe this text

[Assistant] 9th index position we will decrement it by 1, it becomes 7. And at the 7th index position is where we will input this 90. And the last element goes over here.


[User] Please transcribe this text

[Assistant] Because we will access the 7th index position in the count array. The 7th index position is 6. We will decrement it by 1. It will become 5. And at the 5th index position is where we put 170. So this is 170. It will come over here.


[User] Please transcribe this text

[Assistant] Okay, so this is the second iteration of the counting sort.


[User] Please transcribe this text

[Assistant] And after this 6 and 6.1 in the output array, we have a result where we applied counting sort on this input array, but only on the second digit that is a tens place digit.


[User] Please transcribe this text

[Assistant] And then after step number 7 and 7.1, all the elements in the output array that is this 802002024 will be transferred back to the original array. So that's the basic for loop.


[User] Please transcribe this text

[Assistant] And again, if you still observe this output is still not


[User] Please transcribe this text

[Assistant] 100's position. So let's first transfer all these values 802, 002, 024 back to the original array. And there you go. This is now our new array that is the same input array on which we will apply one more time the counting sort. But this time the div value is going to be 100. Okay, so I'm quickly going to go through these steps also so that we don't leave out anything. Again, let's create the output array.


[User] Please transcribe this text

[Assistant] We've created the output array. Take the range. Range is obviously going to be 10. Create the count array with this range and initiate or initialize all the values to zero. Okay.


[User] Please transcribe this text

[Assistant] So we've done step 1, 2, 3. Step 4 is incrementing the count by calculating this expression by targeting the hundredth position now. So now the hundredth position is targeted. That is this position.


[User] Please transcribe this text

[Assistant] So yeaah, you're gonna use this same expression and just this time the div value is gonna be


[User] Please transcribe this text

[Assistant] So I'm gonna evaluate it one time and then we'll update all the count values because this is getting very repetitive. So starting from 0 to the size, the size is 8.


[User] Please transcribe this text

[Assistant] So we'll go from 0 to 7 because i less than size. So ARR of 0 over here is 802. So 802 divided by.


[User] Please transcribe this text

[Assistant] What is div this time? 100. So we will get 8 obviously. So this bracket will give us 8, then we have 8 mod 10.


[User] Please transcribe this text

[Assistant] Which will again give us 8, because it's not divisible, we get the remainder.


[User] Please transcribe this text

[Assistant] So in the count array at the 8th position, so in the count array.


[User] Please transcribe this text

[Assistant] At the 8th position is where we want to do the plus plus. Where we want to do increment. So, you can see.


[User] Please transcribe this text

[Assistant] This individual digit is mapped with this 8 index position in the count array where we have to do the plus plus. So it will become 1. Similarly, 0 will be mapped over here, over here, over here, over here and over here.


[User] Please transcribe this text

[Assistant] So we have 1, 2, 3, 4 and 5 occurrences, so the count will become 5.


[User] Please transcribe this text

[Assistant] For this element that is at this place we have 1. So this 1 will be mapped at 1 index position. So that count will become 1. And for the last element,


[User] Please transcribe this text

[Assistant] Again, we have another zero. Okay, so we have six instances. One, two, three.


[User] Please transcribe this text

[Assistant] 4, 5 and 6 instances of 0, so that count will become 6.


[User] Please transcribe this text

[Assistant] We have one instance of digit 1 in the hundredths place and we have one instance of digit 8 in the hundredths place. So 611.


[User] Please transcribe this text

[Assistant] So step number 4 and 4.1 done. Step number 5 and 5.1 is the cumulative addition. So 6 remains as it is. Then we do 6 plus 1 is 7. Then we have 0 plus 7 is 7. Again 0 plus 7 is 7.


[User] Please transcribe this text

[Assistant] Here we have 1 plus 7 is 8, 0 plus 8 is 8. So you got our cumulative count in the same count array basically. So step number 5 and 5.1 done. And step number 6 is where we have to take


[User] Please transcribe this text

[Assistant] One element from the input array in the reverse order starting from 7 to 0.


[User] Please transcribe this text

[Assistant] So let's quickly evaluate this expression. We have to take arr of i, which is arr of 7 for the first time, which is 090. So 090.


[User] Please transcribe this text

[Assistant] Has to be allocated in the output array at some place based on this expression. So 090 divided by div is 100. So obviously 090 that is 90 divided by 100 will give you 0. That is 90 divided by 100 will give you 0.9. And since it is an integer in programmatic way 0.9 will be truncated so you are left with 0. So this whole thing mod 10 will also give you 0, right?


[User] Please transcribe this text

[Assistant] 6 minus 1 will give you 5. So 5 will be stored over here and at the 5th index position is where you have to store 090. Okay?


[User] Please transcribe this text

[Assistant] So count of 0 would be 6 minus 1, that would give you 5. So output of 5 is where you have to store this 090.


[User] Please transcribe this text

[Assistant] Then we will move on to the next value in the input array. We will take this 0. We will go to the 0 index position in the count array. We will decrement it by 1. So it becomes 4. At the 4th index position is where we will store 075. So 075 will come over here. Then we will move on to


[User] Please transcribe this text

[Assistant] So this becomes 6. And at the 6th index position is where we will store 170. Then we will go to the next value that is 4. That is index position 4 in the input array. We will take the first digit.


[User] Please transcribe this text

[Assistant] And this first digit is basically evaluated by this expression only. That's what we did in the first example. I'm just quickly going through because now you should get a hang of it. Or you can pause this video and calculate this expression for every element in the input array. But basically we're gonna get this zero. Come to the zero index position in the count array. Decrement it by one, that becomes three.


[User] Please transcribe this text

[Assistant] And the third index position is where we store 066. Then we move over here, we get the zero index position of 045. We come at the zeroth index position in the count array, decremented by 1, it becomes 2.


[User] Please transcribe this text

[Assistant] So at this two index position is where we store 0, 4, 5. Moving one place back, we have 0, 2, 4 again coming at zero index position in the count array, decrementing 2 to 1. At one index position is where we store 0, 2, 4.


[User] Please transcribe this text

[Assistant] Moving forward in the input array or moving backward in the input array, we get 002. Again, we are getting.


[User] Please transcribe this text

[Assistant] The zero index position decrementing it by one, it becomes zero. At zero index position is where we store 002.


[User] Please transcribe this text

[Assistant] And then coming at the last element or the first element basically in the input array, we take 802, we take the first digit, we come at the 8th index position in the count array, the value here is 8, we decrement it by 1, so it becomes 7, and at the 7th index position is where we store 802.


[User] Please transcribe this text

[Assistant] So after 6 and 6.1, this is the output that we get. And now if you observe this output is properly sorted in correct ascending order.


[User] Please transcribe this text

[Assistant] So lastly, after 6 and 6.5, in the 7 and 7.1, we take this output and transfer it to the original array. Okay.


[User] Please transcribe this text

[Assistant] And this is where the last counting sort is called in the radix sort. And that's where the radix sort will also stop executing because we've pretty much got our sorted array and it only called counting sort three times because the maximum number that is 802 had three digits.


[User] Please transcribe this text

[Assistant] So this is how the entire Radix sort sorting algorithm works with the point of view of the pseudo code.


[User] Please transcribe this text

[Assistant] On individual digits for numbers which have more than one digit.


[User] Please transcribe this text

[Assistant] Okay, so I hope you got the entire working of radix sort and how it uses counting sort individually and internally with the help of diagram. We've pretty much dry run the entire code and we've taken a diagrammatic representation to better understand how every step impacts the


[User] Please transcribe this text

[Assistant] Internal steps are internal values, which ultimately leads us to this sorted array.


[User] Please transcribe this text

[Assistant] So yea, that's it for this video, guys. If you like this video, if you've now understood correctly how internally things are working, please give this video a like. This took a lot of efforts. Definitely let me know in the comments how this video was. Do share it with your friends.


[User] Please transcribe this text

[Assistant] And in the next video, we're gonna pretty much implement this. So we're gonna write a C++ program to implement this pseudo code and convert it into a C++ program. So thanks for watching. Stay tuned for the next video. See you in the next one. Peace.


[User] Please transcribe this text

[Assistant] Beautiful women, in a land blessed to this day with beautiful women, inspired the miniature painter's brushes.


[User] Please transcribe this text

[Assistant] The first capital was here, in Passarganj.


[User] Please transcribe this text

[Assistant] In celebration of 2,500 years of nationhood, the Persian people, led by their Shah,


[User] Please transcribe this text

[Assistant] His Imperial Majesty, Mohammed Reza Pahlavi al-Yamir, Shah and Shah, make homage at the tomb of Cyrus the Great, the first Shah of all.


[User] Please transcribe this text

[Assistant] Long before Magna Carta of human rights and liberties. Cyrus, the Lord's anointed of the prophet Isaiah in the Old Testament. Cyrus, the founder of Persian culture and the father of Iran, the land, five times the size of Great Britain, which this Shah rules today.


[User] Please transcribe this text

[Assistant] In solemnly dedicating himself to the memory of his predecessor, the Shah was keeping a promise he had made ten years earlier.


[User] Please transcribe this text

[Assistant] As he left the tomb to join his empress and his ten-year-old son, the crown prince, he was filled with a sense of occasion. It had fallen to him, after a twilight in his nation's long history, to remind the world and his own people of Persian pride.


[User] Please transcribe this text

[Assistant] At this glorious moment in the history of Iran, I and all Iranians, the offspring of the empire which thou founded 2,500 years ago, bow our heads in reverence before thy tomb.


[User] Please transcribe this text

[Assistant] 62 heads of state, or their direct representatives, converged.


[User] Please transcribe this text

[Assistant] On the airport of the fairy tale city of Shiraz, set in the desert, beside the Persian Gulf.


[User] Please transcribe this text

[Assistant] In a patchwork of color, in a whirl of salutes, bows and curtsies, familiar faces in the world scene, stepped out of their aircraft over red carpets, fringed with guards of honor into the welcoming Persian sunlight. It was just like this. Too much was happening to pick out the details.


[User] Please transcribe this text

[Assistant] For all the arrivals, ceremony and protocol had to be carefully observed. None who were there saw it all.


[User] Please transcribe this text

[Assistant] So began one of the most historic cultural gatherings the world has ever seen.


[User] Please transcribe this text

[Assistant] The flags of the guest nations flew in salute as the VIPs flew in. This was no party of the year. It was the celebration of 25 centuries.


[User] Please transcribe this text

[Assistant] Throughout the day, escorted cars drove out through Shiraz into the desert towards the ruined palace of the great kings of antiquity, the historic birthplace of the Persian Empire. The guests were traveling to a reception without precedent, even in the days of Cyrus the Great.


[User] Please transcribe this text

[Assistant] Branching out from the Royal Pavilion to represent the five continents.


[User] Please transcribe this text

[Assistant] Each head of state had an apartment with a sitting room, two bedrooms and two bathrooms and a service room with an electric stove and ironing board for their entourage.


[User] Please transcribe this text

[Assistant] The complex of new building was a major piece of construction even for modern times.


[User] Please transcribe this text

[Assistant] As the famous men and women matched their pictures with their presents, they were given an excited greeting. Persia was in gala mood.


[User] Please transcribe this text

[Assistant] The best beginning for the future was to sound the trumpets and recall the Persian people to the glories of their own past. What happened was assuredly unforgettable.


[User] Please transcribe this text

[Assistant] Throughout the day and into the night, the Shah was in constant attendance on the newly arriving guests. His hand, for a hundred times, was stretched in welcome.


[User] Please transcribe this text

[Assistant] Looking at these scenes, a poker player might well reflect that here is that rare hand in cards, which is called a royal flush.


[User] Please transcribe this text

[Assistant] The papers they read on Persian culture were to be published and circulated to research institutes throughout the world. Such a brain's trust of Persian study had never been collected before.


[User] Please transcribe this text

[Assistant] In the state reception room of the Royal Pavilion in Persepolis move people who influence the destiny of mankind.


[User] Please transcribe this text

[Assistant] Your Majesties, Honorable Presidents of Republics, Highnesses, Eminences, Excellencies, Ladies and Gentlemen,


[User] Please transcribe this text

[Assistant] Such a bond of past and present, achieved by understanding and friendship, is surely an omen of good.


[User] Please transcribe this text

[Assistant] On the following evening, the guests moved out into the star-spangled Persian night toward Persepolis, the ruined palace of Cyrus' successor, Darius and his son Xes. Alexander the Great, the conqueror who reduced it to a shell,


[User] Please transcribe this text

[Assistant] Is said to have needed 10,000 mules and 6,000 camels.


[User] Please transcribe this text

[Assistant] To remove the treasures which were housed in the precincts.


[User] Please transcribe this text

[Assistant] In the mountainside overlooking the palace where he ruled 500 years before Christ, the voice of Darius the Great speaks again.


[User] Please transcribe this text

[Assistant] The postal system with relays of horsemen bringing news from the distant outposts of empire. Today, in the company of his guests, in the long shadow of the ruins of Persepolis, messengers of good omen bring the Shah the greetings of his Senate in Tehran.


[User] Please transcribe this text

[Assistant] Every historic detail in this parade, so far as we can know today, is exact.


[User] Please transcribe this text

[Assistant] This wooden fortress, pulled by a span of oxen, was one of the first siege weapons.


[User] Please transcribe this text

[Assistant] Persia has prevailed. Conquerors from the time of Alexander have adopted Persian ways. The spirit of the country has risen again and again. The trumpets have never ceased sounding.


[User] Please transcribe this text

[Assistant] Here is the new army which the Shah has created to develop literacy, health, and international development. A peace army. To fight poverty, hunger, and social injustice.


[User] Please transcribe this text

[Assistant] The fountains, which inspired the poets, philosophers and thinkers of this old land centuries ago, whisper their watery music.


[User] Please transcribe this text

[Assistant] The way it works is that he doesn't sit down himself. Moving among his guests, he makes them all happy. The music and the food are traditional.


[User] Please transcribe this text

[Assistant] They were carrying them from the pavilions at Persepolis to the airport at Shiraz, then by air to Tehran, the modern capital of Persia.


[User] Please transcribe this text

[Assistant] For most of them it was a surprise to discover how the new Persia was evolving. They only remembered the old, when Persia had slept.


[User] Please transcribe this text

[Assistant] Her other enemy is her scarcity of water. By building great dams, Persia's water too is being brought under control. She is moving fast into heavy industry.


[User] Please transcribe this text

[Assistant] During the celebrations of the 2500th anniversary, his son remembered him.


[User] Please transcribe this text

[Assistant] The cavalcade of cars swept towards the mausoleum of Reza Shah the Great.


[User] Please transcribe this text

[Assistant] His son wished to do honor to the memory of his father. The ceremony was solemn and short.


[User] Please transcribe this text

[Assistant] After that, the climax of the celebrations. The first glimpse of the floodlit monument outside the airport of Tehran in honor of the present Shah. Below the monument is a museum of Persian art and a cinema. To open it? Well, what would you expect?


[User] Please transcribe this text

[Assistant] Notice that the soldiers are doing their arms drill without orders to the music of the Viennese Waltz.


[User] Please transcribe this text

[Assistant] Towards the end of the celebrations, the Shah heard an address from the religious representatives of the world. A confirmation that religious tolerance should be extended to all men. Not all countries accept it. In ancient tradition, Persia does.


[User] Please transcribe this text

[Assistant] They remember the words of their great poet and thinker Sadi, who 700 years ago wrote, If ambitious of a great name, make a practice of munificence, for the crop will not shoot till thou shalt sow the seed.


[User] Please transcribe this text

[Assistant] In Tehran, the new monument is likely to become as familiar as London's Big Ben, the Eiffel Tower of Paris, the New York Statue of Liberty.


[User] Please transcribe this text

[Assistant] Symbol of Persia's great celebrations, this baked clay cylinder of Cyrus proclaims that it was here that the rights of man were first made law.


[User] Please transcribe this text

[Assistant] Oh! They have acai bows.


[User] Please transcribe this text

[Assistant] That is really mean. That is really mean. I'm gonna finish my bowl first.


[User] Please transcribe this text

[Assistant] That is so mean, giving me a mission like that. We could have just hired hotter people to do this show. Okay, well, it seems like a lot of-


[User] Please transcribe this text

[Assistant] Bike traffic, it's going around here. Do you think this is a good place to ask? I can maybe try and stop somebody here.


[User] Please transcribe this text

[Assistant] Okay, I'm gonna go check over there. Thank you. Have a good time.


[User] Please transcribe this text

[Assistant] I have to get the exa- oh, oh my god. I have to get the exact same one.


[User] Please transcribe this text

[Assistant] Yo, what's going on guys? Tanmay here for Simple Snippets and welcome back to another video tutorial on data structures and algorithms. And today's topic is infix to postfix conversion using stack data structure and more specifically the pseudo code of infix to postfix using stack data structure.


[User] Please transcribe this text

[Assistant] So this tutorial is all about understanding the pseudo code because ultimately we are going to use this pseudo code.


[User] Please transcribe this text

[Assistant] On example which you can see on the right hand side and understand line by line every statement of the pseudocode.


[User] Please transcribe this text

[Assistant] Now if you've missed the previous tutorial wherein we discussed the different rules which are involved when you have to do the infix to postfix using stack data structure, please make sure you watch the previous tutorial. If you've missed it, you can see all the rules on the left hand side.


[User] Please transcribe this text

[Assistant] We even used these rules and solved two examples in the previous tutorial. So this video is taking that video and


[User] Please transcribe this text

[Assistant] Moving ahead with that, so this is like part two of the part one that is previous tutorial and with that being said, let's get started.


[User] Please transcribe this text

[Assistant] If you're new to my channel, my name is Tanmay Sakpal and I do a lot of computer science and information technology video tutorials like computer programming, development, technology talks and a lot more on this channel. So if that's something you're interested into, then definitely subscribe and turn on the notifications to get the latest updates and never miss out on such important topics.


[User] Please transcribe this text

[Assistant] Now starting off, why do we require this pseudo code of infix to postfix conversion using stack? That is because as I mentioned,


[User] Please transcribe this text

[Assistant] In order to actually implement this application, in order to actually write a program in any general purpose programming language, you require a pseudo code. A pseudo code is sort of like a part English part code representation of the entire algorithm.


[User] Please transcribe this text

[Assistant] So previously we saw all the different rules, which was in plain English, which you can right now see on the left hand side. But of course, when you are going to write some program, you need some step by step pseudo code kind of syntax, which you can easily convert to a code, right? And that's where pseudo code comes into picture. So we're going to use all these rules and create a pseudo code.


[User] Please transcribe this text

[Assistant] Which you can take and implement in any programming language.


[User] Please transcribe this text

[Assistant] We are gonna use C++ and that would be the next tutorial after this one.


[User] Please transcribe this text

[Assistant] But the more important part and the focus of this tutorial as I mentioned is the pseudocode. Now before we actually see the pseudocode,


[User] Please transcribe this text

[Assistant] We have been given this example. It is a fairly complex example of infix, which we have to convert to postfix using stack data structure and using the pseudocode.


[User] Please transcribe this text

[Assistant] But before that, let's actually manually do the conversion. We've also seen the manual conversion in previous tutorials in this entire DSA course. So quickly I'm just gonna write this expression, this infix expression over here. And what we'll do is we'll quickly try to manually convert it into postfix. So we have A plus B minus C which is in brackets.


[User] Please transcribe this text

[Assistant] And then we have star d raised to e raised to f. So this is multiple raised to scenarios. We'll talk about it in a minute. It is a unique situation. And then we have divide by g.


[User] Please transcribe this text

[Assistant] So it's a fairly complex expression and the reason I've chosen this is because it will cover pretty much all the rules and all the conditions in the pseudocode as well.


[User] Please transcribe this text

[Assistant] This small sub-expression will get resolved or will get converted to its postfix format first. So, inside this we have two operators plus and minus, right.


[User] Please transcribe this text

[Assistant] And plus and minus have same operator precedence, we've already studied this.


[User] Please transcribe this text

[Assistant] So this minus will come over here, so ultimately we will get a, b plus and c minus as the postfix format of this small expression. If we consider this as x1, this whole expression will look something like x1 star d raised to e raised to f


[User] Please transcribe this text

[Assistant] Then we have a closing bracket divided by g. Now since we have one more set of brackets, of course this expression has to be evaluated first and in this expression we have multiple operators. We have two raised to operators that is exponents and one multiplication.


[User] Please transcribe this text

[Assistant] So exponent obviously has higher priority than the multiplication. So we have to evaluate these two first.


[User] Please transcribe this text

[Assistant] Now remember in the manual conversion in the rules, we discussed that when the case of exponent operator comes and when we have multiple exponent operators, we start from right to left. The evaluation or conversion happens from right to left. So first this operator will be converted to postfix. So for this operator, the operands are E and F.


[User] Please transcribe this text

[Assistant] So this operator will come over here and we will get EF raise 2 and then this will be considered as OP1 and we have D raise 2. So for this operator, that is the second raise 2 operator, D is OP1 and this is OP2. So now this raise 2 will come over here and ultimately we will have DEF raise 2 and raise 2.


[User] Please transcribe this text

[Assistant] Going from left to right, this expression would be something like d raise to e and f raise to


[User] Please transcribe this text

[Assistant] So this is something that we would have ended up which is not actually correct.


[User] Please transcribe this text

[Assistant] The correct version has to be something like def raise to raise to, okay.


[User] Please transcribe this text

[Assistant] So this is converted to its proper postfix format. This is converted to its proper postfix format.


[User] Please transcribe this text

[Assistant] So we have one last operator that is multiplication operator that will come over here and this entire expression will be resolved. So you will get a b plus c.


[User] Please transcribe this text

[Assistant] And this is OP2 and this is the operator left so this will come over here. So lastly the final conversion will be AB plus C minus DEF raised to and raised to star


[User] Please transcribe this text

[Assistant] So this is going to be the final answer and I know I did it in a little quick way and not so step by step way, that's because we've already solved such examples.


[User] Please transcribe this text

[Assistant] And when you do the manual conversion, this is what the result is. So let's write this result over here.


[User] Please transcribe this text

[Assistant] So that later on we can verify it when we are actually gonna convert infix to postfix using stack and using the pseudocode.


[User] Please transcribe this text

[Assistant] That's where we can cross-verify it. So I'm gonna write the result over here. a b plus c minus


[User] Please transcribe this text

[Assistant] d e f, raise 2 raise 2, then we have a star, we have g and then we have divide by.


[User] Please transcribe this text

[Assistant] So this is the result that we want when we are gonna actually apply the pseudo code as well onto this same expression.


[User] Please transcribe this text

[Assistant] Now I'm gonna erase this out, we've done the manual conversion and now let's see the pseudocode and let's go step by step. We'll read out the instructions, that is the rules, which we've seen in the previous tutorial and I'm assuming you guys already know.


[User] Please transcribe this text

[Assistant] And we will see the corresponding pseudocode statements for those rules. Because these rules need to be converted into pseudocode, right? So technically, we are just converting these rules into pseudocode format so that we can easily write a program using this pseudocode and using the stack data structure. So let's see the pseudocode now.


[User] Please transcribe this text

[Assistant] Okay, so as you can see, it's a fairly lengthy pseudocode, but we will go step by step, line by line, and understand this in very detail. Okay?


[User] Please transcribe this text

[Assistant] So starting off first line says we are creating a function called infix to postfix. So since it's a pseudo code, it is kind of like a code, kind of English statements.


[User] Please transcribe this text

[Assistant] So when we convert this to C++ program or any other general purpose programming language, we can create a function which is named as infix to postfix.


[User] Please transcribe this text

[Assistant] In that we will pass a stack data structure and we will pass the infix expression. So this entire expression can be stored in a string.


[User] Please transcribe this text

[Assistant] At index position 0, this will be at index position 1 and so on and so forth. So, in programmatic terms,


[User] Please transcribe this text

[Assistant] This would be a character array or this can be a string, right? Which will have index positions. In C++ we have C style strings and C++ style strings which we are gonna actually use.


[User] Please transcribe this text

[Assistant] Index position 1, we will have another opening bracket and so on.


[User] Please transcribe this text

[Assistant] So the size of this string you can see is from 0 to 16 which is 17, size equals to 17.


[User] Please transcribe this text

[Assistant] And it's basically a character array, you can think of it as a character array when, when thinking in terms of program.


[User] Please transcribe this text

[Assistant] So that is gonna be passed over here, okay? Now inside this, first things first, we will create a postfix string.


[User] Please transcribe this text

[Assistant] We have the infix string which we are gonna pass in this function. And then we are gonna create a postfix string which will store the postfix expression. That is this expression.


[User] Please transcribe this text

[Assistant] And we will build this expression as we entirely run through this entire function. So we'll see how that goes.


[User] Please transcribe this text

[Assistant] So after this we have a loop which says i equals to zero and i less than infix.length. Now infix is basically


[User] Please transcribe this text

[Assistant] This entire string, the length of this string is 17. So we want to iterate through all these characters inside this string starting from 0 to 16. So that's why we say i less than infix.length. In our case, the length is 17. So we will run from 0 to 16, right?


[User] Please transcribe this text

[Assistant] Now this corresponds to the rule number one which says scan the expression from left to right. So we will start from left that is from zero position and we will go till the right. Correct?


[User] Please transcribe this text

[Assistant] So programmatically we are basically gonna go from 0 to 16.


[User] Please transcribe this text

[Assistant] From left to right. That's how you scan the entire expression from left to right, right? So first rule pretty much is done over here using this loop.


[User] Please transcribe this text

[Assistant] From i equals to zero to infix dot length. Okay. Now inside this loop, we basically have four conditions or four subparts.


[User] Please transcribe this text

[Assistant] Which I have mentioned by numbers. So this is number 1, number 2, number 3 and number 4. Inside 4 we have more subparts which we will talk about but in a broad perspective.


[User] Please transcribe this text

[Assistant] We have four different parts. So what are these four different parts? Let's read rule number two first. The rule number two says print operands as they arrive, which means that at any point in the loop when we are iterating from zero to 16, if the character is a operand, operand is something like a variable or a number


[User] Please transcribe this text

[Assistant] So anything that is not a operator or not a bracket is an operand, right, in our case.


[User] Please transcribe this text

[Assistant] So if an operand comes, we have to print it as it is. So the first condition, that is the first part, that is point number one says, if infix of i is an operand, then postfix plus equal to infix of i.


[User] Please transcribe this text

[Assistant] What does this mean? This means that if in the infix expression of i, since we are gonna go from 0 to 16,


[User] Please transcribe this text

[Assistant] At every iteration, if it is an operand, if it is a, b, c, d, e, f or any other operand, you just paste it.


[User] Please transcribe this text

[Assistant] As it is into the postfix expression. So postfix plus equal to means


[User] Please transcribe this text

[Assistant] The postfix variable that we've created over here, let's write it over here.


[User] Please transcribe this text

[Assistant] At the bottom you can see I have written postfix. So let's build our expression over here. It will get


[User] Please transcribe this text

[Assistant] If infix of i is operant, then just basically put it in the postfix expression that we've created, postfix string that we've created. And lastly, we will print this postfix string, right? So at the end of this entire function, in the postfix string we will have the output. Over here,


[User] Please transcribe this text

[Assistant] Just put the operand in the postfix and at the end we are gonna print it anyways. So part number one or the step number one is done and it is for rule number two. So this is done now.


[User] Please transcribe this text

[Assistant] So operands are done. Operands are basically a, b, c and all the variables. Right? So that's done. Covered. We've covered operands.


[User] Please transcribe this text

[Assistant] The second sub part is for opening brackets. Now remember in the previous tutorial also when we were going through these


[User] Please transcribe this text

[Assistant] So we have 3 separate rules for opening, closing brackets, right? So 10, 11 and 12 are dedicated for opening bracket, closing bracket.


[User] Please transcribe this text

[Assistant] That's because we do not consider opening bracket and closing bracket as operators. Operators are basically arithmetic operators plus, minus, divide by, star, and raise to. In our example, these are the only operators. So opening and closing brackets are not operators.


[User] Please transcribe this text

[Assistant] So for them we have separate rules, that's why we have separate elsif condition, which is covered in point number 2 and point number 3. So point number 2 says, if infix of i, if infix


[User] Please transcribe this text

[Assistant] The character that we are currently going through is an opening bracket, you just push it onto the stack. So you can see


[User] Please transcribe this text

[Assistant] Rule number 10, if incoming symbol is an opening bracket, push it onto the stack. So this is covered. So this rule is converted into its appropriate pseudocode over here. So point number 2 is done. Okay, pretty basic enough. Let's move to else-if, that is third part. Let me just erase this out.


[User] Please transcribe this text

[Assistant] We've done one, we've done two, and now we are at third else if.


[User] Please transcribe this text

[Assistant] So in the third else-if, we are saying else-if infix of i is closing bracket.


[User] Please transcribe this text

[Assistant] So if it's a closing bracket, then pop and print the stack.


[User] Please transcribe this text

[Assistant] Till the stack gets empty or a opening bracket is found.


[User] Please transcribe this text

[Assistant] Now this is corresponding to rule number 11. Rule number 11 says if incoming symbol is a closing bracket, pop the stack and print operators till a opening bracket is found or obviously the stack gets empty so that our condition is not mentioned in the rules because the rules are not very specific because we are not using


[User] Please transcribe this text

[Assistant] Or we are not writing the code using these rules. But when it comes to pseudo code, it has to cover all the conditions because those conditions are gonna get implemented in the code, right?


[User] Please transcribe this text

[Assistant] So when we get a closing bracket, we have to pop and print the stack, that is all the operators in the stack.


[User] Please transcribe this text

[Assistant] And after we've covered operands, after we've covered opening bracket and closing bracket, the only next symbol, that is the only last symbol left, is the last lcf condition, that is fourth part, which deals with operators.


[User] Please transcribe this text

[Assistant] So so far we covered operands which is a, b, c and all the variables. We covered opening bracket and closing bracket. But the operators are left. So the fourth part deals with the operators.


[User] Please transcribe this text

[Assistant] So in the last else-if, that is the outermost else-if, we say if infix of i, that is if any of the character is an operator, in that case, we have some more extra conditions. So when it comes to operators, we have a lot of more conditions, right? So we have still 3, 4, 5, 6, 7, 8, 9, and 12 rules to be covered. So that's why we have more conditions inside this. So let's take a look at what we have.


[User] Please transcribe this text

[Assistant] So let's say it is an operator, it is plus or minus or star or divided by or raised to. So in that case we go in the else if part. In the else if part we have more steps. In four we have four point one four point two and then we have four point


[User] Please transcribe this text

[Assistant] We have 4.2.3.1 which means that we are going inside if and else if conditions.


[User] Please transcribe this text

[Assistant] And then we have 4.2.3.2 also. So we will go through them also step by step and then we will see their corresponding rules in the rules part.


[User] Please transcribe this text

[Assistant] So let's say it is an operator, okay. So if it is an operator, we are going to execute step number four. Inside that we have 4.1. So if it is an operator and if the stack is empty,


[User] Please transcribe this text

[Assistant] Operator means anything which is plus, minus, star, divided by, and raised to, okay? That's what an operator is.


[User] Please transcribe this text

[Assistant] So if it is an operator and the stack is empty, you simply push this operator onto the stack. So that's rule number 3. So we've covered rule number 3. Now let's say the stack is not empty, right? So.


[User] Please transcribe this text

[Assistant] The stack can be filled with other operators also, right? So in that case, we have a lsif. So that's why after 4.1, we have 4.2. In 4.2, the condition is the stack is not empty.


[User] Please transcribe this text

[Assistant] Now in that case, what we have to do, we have to check the precedence of the infix of i, that is the operator that we are at currently with the operator which is inside the stack. Okay, so let's say inside the stack we have plus that is this operator. This is the first very first operator and now minus is coming. So when we are at minus, let me just use another color. So in the operator, let's say we have plus already.


[User] Please transcribe this text

[Assistant] And now we are at this position which is minus, so what we have to do, we have to check the precedence, right? We have to check infix of y, that is the precedence of minus, with the precedence of already existing top of the stack. So this is the top of the stack currently.


[User] Please transcribe this text

[Assistant] So three possibilities can happen. The precedence of infix of i that is this can be greater than the precedence of the top of the stack or


[User] Please transcribe this text

[Assistant] It can be equal equal to this. Equal equal to is a unique case which we will talk about. But let's assume that right now the precedence, let's say we have


[User] Please transcribe this text

[Assistant] Star coming in. Okay, so we are at this position and we have plus inside the stack. So obviously precedence of star is greater than plus operator.


[User] Please transcribe this text

[Assistant] So in that case we will push this star onto the stack. So star will come over here and this will be the new top. So this is basically rule number 4.


[User] Please transcribe this text

[Assistant] Which says if incoming operator, that is if infix of i, that is this operator.


[User] Please transcribe this text

[Assistant] Has higher precedence than the top of the stack. Earlier the top of the stack was plus. So if star operator has higher precedence than the plus, in that case we have to push this star onto the stack, right?


[User] Please transcribe this text

[Assistant] So this is 4.1.1 which is corresponding to rule number 4. Now in case where the precedence of infix of i is less than or equal to the precedence of the top of the stack, we have 4.2.3.1.


[User] Please transcribe this text

[Assistant] But before that, let's say the precedence of infix of i is equal equal to the precedence of top of the stack and the operator


[User] Please transcribe this text

[Assistant] And whichever has the highest precedence, we will calculate it according to the precedence function. Okay? So that's why I'm using precedence and then brackets and passing the character infix of i and then I'm also using precedence and passing the top of the stack character to calculate its precedence. And one of these numbers will be returned


[User] Please transcribe this text

[Assistant] Depending upon that, we will calculate the precedence. But here, a unique scenario can happen where


[User] Please transcribe this text

[Assistant] Which is going to be the basically first race to that we put it onto the stack and now we are scanning this race to of course, when we actually apply the pseudo code on the salt example, we will see that case appears over here right now. I'm just trying to explain in an overview way.


[User] Please transcribe this text

[Assistant] So infix of i is also raised to and top of the stack is also a raised to operator.


[User] Please transcribe this text

[Assistant] So, the precedence is obviously gonna be equal and the infix of i is a raise to. So, the reason why we are having this else if condition, this unique else if condition is because for the raise to operator, the rule of associativity is from right to left. It's not from left to right.


[User] Please transcribe this text

[Assistant] Which is there for, you know, plus and minus and star and divide by. It is a unique case.


[User] Please transcribe this text

[Assistant] Precedence is equal and when the infix of i is basically a race to sign, we simply push the newly coming race to sign onto the stack. So we will take this race to and we'll just put it onto the stack and now this will become the new top of the stack. Because we don't want to pop it out immediately.


[User] Please transcribe this text

[Assistant] If we pop out the first race 2 sign, we will get the result as D E race 2 and then F race 2. We don't want that. Okay?


[User] Please transcribe this text

[Assistant] And right now it might not be clear, but when we actually apply this all entire pseudocode onto our example, things will be more clear.


[User] Please transcribe this text

[Assistant] But just understand that this condition is unique for the race to operator where we have to push the incoming race to operator onto the stack if we have the top of the stack as a race to operator as well. Okay.


[User] Please transcribe this text

[Assistant] And lastly, in the else condition, so the first if was when the precedence of infix of i is greater, the second else if was when the precedence of infix of i was equal equal to, and the infix operator was a race to sign, so there is an and clause in between, and obviously the last condition would be when the precedence of infix of i will be


[User] Please transcribe this text

[Assistant] Less than or equal to the precedence of top of the stack.


[User] Please transcribe this text

[Assistant] So in that case, rule number five applies if incoming operator has lower precedence, then top of the stack, then pop and print the top. And if you see in rule number five,


[User] Please transcribe this text

[Assistant] It states that if the operator has lower precedence, but in our rule number 4.2.3.1, we also cover the equal to precedence. So let's, let's take an example.


[User] Please transcribe this text

[Assistant] Let's say the top of the stack is plus and now we are scanning or we are at


[User] Please transcribe this text

[Assistant] Minus operator in the expression. So infix of i is minus.


[User] Please transcribe this text

[Assistant] And minus has equal precedence as plus, right? So top of the stack is plus.


[User] Please transcribe this text

[Assistant] And we are scanning in fixify, which is minus. So minus has equal precedence as plus. So in that case, we simply pop and print the stack.


[User] Please transcribe this text

[Assistant] And the while condition checks for if stack is not empty. So obviously the plus will be popped out and will be printed in the postfix expression. And once the stack is empty,


[User] Please transcribe this text

[Assistant] We have 4.2.3.2 which says push the current operator which is minus. So minus will be now pushed onto the stack. So plus will be popped out.


[User] Please transcribe this text

[Assistant] Pseudocode is slightly different than the rule, but it is pretty much covering this rule also. And that's because in coding perspective, when you're converting a infix to postfix, the operators are basically coming at the end.


[User] Please transcribe this text

[Assistant] So, ultimately when you pop and print the operators, they will obviously come at the right hand side of those two operands. And you'll see that when we dry run it in a minute. And that is pretty much basically the first iteration. And then we will end the for loop over here.


[User] Please transcribe this text

[Assistant] After going from 0 to 16. Okay, so 16 iterations obviously are gonna happen and every time either point number 1, point number 2, point number 3 or point number 4 will happen.


[User] Please transcribe this text

[Assistant] So either the infix of I that is the character will be an operand, it will be an opening bracket or a closing bracket or it will be an operator. Only four cases can happen.


[User] Please transcribe this text

[Assistant] And depending upon those four cases, we have their corresponding actions in the stack data structure.


[User] Please transcribe this text

[Assistant] So I just gave you an overview about the pseudocode and I know things are still not that very clear.


[User] Please transcribe this text

[Assistant] And I know it will be very clear only after we actually apply this pseudo code onto our example. So now, let's actually do that.


[User] Please transcribe this text

[Assistant] You can take a screenshot of the pseudo code. You can, you know, probably pause this video and note down all the points. That is all the rules as well as the pseudo code because


[User] Please transcribe this text

[Assistant] This is very important from your exam perspective as well if the pseudocode is asked.


[User] Please transcribe this text

[Assistant] So just take a screenshot maybe, take a pen and paper, that is take a pencil and paper and let's dry run this pseudocode. So first just.


[User] Please transcribe this text

[Assistant] Let's track the i value. So the i value obviously initially will be from 0. So we will go from 0 to 16 in our case.


[User] Please transcribe this text

[Assistant] That's the length of the infix expression. This is the entire infix expression. Okay? So initially we will be at position 0.


[User] Please transcribe this text

[Assistant] So the loop will start running, we will say if infix of i is an operand. Is it an operand? No. It is not an operand. Bracket is not considered as an operand. Then we will go to step number 2. In the else if we say


[User] Please transcribe this text

[Assistant] Is the infixify opening bracket? Yes. What do we have to do? We have to push it onto the stack. So opening bracket will be pushed onto the stack. And this is basically the top of the stack.


[User] Please transcribe this text

[Assistant] Since step number two is executed, that is this else if part is executed,


[User] Please transcribe this text

[Assistant] Obviously third lsf will not be executed and fourth lsf will not be executed. We will come at the end of the for loop because either of these four


[User] Please transcribe this text

[Assistant] Points will be executed, right? When we are actually writing a code.


[User] Please transcribe this text

[Assistant] The if, else if and else control structure works in such a way that only one out of the entire


[User] Please transcribe this text

[Assistant] If, else if and else block will be executed. So in our case, right now,


[User] Please transcribe this text

[Assistant] Else if was executed because the character was a opening bracket.


[User] Please transcribe this text

[Assistant] So step number three and four will obviously not be executed. We will come at end of the for loop and now I will become one. So I has become one. We are at this index position. Again, we will start with the loop.


[User] Please transcribe this text

[Assistant] First is we'll check if this infix of i is operant.


[User] Please transcribe this text

[Assistant] Is this opening bracket an operand? No. Then we will go to step 2, that is second L-save.


[User] Please transcribe this text

[Assistant] In this else if we check if, if infix of i is opening bracket, yes. So we just have to simply push it onto the stack. So we'll push it onto the stack. This becomes the new top of the stack.


[User] Please transcribe this text

[Assistant] And then obviously step 3 and step 4 will not be executed because these are other elsef conditions. Only one elsef is gonna be executed. We will come at end of the loop and we will again go at the start. i will become 2. So at i equals to 2, we are at this index position. Inside that again we will check if infix of i is an operand. And now it is true, right? a is an operand. a is a variable which is considered as an operand.


[User] Please transcribe this text

[Assistant] So the rule for operand is print operands as they arrive. And in our case, we will append this a into the postfix expression. So postfix plus equal to means in coding perspective, it means the existing expression postfix plus infix of i.


[User] Please transcribe this text

[Assistant] Point number 4 elsef will not be executed. Obviously, we'll end the, come at the end of the for loop. Again, go at start of the for loop and i will become 3. So when i will become 3, we will be at index position 3. At index position 3, we have operator plus. Okay. So in the conditions, first condition will not be true because it is not an operand.


[User] Please transcribe this text

[Assistant] Second condition will not be true because it is not an opening bracket. Even third condition will not be true. It is not a closing bracket. We have a plus sign which is an operator.


[User] Please transcribe this text

[Assistant] So ultimately the fourth condition will be true because if infix of i is an operator, which means it can be either plus, minus, star divided by and raised to. It is plus.


[User] Please transcribe this text

[Assistant] So this condition is true. So we'll go inside step number 4. So we have 4.1. In step number 4.1, we check if stack is empty.


[User] Please transcribe this text

[Assistant] Is it empty? No, we have two elements or two symbols which are two opening brackets, so stack is not empty.


[User] Please transcribe this text

[Assistant] So 4.1 will not be executed, so we will go in the elsef part, which is stack is not empty.


[User] Please transcribe this text

[Assistant] Which states that if precedence of infix of i


[User] Please transcribe this text

[Assistant] is greater than the precedence of stack of top. Okay, so right now infix of i is plus. What is the top of the stack? Top of the stack is opening brackets. Now according to our rules obviously we've seen in the theory part in the rules part


[User] Please transcribe this text

[Assistant] But when we are implementing the code, when we are writing the pseudo code or actually writing a program,


[User] Please transcribe this text

[Assistant] These brackets are not operators at all. We are not considering them as operators only. Operators are plus minus star divided by n, this raised to exponent operator. So, when we are calculating the precedence of stack of top which is opening or closing bracket,


[User] Please transcribe this text

[Assistant] What we will do is, we will give this the lowest precedence, that is the value. So in the code when we actually write the program,


[User] Please transcribe this text

[Assistant] Plus and minus will be given precedence of 1, that is the value.


[User] Please transcribe this text

[Assistant] That is the weightage, star and divide by will be given 2, raise 2 will be given 3 and otherwise in else, in the else part we will


[User] Please transcribe this text

[Assistant] Return minus 1. So, this precedence will be a function which will take a character.


[User] Please transcribe this text

[Assistant] And depending upon whether it is plus or minus, star or divided by or raised to sign, it will return 1, 2 and 3. Otherwise, it will return minus 1.


[User] Please transcribe this text

[Assistant] So that's how the precedence function will look like when we actually implement the pseudocode.


[User] Please transcribe this text

[Assistant] But right now I'm just giving you a overview or a preview of how it would look like. So what will happen? The precedence of stack of top. Stack of top is this opening bracket will be minus 1 because it is not considered as an operator. Precedence of plus and minus will be 1. So 1 is obviously greater than minus 1. So this 4.2.1 will be true.


[User] Please transcribe this text

[Assistant] And we will push this infix of i which is currently infix of 3 which is plus onto the stack. So plus will be now pushed onto the stack and now the new top of the stack will be plus. Okay. So I hope you understanding this. It is slightly different. That is the precedence is slightly


[User] Please transcribe this text

[Assistant] When you are implementing it, we do not consider opening and closing bracket as operators.


[User] Please transcribe this text

[Assistant] These are just used to determine which part of the expression happens first or gets converted first. That's why they are not treated as operators primarily. So now we have a new top of the stack.


[User] Please transcribe this text

[Assistant] So we will come outside this inner if. So essentially 4.2 got executed. That is stack is not empty. So this got executed, which means step number four got executed. So we've pretty much covered this iteration. Anything else will not be executed. We will come at end of the for loop. That is the outermost for loop. We will go at the top and now I will become four. So let's make I equals to four.


[User] Please transcribe this text

[Assistant] So when i becomes 4, we will be at index position 4, which is our operand.


[User] Please transcribe this text

[Assistant] Pseudo code will be executed. The first part checks if the infix is an operand. Yes, it is an operand.


[User] Please transcribe this text

[Assistant] So B will be appended to the postfix expression. Currently the postfix expression only has A. So we will attach B over here.


[User] Please transcribe this text

[Assistant] That is because postfix plus equal to of infix r5 which means current postfix value plus


[User] Please transcribe this text

[Assistant] Since point number one is executed of the pseudocode, point number two, three and four will not be executed. We will come at end of the for loop and I will now become five.


[User] Please transcribe this text

[Assistant] Now we are at i of 5 which is a minus sign, so let me write.


[User] Please transcribe this text

[Assistant] First point or instruction number one will not be executed.


[User] Please transcribe this text

[Assistant] So third point will not be executed. So fourth will be executed. Obviously it is for operators, which include minus also.


[User] Please transcribe this text

[Assistant] In 4, we have 4.1, which says if stack empty, then push in fixify. Obviously, the stack is not empty. You can see three operators or three symbols basically, one operator and two opening brackets. So it's not empty. So 4.1 will not be executed.


[User] Please transcribe this text

[Assistant] 4.2 will be executed because 4.2 is for stack not empty. So this condition is true. We will go inside 4.2. Inside 4.2, we have 4.2.1, which says if precedence of infix of i is greater than precedence of stack of top.


[User] Please transcribe this text

[Assistant] Now infix of i is minus, stack of top is plus. The precedence of both of them is 1 and 1, right? That's what we have deduced over here.


[User] Please transcribe this text

[Assistant] So obviously it is not greater, it is equal. So 4.2.1 will not be executed. Let's check for 4.2.2. In the elseif,


[User] Please transcribe this text

[Assistant] Are the precedences equal? Yes. Precedence of infixify is equal equal to precedence of stack of top. 1 is equal to 1.


[User] Please transcribe this text

[Assistant] This is true. However, there is one more and clause and one more condition which says is this in fix of i that we are at, which is minus, is it equal to a race to sign? Is it a exponent? No. So this becomes false, right? And since there is a and in between,


[User] Please transcribe this text

[Assistant] The precedence of infix of i is less than equal to precedence of stack of top.


[User] Please transcribe this text

[Assistant] Because obviously, what is the condition while stack not empty? Is stack empty? No. We have three elements in it. Then the second condition in the AND clause is infix of i.


[User] Please transcribe this text

[Assistant] Which is minus, the precedence is, is it less than or equal to, it is equal to the precedence of stack of top. Stack of top is plus, their precedence is equal.


[User] Please transcribe this text

[Assistant] So this condition is true, this condition is true. So we will go inside the while loop which says then pop and print the stack. So pop. So first thing we will pop this plus sign.


[User] Please transcribe this text

[Assistant] It will be popped out and appended to the postfix expression. So let's write plus over here. Let's remove it from the stack. And now the new top of the stack is this opening bracket. So first pop and print is done.


[User] Please transcribe this text

[Assistant] Again the while loop will execute because obviously stack is not empty. So this condition is true. However, now when we check the precedence of infix of i, infix of i is still minus. But now,