Learn data structure together 1

You, who saw this post, have already started to study deeper computer knowledge.
The lower the level of knowledge, the more difficult it is, but it’s okay, take your time and
learn more, and you will make more progress. You should continue to work hard today!

some basic concepts

Before learning the data structure, some basic concepts still need to be popularized:

1. What is data

Data is actually all kinds of information, such as numbers, symbols, pictures, etc., thisThe range of data is actually bigger than you think, any content that can be input into a computer and can be recognized and processed by the computer is data.
So the various operations we do are actually carried out around the data, and you can also understand the data as the "raw material" for various processing of computer programs.

2. What is a data element

The concept of data is actually very broad, so in order to refine it, there isdata elementthe concept. A data element is the basic unit of data. For example, when we are doing company business, an employee's information can be regarded as a data element. This data element contains multipledata item, such as: employee's name, gender, position, department, etc.
Is it okay to see here? Then let's continue~

3. Data objects

A data object refers to a collection of data elements with the same properties. This concept is a bit abstract. Take a chestnut:
what are the integers? An integer data object can be represented as such a set: N = {0, ±1, ±2...}

4. Data structure

In fact, no matter what problem we have to deal with, data elements do not exist independently, and there is a relationship between data and data. We refer to the relationship between data elements as structure.
Data structure includes three aspects: logical structure, storage structure and data operation.
The design of an algorithm depends on the logical structure it chooses, and the realization of the algorithm depends on the storage structure it adopts. So logical structure and storage structure are two inseparable aspects.
This passage may be a bit difficult for you who are just getting started, but it doesn’t matter. I will explain it further in the future. This is just a general overview!

Three Elements of Data Structure

Next, let's describe in detail the three elements of the data structure:

1. Logical structure of data

Logical structure means that we organize and describe data through logical relationships. This has nothing to do with data storage and is independent of the computer.
The logical structure of data can analyze linear structure and nonlinear structure. Linear tables are typical linear structures, while collections, trees, graphs, etc. are typical nonlinear structures.
Let me explain again to assist understanding:
set: refers to the data elements in the structure, there is no other relationship except belonging to the same set, for example, a class can accommodate multiple different students Linear
insert image description here
structure: refers to the structure There is only a one-to-one relationship between the data elements in the tree structure, for example, a person has only one unique ID number
insert image description here
tree structure: refers to the one-to-many relationship between the data elements in the structure, for example, A grandfather has multiple grandchildren.
insert image description here
Graph structure or network structure: refers to the many-to-many relationship between data elements in the structure. For example, a class has multiple teachers teaching, and a teacher can also bring multiple class logic
insert image description here
. The structural classification is shown in the figure:
Please add a picture description

2. Data storage structure

The storage structure refers to how data is represented in the computer, also known as the physical structure. It includes the representation of data elements and the representation of relationships.
The storage structure of data is the logical structure of these data using computer language.
The main data storage structures are: sequential storage, chain storage, index storage and hash storage.
Next, explain the characteristics of different storage structures:

1. Sequential storage

Store logically adjacent elements in physically adjacent storage units, and the relationship between elements is reflected by the adjacency of the storage units.
Advantages: Random access can be achieved, and each element occupies the least storage space.
Disadvantage: Only a whole block of adjacent storage units can be used, so more external fragments may be generated.
For example: the structure of an array If the concept of an array is not clear, you can refer to this detailed note

2. Chain storage

It is not required that logically adjacent elements are also adjacent in physical location, and the logical relationship between elements is represented by pointers that are only storage addresses of elements.
Advantages: There will be no fragmentation, and all storage units can be fully utilized.
Disadvantages: Each element occupies additional storage space due to storing pointers, and only sequential access can be achieved.
For example: LinkedLinst storage structure LinkedList related content can refer to this note

3. Index storage

While storing element information, an additional index table is also established. Each item in the index table is called an index item. The general form of the index item is (keyword, address) Advantages: Fast query speed Disadvantages: The index table needs to occupy
additional
space In addition, modifying the data also requires modifying the index table at the same time, which will take a lot of time.
For example: we wrote a paper, in order to facilitate the search, we can generate a corresponding directory, and the query speed is fast, but if the paper is modified, it will also Need to modify the directory synchronously

4. Hash storage

Calculate the storage address of the element directly according to the keyword of the element, also known as hash (Hash) storage.
Advantages: the operations of querying, adding, and deleting elements are very fast.
Disadvantages: If the hash function involved is not good, there may be conflicts in element storage units, and resolving conflicts will increase the overhead of time and space.
For example: the stored procedure HashMap of HashMap For related content, please refer to this note

3. Operation of data

Operations performed on data include the definition and implementation of operations.
The definition of operation is aimed at the logical structure, pointing out the function of the operation; the
realization of the operation is aimed at the storage structure, pointing out the specific operation steps of the operation.
This will be explained further later.

Guess you like

Origin blog.csdn.net/weixin_43884234/article/details/122957335