I’m sorry. I really can’t learn

Want to speak of my blood and tear history again 😂

When I first went to college to study data structures, I learned this textbook:

Insert a picture description here


There must be a lot of friends who learned this book.
Finished, the last article, we all know my data structure 60 minutes, can’t mix 🤣), recently, a lot of friends know that I want to serialize the data structure and algorithm series, they ran to me private letter “congratulations brother ah, this data structure really made my head big, what is it 😂”

I didn’t know what data structures were for four years in college. 😂 (Am I really that stupid? I am embarrassed.

On college, always feel the thing is too abstract, learn to don’t understand, more and learn more to keep up with, not half left behind, is basically to give up the kind of treatment, then know, are pseudo code written in this book, I say how I see it one leng one leng, in this way, the university four years, I don’t understand the data structure is a what?

Then, those who understand, successfully participate in the school recruitment, get satisfied offer, enter the factory, marry Bai Fumei…… And I?

Interviewer: “Do you know anything about data structures?”

Me: “What? You say what? What is a data structure?”

And THEN I graduated…

To the heart, old man? If you’re in college and you don’t know what a data structure is, or if you graduated and still don’t know what a data structure is, you’re embarrassed to say it. Finally… Know… What is a data structure? “(drawl…)

What the hell are you doing with data structures?

When I first came into contact with “data structure”, I thought it was a little abstract, but I thought it was not that difficult to understand.

A data structure is a collection of data elements that have one or more specific relationships with each other. In other words, a data structure is a collection of data elements with “structure”, and “structure” is the relationship between data elements.

I don’t know how you felt when you saw this definition, but I was a little confused at the time, but now that I look at it, I think it’s pretty good.

Talk about how data is stored on a computer

To better understand the data structure, you need to understand the data stored in the computer, let’s take a simple example, for example, we want to store a number, such as 1024, how to store, we know that the general code (Java)) :

int a = 1024;

Copy the code

Also is to define an integer, we finished it, is to save on our computer, is actually stored in the hard drive in a computer, the program to be loaded into memory can only be read by the CPU running, so, the 1024 actually loaded into memory, to be sure, here in the 1024’s us to write a program that an integer variables, And you also have to understand that when we say it’s in memory, it’s because we’re going to run this program.

Once the program is run, the data contained in the program will be loaded into memory, like 1024, which will also be saved into memory. Here’s another thing to remember:

The data in the computer is kept in binary form

If you want to store an integer in memory, you need to take up some space in memory.

Insert a picture description here


So, you see, this 1024 is stored in memory, and of course, you have to understand that this 1024 is actually converted to binary, but I’m just doing this for illustration purposes.

For those who don’t know, check out my previous posts:

How does a program work in a computer? Super dry!!

As a programmer, you must know this core knowledge of CPU!

As a programmer, this is the core knowledge of memory that you must understand!

As a programmer, you have to know these things about memory and disk.

Let’s talk about data structures

Now that we know how data is stored in a computer, we can look at data structure again. We have seen the definition before, data structure from the name, is data and structure, structure can be understood as a relationship, is the relationship between data…

So you’re still a little confused, but you can think of it this way: first of all, you know, data structure, it’s a discipline, what does it do? In plain English, how should research data be stored?

You may say, also study how to store, don’t store is the same 😂, although this problem is a little chun, but MAO, is really a let small white confused problems, data storage, of course, is not the same, for example, if we want to store a five integers {1, 2, 3, 4, 5}, zha yao a stored in your memory, is likely to be like this:

Insert a picture description here


What’s the point? It’s these five numbers, they’re all in a row in memory, right next to each other, but it could be something like this:

Insert a picture description here


Is no order in the memory, the storage of scattered, so you see, for data, can according to the different ways to store, is a continuous next to the store for you, or store where it is stored, ah, you may ask, what how to do this, well, it depends on the data itself, and other related requirements, see you how to use this data to prepare, Then figure out how to store it properly.

So, the data structure is to manage the storage of data in memory, for example, some data to be stored in memory, that depends on the data structure, the data structure let you store what you want to store, let you store continuously, you can’t scatter flowers everywhere.

In addition, you also need to know, here is a general data structure, is like a fruit, it is bananas, apples and oranges data structure is the same, it is a general, array, linked lists, stacks and queues, and so on, these all belong to the data structure, like, bananas, apples and oranges are all fruit, this good understanding!

W then, these data structures, each have their own characteristics, these characteristics are rules if the data structure to store data chose it, will be stored in the memory, according to the requirements of it such as you choose the array, so you these data in memory is stored in a row, one next to one, can not disorderly, If you choose a linked list, you don’t have to store it consecutively in memory. You can store it whenever you have space.

So you see, different data structures have their specific uses…

