Hi everyone.
So in this video we will discuss how to it is actually stalled.
So for example if it will create a windy area let's say 5 The size is 5.
So what would happen.
So basically you will get five blocks of memory five blocks of continuous memory and the sites would
be drawing debates.
And let's say if you want to take in both.
So what you will do you will create a variable end and you will dig the value off and from the user
and let's see the value of honesty.
So the value find this tree.
I will use the first three blocks and these two blocks are not used.
Now similarly let us consider to the idea.
For example if you create a judiciary let's say the number of rules out of five and the number of columns
that are also five.
So what will happen.
You will get five fruits and five columns.
So first or second or third row fourth and fifth row.
Similarly first column second column third column fourth and fifth column.
And now let's see what I will take.
So I will take the value of rows and columns input from the user.
So I am going to create the variable and meaning and lose it will give me the value of M which is the
number of rows and end which is the number of columns.
Let's say the value of M is three and the value of these two.
So what I will do I will take.
So I will make use of three rows and only two columns.
So only this much part of the truly array will be used.
So just like this one.
So in this case I am losing three blocks.
And in this case I am losing only these three three rows and two columns.
So this is not actually how my two areas are stored so there are two ways of storing my to the 80.
So first one is actually your major and the second one is actually column major so column
column Major.
And what is their difference so let's say this is one two three four five and then six seven eight nine
and ten.
So it will be 15 then 20 and then here you will have 25.
So in the room we did form.
So what I will do.
So this ad is actually five cross five.
So first thing is same between column major and all major.
What you will have.
You will have one DST basically.
This is you are one damage Larry and its size will be five to five.
That is there will be total 25 elements.
So the first index is going to be 0.
And the last index is going to be 25 24 because there are 25 blocks.
So the last 16 is going to be 24.
I am a bleeding myself.
So this matrix is actually 5 close five and how this is actually stored.
So the first step is same for the major or the column Major what is happening inside the memory.
You will get a one degree you will get a continuous block of memory 25 blocks of continuous memory first
your next is obviously 0 and the last Unix is obviously 24 now.
Indeed all major forms so.
So this is.
So this is let's say for row major and now this is column Major again the size of the array will be
same.
This is your zero index and this is your index 24.
So this is your column Major.
Now what will happen.
So indeed what data from what I will do so I will store the first row.
So this will be one two three four and five.
Then I was told the second row then I was to the third row then I was told the fourth.
And finally I restore the fifth row.
So this will be 25 then 24 then 23 and so on.
Similarly this will be six then seven and so on.
So this is all Major.
We are starting revise.
So we are storing railways first.
I am storing the first row then stored the second row then stored the third row then stored the fourth
row and then stored the fifth through.
So this is how we rule major books and read this column Major.
You can guess first stored the first column then stored the second column.
So first let us draw the first column.
So this will be one then it will be six then it will be eleven then it will be basically 16 and so on.
So first stole the first column then stored the second column then stored the third column.
So this was first.
This column will be stored then this column.
So first this column will be stored then this column will be stored then this column then this column
and finally this column.
So the last five elements will be 25 then 20 then 15 then 10 and then five.
I hope you understood both.
So rule Major is stored rule by rule store the first rule then store the second rule then third then
fold then fifth and so on and then column Major.
I am going to store column by column so first store the first column then you will store the second
column then you install the third column then you will store the fourth column and so on.
Now among these two major is actually the correct one.
So we use this rule Major.
I am repeating myself.
So this is how we visualize our judiciary.
So this is only for visualization.
Now inside the memory inside our system this truly metrics is actually stored as a one dimensional area
and to store this one dimension Larry.
Basically there are two approaches.
First is the major approach.
Second is the column measured approach.
So among these two approaches draw major approach is used.
So we are going to use that all major approach and column major approach is not used.
It is very rarely used.
All the systems in today's world uses rule major approach.
Now in the room your approach let's see how it will work so for example if you want to store something
let's say my area is a again five rules five columns so you will get five rows and you will get five
columns.
Correct.
So the first rule.
Second row third row and fourth and fifth rule similarly first column.
Second column third column fourth and fifth column.
And now let's say you want to do something like this go to second row.
You want to do a of to 1 equals 7.
So this is 0 1 2 3 and 4 this is 0 1 2 3 and 4.
Now we are going to visualize it like this but actually it will be stored as a one day area so if 2
1 So this is 2 and 1.
So here I will store 7 for regulation.
This is correct but how it will actually be getting stored.
So basically again you will have one day at a and we are actually going to store in the true Major form.
So this is indexed as you do this is in next 24.
Now I want to store this element 7.
So what we have to do we have to find the index so basically you have to convert the politician to come
on into the one D.
So this is one B area so you have to find the correct index is starting to call Milan and how we can
find that correct index.
So basically let's see.
So this has to come out when.
So what we have to do so we have to skip first row then we have to skip second row.
So how many cells.
One two three four five six seven eight nine ten.
So how many cells we have to skip.
So first of all the value of.
So this is actually true.
So you have to skip Tutu's.
So this is first rule that you have to skip.
This is the second rule you that you have to skip and then you have to skip one column.
So two rows plus one column and how many elements how many cells are present in doodles.
So in Vendrell there are five elements.
Five cents.
So two into five plus one.
So basically we have to skip 11 cents we have to skip 11 cents and we have to insert our element and
do well to sell.
So we will we will insert seven inside twelve to sell now not Wilson will be present at the next eleven.
So add to next 11 because the indexing starts from zero.
So that Wilson is actually next eleven in one dimension Larry so you store seven at index eleven of
this so actually what happens.
So this calculation.
So this calculation we will not do this calculation and this calculation is actually automatically done
by our system so internally our duty edit internally our duty area is actually going to be stored in
the room we dare form basically in the one dimension Larry and this calculation the calculation of finding
the correct index.
So this is going to be done by our system automatically can we generate the formula.
So for example I want to insert that I Yeltsin and the G8 column.
So what is what will be our formula.
So here we can see if the value of so this is actually a and this is actually G so so we have to insert
at index eleven so for finding the eleven what you did you multiply two what to two is I.
So you will multiply with how many cells are present in.
Wonderful.
So five other cells present in bundle basically these are the columns.
So these are the columns and what of the value of columns so let's see.
So are denotes rose and c denote column.
So I am a diplomacy and then basically this plus one is actually the value of G so you relate.
Plus G.
So this is the formula for calculating the index
so just let us take an example.
So let's say you want to insert at of three called Michael so according to this one AFTRA do so this
is three and this is two.
So let's say you want to insert element eight.
Now let us use this formula.
So the value of pi is 2.
So this is your eye.
And this is your G.
So 3 multiply how many columns are there.
So you can see there are five columns.
So that's why I told you the value of column is mandatory rules are not mandatory because in the formula
column will be getting column is getting used not rows.
So there are five columns.
And what is the value of j.
So the value of j is too so according to this formula you should.
In so doing element so three into 515 plus two you should insert your element at index 17.
So let's say this is your index and 17.
And here you will store the element eight.
Now let's see with that our output is whether this formula is correct or wrong.
So skip one two three four five six seven eight nine ten eleven.
This is drill 13 14 15 16 17 and 18.
So basically you have to skip 17 cents.
So how I mean since we have to skip we have to skip 17 since that means I want to insert at 18 to sell
and in the 80.
The indexing starts from zero.
So 18 to sell means the index is going to be 17.
So this is the formula and you have to remember this formula so finally.
So finally this is I am writing that is n for you if you are creating an eddy the number of rows I'd
add the number of columns to see.
So in the middle throws out in ordered by capital letter at a number of columns and in order to make
capital letters c.
And if you want to insert if you want to excess yet row and git column.
So the formula for finding the correct index is actually a minus.
I multiply so this is I multiply C plus G.
This is draw major.
So what is the form logging out is the number of rows sees the number of columns you want to access.
I get rule jeered column l I.
So this is nothing this is just I will get multiplied with these columns this value and you will add
plus G.
So this is for real major and all the computers uses rule Major.
So if you want to find out the formula for column Major what do you do you will just write the opposite.
Basically interchange identity and invent change.
I N G.
Simple just everything will become oppose.
So it all major is not important.
Our system stored the data in a true Major form.
So that's why this formula is important.
And that's why I told you the value of column is mandatory via value of column is mandatory.
So even if you will not give the value offered so you are not giving the value of our let's say Vanuatu
initializing the eddy you are not giving the value offered.
Now in order to access a neutral and yet column What do you need.
You need only the value of c you can see in this formula is not used.
You only need the value of c.
So that's why the value of C is mandatory.
You have to give value of C so that so that system can use this formula.
So that's why the value is important.
That's why C is mandatory.
And similarly so you can see here what we are doing.
So let's say we do not initialize the 80
so let's say I'm creating an so this is let's say the golem ended ended.
The rules are 5 5 rules and and let us stick in input from the use it only.
So what we are doing here and now let us call Brent at a function.
Now if you remember I told you that whenever you are passing a duty area as input to a function you
have to pass the number of columns.
So here the name of the edit is actually e you want to give em man you will give an.
So what do we are doing here.
So what we have to do here.
So if you remember that I told you that whenever you want to pass our duty to a function you have to
give number of columns not the number of rows and the middle throws out option number of column sideman
duty.
So I am creating an 80 of five routes and hundred columns.
Then take value if I meant it as input.
I am taking that is input then I'm cutting the function print diary I'm giving M and Eddie so eminent
that correct.
But here what you are doing you are writing e if I G and what is the formula for AIG.
So the form lays.
I multiply columns plus G.
Now my question is how this function will be able to find the value of c c is the number of columns.
So there is no way that this function can find out the value of c.
So what we have to do we have to pass the value of c and how we will pass.
So this is C so C is actually a hundred.
So you have to pass handed.
So that's why you have to write under there.
So it was a Lear 5.
Now you have to write under there.
That's why I told you that whenever you are passing you are to the area as input to a function.
The value of the rule are optional.
You give or not give.
It is your choice but the value of columns have to be given.
So you have to give the number of columns and the to match these two value should match not intended.
Then only this formula is valid then only we will be able to find out the correct index.
So if you will pass handed here then C will become hundred.
So that's why whenever.
Always remember the value of column is very very important.
So that's why you have to write under there.
I hope I am clear to you and all of this is valid because our systems to our to the error in draw major
form.
This is your one theory.
So your to the idea will actually will be stored in this one the very first the first one will get stored.
So first row will come here then second row then third row will come then fourth row will come then
fifth row will come.
Then six will come and so on.
So for a row major.
This is the formula and I hope you can remember this homeless remembering this one life is really important
and I hope you guys know that why you have to pass the value of columns to the function and why we have
to give the value of columns when you are creating a duty 80 because of this formula and because of
how do the ideas are actually being stored how do the ideas are actually getting stored in our system
memory.
So if you have any doubt in this concept you can definitely ask.
I will see in the next video that by.