Where does AI exist? We use the letter L to indicate the number of characters in a given data object. If it is a four-character word, the location of any A.I. is equal to A1 equals to A1, which is the location of the first data. The location of the first data is the address pointed out by the pointer just now.
The address of AD1 plus I-1 times L. L is the number of digits for each data object. So, from A1 to A2, where does AI start? You can calculate it according to this formula. This is relatively simple. It's easy to understand.
Next, we know that if we open a continuous storage space, we also know which part of the storage space will be used. We can now write the basic structure of a data table. First of all, let's look at some initial descriptions. The example here is to use C to dynamically assign a 1-digit number.
For example, if my initial value is 100, This can be changed. How can we write the structure, the struct? First, the first item is the mechanism of my storage space. This is the beginning address of A1. This is the beginning address of the distributed file search.
This is the machine we are talking about, the one with the needle. And this length is the current length. The current length is how many lines I have inserted into this order table. Because the first time I opened a space, I might have opened a space with 100 integers.
But in the process of insertion, I may have inserted 50 data for the time being. So what this line records is how many data are there in your current data table. It may not be 100 in the beginning. And then this size, size is the current allocation storage capacity.
If we use 100, the value here is 100. Then give this slot a name. It's called SQList. Do you know what it means?
This is a description of the structure of our data. Here are the basic operations we need. Let's take a look at the basic operations we just listed.
Let me show you some examples of these basic operations. For example, this initialization. How do you write this function? At the very beginning, it is equivalent to dividing. For example, save 100 columns. When I call, I pass in the number of data.
For example, this list initial size, let's say my name is... So this is the total storage space we need. And the return is our base address, which is the initial memory address of the memory space. The condition of the clothes here is compatible with this map.
If you fail to allocate, you will be rejected. If there is no withdrawal, it means that the allocation is successful. At this time, our L is the length of the data table just now. The length is actually 0. Now it is an empty table. The size of the memo is the size of my initial space.
I can put 100 data in it. Then I return it. This is an initialized voice memo.
If you know how to write this, you can refer to this. It is very similar to what we just saw. We define a class and a name in here. In this list of classes, we need to have 数足,数足就是用了一个指针表示的,最大的长度,实际的长度 It shows how much data is actually stored. The following is the basic operation that we need to implement.
It also includes insertion and deletion. Please note that some questions need to be checked. Please pay attention to the question. If the question requires you to use memory allocation, how do you operate it? If you don't have it, you can use the numbers in the code.
For more details, please refer to the requirements.
Next, let's talk about the other operations of the order table. The first is the insertion operation, which is how we add new data to the order table. When we use continuous storage space, for example, we have put these data into the continuous storage space.
If I need to include the 3rd and 4th characters, For example, when I want to put a new number between the elements, for example, I want to put it here, where the bottom line is 3, if I want to put it at 50, At this time, we need to pay attention to the steps we need to take for the insertion operation.
Because it is a continuous storage space, I have to squeeze this 50 to this position. I have to put this position The following line shows the result after insertion. When I want to insert a data into a specific location, the writing method of the function is to move all the data to the back, and then insert a new data into the output location.
This is a version operation. Let's take a look at the code for the input function. The capital L stands for the order table. This is the structure that we used the memory allocation method to create. The E stands for the new data that we are going to insert.
The I stands for the position that I want to insert. I want to insert it at the position of the I. At this time, we need to make a judgment. The position of i cannot be outside the range of the data I already have, otherwise I will make a mistake. This is to deal with an abnormal situation.
Longitude means the number of data. When it exceeds the number of data I have distributed, If I want to insert new data, it is possible that the space I have allocated before is full, right? So when this happens, we need to redistribute. When we need to redistribute, we use the realloc function.
to calculate the size of the memory occupied by each data element. Then it returns a new address. Returns a new address. The following is also to deal with abnormal situations. If it fails, it will be rejected. If the feedback is successful, it will give you a new address, which is a new base, and you will save it to the address of the order table.
Then its size will increase. If it is increased by 10, it will be increased by 10. Let's take a look at the following part. When you want to insert a new data 1 to the position of i, if we start with 0 at the bottom, the bottom is actually i-1 when you insert it to the second position.
At this point, we need to cancel the data. Because we need to start from this data and deduct all the other data. This is a loop. This loop starts with the data you want to insert, and then moves backwards. You can take a look. What we need is this P.
P is the last one, the last data. Let's start. Then move it to the right. Then go back to the second row in the P-short part. Let's look at it from this picture. If I were to deduct 16 from 63, what would we do? We would start from the last digit. From the last beat, move it to the last beat.
This way, you can emphasize a place and emphasize a beat at the same time. So, what we are writing here is the last data obtained. The last data obtained. P plus 1 is equal to P. It moves it to the right. P dot dot is equal to... The second digit is the same as the first one.
So it starts from the last one. After you move it like this, this part will come out. Finally, we will move to the bottom of I0E. We will use E, which is the new data. I will put it in the queue, which is the target that I want to insert. Finally, the number of data elements will increase.
This is an example of an insertion. Let's take a break.
Basically, if you have studied programming and C, you should be able to do it. If you look at the code, you may still have some difficulties.
In the afternoon class, Mr. Lu will be teaching everyone. We also have an assistant teacher.
Basically, there is no way to talk about it. Because if you pass the program design, you will only be able to do it at the level of algorithmic design. So you have to make the most of this semester's time. Because our major is programming, we still have to pass this level.
This is our foundation. So you have to make the most of this class and this semester to train your ability to realize it. This is the plug-in we just talked about. Let's use the time complexity analysis method we just talked about to see what the time complexity of the plug-in program is.
We still have to count the number of times the basic operation is executed in the program, right? Let's take a look. There is a very simple strategy. You can quickly judge all the functions. The punctuation, calculation, and condition-judging punctuation are all long-term.
So you can think of them as OEs. Add them up, they are also OEs. So you only need to pay attention to the loop. In the program we are currently working on, all you need to do is pay attention to the loop. Look at how many layers it has. In the Xcode program, where is the loop?
It is here. This is the place of the retrocircle, right? In the retrocircle, what it does is... Let's look at it with this picture. From the position of the insertion, all the data will be in the same position. So the number of times this loop is executed is...
Every data is meaningful. This data is meaningful. So how many times does it execute? If I have a total of n data, The position I inserted is the position of the i. The data I want to move is...
n minus i, right? So, do we say that its answer is greater than n minus i? No, it can't have this. This is a typical voice memo. Its complexity will change depending on where you insert it, right? Let's say I insert it at the last digit.
In the last one, the complexity becomes OE. Because if I insert it to the last position, I don't need to have this kind of data. I can just fill it in. If I insert... The voice memo will be sent to the first location. The data I need to move is...
I think all the data should be moved backwards, right? So, this program will be different depending on where you insert it. It has different punctuation. In this case, we usually call it the lowest punctuation in the worst case. Therefore, it takes a long time to insert it.
In our analysis, the worst-case scenario is a big error.
Another way is to calculate the average time complexity. The average time complexity, because our i can go from 1 to n, which means our time complexity can go from 1 to n. In fact, this voice memo is still a big problem for us to solve. There may be a number in front of it, but usually this number is omitted.
There are a few more operations. The deletion operation, I need to delete the first data element. In this process, it depends on the example. If I want to delete 16, which is the position of the lower third, then this place is empty. For a continuous storage space, it can't have a gap in the middle.
So when we delete a data object, we need to move all the data behind the position of I. So it's the opposite of the insertion. The insertion is to move all the data in the inserted position to the right. If you delete one, you have to move all the rest back.
After deleting it, you can see that the following three data are moved forward and form the following network. Let's take a look at the program. The order table is still L. We need to delete the second data element, which is E. First, we take the data that we want to delete.
Our DI data is stored in the i-index. We take the data and put it in P. Next, let's look at this Q. This Q is the location of the last data. The last digit is L1M, which is the base value of the order table. The last data point is where the G address plus the length minus 1 is located.
This is the same formula as the calculation of where the data is stored. The next cycle is that we need to move all the data forward after we delete the data. So in this place, let's go back to this picture to see it more clearly. It starts from here.
从这个位置开始数据,往前移一个,然后这里就空出来了,后面这个再往前移,后面这个再往前移。 So in this code, our P This P is from our We will start from the point where we want to delete. We will move the next one in. Then it will take the next element. In this way, we have completed the left-moving part of the data.
Remember to reduce the length of the table to 1. Because we have deleted a data.
Next, there is a deformation delete. The parameter for this delete is how many data I can delete. This is quite simple. Next, there is a variable. My delete is not about how many, it is about a specific data. For example, I want to delete 10 numbers.
It does not indicate how many numbers I want to delete. To delete 16, we need to find where 16 is. In this version, when you want to delete a data, you need to do a query first. When you do a query in the database, you start from the first data, to list all the data in the database.
Let's start with the first one. Is it equal to 16? If you find it, you will know where it is. Let's take a look at the code. The name is different from the previous one. It is called locate and delete. I need to check if it can be deleted. At this time, there are only two parameters, so there is no i.
There is no number. There is only l, which is the data table. And x is the data you want to delete, for example, 16. The first thing we do is to look for the data to be deleted. When we search, we write in the order table. First of all, we need to make a judgment in this loop.
Then my i++, which is to say, from the beginning of i0 to the beginning of i1, should be compared with this i4. If it is not equal, this i++ should be moved backward to see the next one. If you have found it, please wait. If you have not found it, please look back.
If you have found it, please look back. This is what we should do. This process is similar to what we talked about earlier. After I find it, I will start to move all the data forward from where it is. So what we see here is that our loop starts from the position of i plus 1, which is the position behind the number I deleted.
After the execution of this loop, I actually finished it. End of movement. Then I reduced the length of the data table to 1.
The condition is that the IA is less than the length of the sequence. This is to prevent this from happening.
Because we are going to do a search first, and then there will be a situation. In the process of my search, I did not find the data I wanted to delete. In this case, this one-off loop can be controlled here, which is this IR. Because our i is added all the way, right?
Go back. Help me to reach the last element of the data. At this point, the word loop will exit. If you don't write this, you will make a mistake. In the initial case, if i is greater than the length of the sequence bar, we need to give a hint that delete data does not exist.
This is the search and delete function. Let's look at the neural complexity again. How about this time complexity? We only need to look at the cycle, right? Okay, we only need to look at the cycle. So the cycle, first of all, what is the cycle? How many times will this light loop be executed?
Its stop condition is i less than this length. So, in this situation, it seems to depend on when I can find X. It is a variable situation. Let's consider the worst-case scenario. In the worst-case scenario, how many times should I look for it?
This is the situation. In this situation, if I find the one inside, let's take a look. This part is quite interesting. If I find the last data, find x, this is when I want to delete it. If I find this, and I want to delete it, I just delete it. So, in the process of deleting, the complexity of my data transfer is...
Because I am the last one in the mountain, I don't need to move. So the total time is 05.01.
But there is another problem. If I am the first person to find it, and I want to delete it, Then I have to move all the data to the front. At this time, my loop is not a long time. I have to move all the remaining data forward. So this loop will be executed again.
This is the history of OWN4. So the overall complexity is still the same. So in the process of finding and deleting, It either refers to the processing of data, or to the process of data transfer. But what if you are in the middle? Think about it, if I'm in the middle, for example, 16.
When I want to delete the 16th data, my complexity is still large. This is the first half. After deleting it, I move the second half forward.
Next, there is one more operation. This is a combination operation of the sequence table. In this scene, I need to combine two proper punctuation. It creates a new and interesting formation. You don't have to feel unfamiliar with this formation. You can think of it as two interesting sequences.
To put it simply, it is a combination of two order tables. Let's say my two order tables are A and B, and I want to combine them into C. After combining them into C, C still has to be an order table with D and O.
Let's write an example.
For example, my A and B, A is one and O is two.
1, 3, 5, 7, and then B is 2, 4, 6. Let's say A and B are in this order.
Now we are going to get a C table.
C is a combination of A and B. It is still interesting. In this part, Let's take a look. If we still use the order table, it means that we need to use a new continuous group function for the C table. Let's look at the code. The size of C should be calculated according to the size of A and B.
If A is 4 and B is 3, then C should be 7.
There should be seven. Now, the LALPLC that we have passed in here corresponds to the A and B and C tables respectively. In this, it avoids the distribution process of C.
First, we need to calculate the length of the C table. The code is the size of the C table should be equal to the length of A plus B. It is the length of C. Then we use the memo to allocate. The length allocated to the C table is its length. In other words, we have to allocate these seven consecutive spaces.
After the allocation is successful, we will go down. If the allocation fails, we will deal with the abnormal situation. After the allocation is successful, let's take a look at the operation process. We will have a... The last data for A and the last data for B.
There are two marks. Find this position first. Let's write it in B standard. This represents LB.
This represents the first address. For B2, this is the first address, so the last digit of the address. It should be long and short. Because if we look at it from the bottom, we can already start to see it. So these two lines, These two rows can be used to calculate the last digit of A and B respectively.
These two positions will be used when we combine A and B, when we discuss A and B, we don't cross the line. The PADAS and PBDAS are in the condition of this loop. In the conditions, there is a control boundary. My PA should be less than this last. PB should be less than PB's last.
Each of them cannot exceed their last data. These two conditions must be met at the same time. Let's take a look at why there is a mismatch. Let's look at the mismatch first. At this time, we will merge. We need to make sure it is orderly. So we start from the first one.
他是有序的,他是有序的。 所以我们要让他是有序的时候呢, 这两个都从第一个开始,我们就去比较。 Comparing 1 and 2, we can see that PA and PB are smaller. If pKa is small, then what? Else is the opposite. If pKa is large, then what? After comparing these two, if pKa is small, we need to give the small number to c.
If A is smaller, we need to save it. If A is smaller, we need to save A's data. The pointer should point to the next number. Because this has already been taken. When it comes to the next number, what we are thinking about is B2 and A3. Since b2 is smaller, I will subtract b2.
And now we are at this part. The difference is between 5 and 6. 5 is smaller, so this is 5. The last one is 6 and 7. This if-else is looking at who is small in A and B. If the data in A is small, we store the data in A into C. And then add them all.
Add them all means move one down. Else, since B is smaller, we will add B and C to C. I feel like I need to shorten this part.
Let's make it simple. Let's say I only have one in my bag. I only have one. One and two. After comparing, save one. After the second and third strokes, the second line comes down. At this time, the second line is gone, right? In this case, We can see that the condition for b is less than or equal to last is not met.
So the second hand will jump out.
Up to this point, I have finished the B table, and there is no more left. So in this forgetful situation, I don't need to compare A with B. I just copy the rest of A directly to the next line. So, when my B... When you have reached the last digit, the word loop will jump out and you will have to look at the next digit.
Which one will we execute? It depends on A and B. Who hasn't reached the last one? Obviously, if the above one is because... If B is the last one to jump out, then in the following two ORs, we will definitely enter the loop period of a to the right of a.
If A is shorter and B is longer, the above value will also jump out of one of the tables and find the corresponding winning part below. In the end, we have completed the process of merging two order tables into a larger order table.
Let's take a look at the complexity of this program. Let's take a look at the video. There is no loop at the beginning, so we don't have to worry about it. The loop is at the bottom. How many loops are there? Let's take a look at these three circuits.
The first circuit is executed by... It is related to the length of A and B, right? A and B must be satisfied at the same time. I will only solve this loop problem if I don't reach the last one. So, the first cycle I want to do, the number of times it has to be executed, let's use the number A.
The length of A, the length of L A and the length of L B are their lengths. The first loop is actually... Let's simplify it on A and B.
So the first equation has the smallest values of a and b. The first one is a question, right? It depends on which one is shorter. And then, the remaining two vowels, Because if A is shorter, and A is processed at the top, the circularity of A will not improve.
It is the same anyway. So in the following two whiles, only one will be executed. So how many whiles will be executed?
It will be executed in this order. Because in terms of meaning, the two circles at the bottom are the long ones. So the answer is, add these two up, and see how much it is.
Thank you for watching!
It depends on the length of the line.
Okay, and then slowly...
Next, we will summarize the data table. This table is a bit long. The order table is the first linear order structure we talked about. The linear data structure is a logical relationship between the data. That is, every data has its only starting point and only end point.
Please remember this relationship. When we implement it, we use a continuous storage space to express the linear logical data structure. After reading the codes, have you noticed how continuous storage space is realized?
How does the memory structure express the logical structure?
Let's take the example of a tree. This tree has a front area of 3. We need to compare the logic structure with the physical reality. The logical structure is like this. For each data set, the front area is 3 and the back area is 5. This is the logical relationship.
We say that this is a linear structure. So, what we see today, when we use continuous storage space to realize this logical data relationship, how does it find the front area and the back area of a data set?
Yes, the next line. If it is a group of numbers, let me write it down. If it is a group of numbers, the next line starts from 0, 1, 2, 3. This is the lower back, and this is the C-section. Thank you.
Our CI is the data in this line. Its front area is C.
This is the writing method of a set of numbers. So who is the front end of a set of numbers, and who is the back end? This is the linear relationship between a set of numbers.
Can you show me the address? I don't think I need to write it down. This is the address of the second data. The address of the precinct is...
To reduce the storage space of data, we use...
Let's use S1 as an example. Let's use S1 as an example. How many U characters does a data element need to occupy? If this is a whole number, it will be 9400. If you are someone else, how many times do you need to take a data item? So if I am using a continuous way to search for data, the linear structure of logic is reflected in my physical reality.
The address of any data, the address of its front area, is its address minus this one.
This is the relationship. So how do we express the relationship between logic and physics? It is quite simple. We will talk about the structure of Python later. After reading it, you should think about how to realize logical relationships. We can see the logical linear relationships.
1234567 This is its physical realization. How to express it? This is the order table we are going to talk about today. We will talk about the non-continuous storage space later. When you train a table, it is not continuous. How do you express the non-continuous space?
Or how do you express the linear relationship on the same logic? How is it realized? It's a little different from this one.
That's all for today. In the afternoon, we will do the experiment. Please refer to the basic code above. There is a merge button, delete button and insert button.
And this is the initialized version. You can take a look at this first. You can use this as the basis when you write in the afternoon. Then you can mark it.
I have a question. If we find a problem in the machine room in the afternoon, what should we do?