Here, you understand the same time as the data structure is what, that is to say, w data structure is how the data storage, and then the data structure is a term, is like a fruit, it has an array, linked list, stack and queue these data structures, like fruit has a banana apples and oranges, MAO, actually you can imagine the data structure into a container, Containers are for storing data, and these containers are all different shapes. You choose different containers (data structures), which means the data is stored differently.

So much for that, is that it? Of course not, and the poor is far away 😂, we said above the storage of five data, can imagine, there is no connection between the five data, at most is continuous storage, one next to one, so there is a one-to-one relationship, that is, with the queue like, you have me in front of me, I have you behind.

But there is another kind of data, for example, we want to store the data information in a family tree, like this:

Insert a picture description here


If so, how do you store it in memory? These are not just cold numbers that you can store in memory, but when you store family tree data, it’s not just data, it’s the relationship between data.

After the introduction of the above, I think you must know a little about that choose a data structure to store it bai, said good, we can discover genealogy data analysis, the data have a one-to-many relationship, such as grandpa had three sons, uncle has two children, like this kind of data, data structure has a structure called tree is can save the data.

All of these one-to-one, one-to-many things that we’re talking about are relationships between data, really structures in data structures, and you might ask, is there a many-to-many relationship? The answer is certainly there, so how to store this? Well, there’s another thing called graphs in data structures, which are for many-to-many data.

So what is a data structure? It’s about how the data is stored.

What are the data structures?

So, you’re wondering, well, what are the data structures? Data structures generally fall into the following three categories:

  • Linear tables, that is, arrays, linked lists, stacks, and queues;
  • Tree structure, including ordinary tree, binary tree, red black tree and so on;
  • Graph storage structure, this stuff is a bit difficult 😂;

Let me give you a brief introduction to these data structures.

The linear table

Linear list is also a general term, it contains sequential list and linked list, as well as stacks and queues, linear list is actually easy to understand, the word linear is very clear, indicating that the data is one-to-one relationship, the form of storage is also arranged in order.

Arrays are very clear, they need contiguous memory space, and they need to store data one by one. That’s ok, but linked lists don’t have to be contiguous. Yes, that’s true, but the actual storage of a linked list in order to maintain this order, it introduces Pointers, like this:

Insert a picture description here


The array looks like this:

Insert a picture description here

So, a linked list is also a linear list, it’s also a sequential list, that’s something to understand, and you might hear the idea of a sequential list here, if you’re a beginner, you can equate a sequential list with an array, so listen to me.

Then there are stacks and queues. These are also linear tables, but they are special linear tables, and they have specific requirements for the entry and exit of data. I won’t go into details here.

Come on! Give you a different array in-depth explanation!

Linked lists don’t? Look at this and you’ll get it!

Easy to learn stack and queue (with sequential stack implementation ideas analysis)

Come on! Hash table complete!

Come on! The tree of data structures!

Read this article on binary tree introduction, except can’t write code everything!!

Java code combat: through handwriting a single linked list, tell you to learn programming methods and shortcuts!

Tree structure

In fact, I think it gets harder as you go down, like a tree is a little bit harder than a linear table, but again, a linear table is one-to-one, whereas a tree is one-to-many, so it gets a little bit more complicated.

Speaking of tree ah, what binary tree, red black tree, B+ tree and so on, these are key knowledge, and I think it is a little difficult to learn, to tell the truth, data structure and algorithm is really difficult, but don’t worry, with qingge I, don’t fall behind, let’s take it together this year.

So tree structure, as we said above, is to store data that has a one-to-many relationship, such as family tree, organizational structure, etc. Anyway, there is a one-to-many relationship between data, so you can use a tree structure to store data.

The graph structure

Naturally, graph structures store data with many-to-many relationships, which are much more complex and challenging to learn. It looks like this:

Insert a picture description here

## Logical and physical structure of data

After our above introduction, I believe you have got a lot of dry goods, then we will continue to do some hard goods for you, that is about the logical structure and physical structure of data.

Now that we know what data structures are and what they are, we have also done a simple analysis above, talking about various data structures, so have you ever thought about how we should choose these data structures to store data? As mentioned above, it depends on the data.

In fact, what kind of data structure to choose for data storage, it depends on the logical structure and physical structure of the data, again, this understanding is very important, I say every word do not miss oh 😁

What is a logical structure?

I don’t know if you’ve thought about this before, but what is the logical structure of data? You may be a little confused, but it’s really easy to say:

The logical structure of data refers to the relationship between data

I think you can see right away that the relationships here are one-to-one, one-to-many and many-to-many. Yes, that’s it. The logical structure of the data here refers to those relationships, just like the graph I gave you above.

Insert a picture description here


For example, the uncle, second uncle and father in the figure above are all brothers. The grandfather has three sons and the uncle has two children, which is a one-to-many relationship. If we want to store such data, we should not only store basic data information, but also store the relationship between them.

This relationship is the logical structure of the data.

To sum up, there are three logical structures between data, namely:

  1. One-to-one: You’re next to me, I’m next to you
  2. One to many: just like the family tree we drew above
  3. Much to much: this for instance map, perhaps some of the way that reach in all directions, can understand my meaning 😂

In fact, given some data, you can almost always figure out what the relationship is, that is, the logical structure of the data is not hard to identify.

Here, do you find that the data of these three logical structures can be stored by the three types of data structures we introduced above, which are the following three types:

  1. Linear table: one to one
  2. Tree structure: one to many
  3. Structure: many-to-many

Have you found that all changes are inseparable from it, but after we understand the logical structure of the knowledge point, you will feel that this piece is only more complete.

What is the physical structure?

Important knowledge points

We know on what is logical structure, then we can analyze data logical structure to look at the data between the choose which kind of data structure to store, it seems everything is all right, nothing happened, but, but it is not, in fact, speaking of which, involving the knowledge and many, I only give you to the point, take out alone after detailed chatter.

Remember this very important sentence:

Data structures can be stored in only two ways: arrays (sequential storage) and linked lists (chained storage).

What do you mean? Actually, arrays and linked lists are data structures within data structures, and all other data structures can be implemented using arrays and linked lists, if you take stacks, you can implement stacks using arrays, and that’s called a sequential stack, or you can implement stacks using linked lists and that’s called a linked stack.

So, each data structure can be divided into sequential storage (arrays) and chained storage (linked lists)

If you want to use a data structure like a queue to store data, there are actually sequential queue implementations and chained queue implementations, depending on how you actually store the data in memory, so you can see that arrays and linked lists are the building blocks of a data structure.

So, the new question is, since there can be sequential storage and chained storage for every data structure, how can I determine whether I want sequential storage or chained storage even if I choose a data structure based on the logical structure of the data?

PS: The above question is very important, you must understand, do not understand the above paragraphs read several times, must understand, must understand!

The key to this question is to analyze the physical structure of the data, right?

Now look at the physical structure

What is the physical structure of the data? Again, it’s confusing if you haven’t thought about it before, but it’s pretty simple:

The physical structure of the data refers to whether the data is stored in memory continuously, that is, in a lump, or scattered.

That is to say, for some of the data, we analyzed the logical structure between them, and know with what kind of relationship between data, this we can determine the data structure, but we need to analyze the physical structure of the data, however, have you found the problem, how do we know the physical structure of the data is what?

Here are two points to look at to determine the physical structure of the data:

  1. The spatial state of memory
  2. Use of data

What do you mean? We take the state of the memory space, first of all, we need to know, continuous storage requires continuous memory space, we need to store the size of 10 MB data, for example, it is required also should have a block of memory space is 10 m, but if not it must be stored in a row, it can only be stored separately, otherwise the storage is not successful.

Look at the purpose of the data, for a continuous and dispersed storage main difference is that will affect the operation of the subsequent data, take continuous storage, it to data traversal efficiency is higher, therefore, if you store the data in the subsequent operations traverse are frequent, it must give preference to storage in a row, of course, If you’re going to be doing a lot of updates later on in your data operation, it’s a good idea to decentralize storage because it’s more efficient.

Therefore, we determine whether the physical structure of data is stored continuously or dispersed according to the spatial state of memory and the use of data, and then select the corresponding storage mode, that is:

  1. Choose sequential storage if the physical structure is continuous storage
  2. Choose chain storage if the physical structure is distributed storage

There may be a little bit around, more understanding understanding!

Thank you for reading

When I was in college, I chose to study Java by myself. When I worked, I found that I had suffered from a poor computer foundation and a poor academic background, which was impossible and could only be made up for the day after tomorrow. Therefore, IN addition to coding, I started my own counter-attack, constantly learning Java core knowledge and in-depth study of basic computer knowledge. All the experience of all written, organized into a catalog of PDF, continue to be original, PDF in the public account continues to update, if you are not willing to mediocrity, then with me in coding, continue to grow!

In fact, there are not only technologies, but also things beyond those technologies, such as how to be a delicate programmer, rather than “diaosi”, == programmer itself is a noble existence, isn’t it? = =

Very welcome you to join, in the future, coding, you have me, together to do a person is not stupid, a lot of money, live a long time happy programmer!

Reply keyword “PDF”, obtain technical article collection, has been sorted out, with a directory, welcome to exchange technology together!

In addition, reply to “qingge”, see the surprise package prepared by qingge for you, only for the first time to pay attention to you!

Any questions, you can add Qingge wechat: H653836923, in addition, I have an exchange group, I will not regularly share learning resources in the group, not regular welfare, interested in can say I invite you!

By the way, if you are a Java white, you can also add my wechat, I believe you must meet a lot of problems in the process of learning, maybe I can help you, after all, I am also experienced! = =

Insert a picture description here

Thank you for reading 🥰