Dahua Data Structure Reading Notes Series (1) Data Structure Introduction

Chapter 1 Introduction to Data Structures

data structure

A collection of data elements that have one or more specific relationships to each other.

1.4 Basic Concepts and Terminology

1.4.1 Data

It is a symbol that describes objective things , ** is an object that can be manipulated in a computer, and a collection of symbols that can be recognized by the computer and input to the computer for processing. **Data includes not only numeric types such as integers and real types, but also non-numeric types such as characters and sounds, images, and videos.

1.4.2 Data elements

It is the basic unit that makes up data and has a certain meaning, and is usually treated as a whole in the computer. Also called a record. ( The data elements of people are people; the data elements of poultry are animals such as cattle, horses, sheep, chickens, pigs, dogs, etc. )

1.4.3 Data items

A data element can consist of several data items. A data item is the smallest unit of indivisible data . For example, a data element such as a person can include data items such as eyes, ears, mouth, nose, hands, and feet, as well as data items such as name, age, gender, birth address, contact number, etc. The specific data items depend on the You do the system to decide.

1.4.4 Data Objects

is a collection of data elements of the same nature and is a subset of data. What is the same nature? It means that the data elements have the same data and types of data items. For example, in the example just now, people have the same data items such as name, birthday, gender, etc.

1.4.5 Data Structure

** Structure, a simple understanding is the relationship**, such as molecular structure, that is, the arrangement between the atoms that make up the molecule. Strictly speaking, structure refers to the way in which the various components are matched and arranged with each other .

In the real world, different data elements are not independent, but there are specific relationships, which we call structures. What is that data structure?

Data structure: A collection of data elements that have one or more specific relationships with each other.

1.5 Logical structure and physical structure

According to the different viewpoints, we divide the data structure into logical structure and physical structure.

**Logical structure: refers to the relationship between data elements in a data object. **In fact, this is also the issue that we need to pay attention to the most in the future. The logical structure is divided into the following four types:

  1. Set structure: The data elements in the set structure have no other relationship except that they belong to the same set . Each data element is "equal", and their common attribute is "belonging to the same set". The set relationship in the data structure is similar to the set in mathematics (as shown in Figure 1-5-1).Enter image description
  2. Linear structure: There is a one-to -one relationship between data elements in a linear structure.Enter image description
  3. Tree structure: There is a one-to-many hierarchical relationship between the data elements in the tree structure.Enter image description
  4. Graph structure: The data elements of the graph structure are in a many-to-many relationship.Enter image description

When using a diagram to represent the logical structure of data, two points should be noted:

  1. Think of each data element as a node, represented by a circle.
  2. The logical relationship between elements is represented by the connection between the nodes. If the relationship is directional, it is represented by the connection with arrows.

Physical structure (storage structure): refers to the storage form of the logical structure of data in the computer . Divided into sequential storage and chain storage.

The storage structure of data should correctly reflect the logical relationship between data elements, which is the most critical. How to store the logical relationship between data elements is the focus and difficulty of realizing the physical structure.

1. Sequential storage structure

Sequential storage structure: It stores data elements in storage units with consecutive addresses, and the logical and physical relationships between the data are consistent. Enter image descriptionThis storage structure is actually very simple. To put it bluntly, it is queuing and occupying space. Everyone is arranged in order, everyone occupies a small space, and no one is allowed to join another team. When we learned computer languages ​​before, arrays were such sequential storage structures. When you tell the computer that you want to create an array with 9 integer data, you will find an empty space in the memory at the third level, multiply the size of the position occupied by an integer by 9, and open up a continuous space. So the first array data is placed in the first position, the second data is placed in the second, and so on.

2. Chained storage structure

If it were that simple and regular, everything would be fine. But in fact, there will always be people who will cut the line, some will have to go to the toilet, and some will give up the line. Therefore, new members will be added to this team, and old elements may also be removed, and the entire structure is constantly changing. Obviously, in the face of such a time-changing result, sequential storage is unscientific. then what should we do?

At present, places such as banks and hospitals have set up queuing systems, that is, when everyone goes there, they get a number first, wait for the number to be called, and then go to do business or see a doctor when they arrive. While waiting, you can sit, stand, or walk wherever you like, or even go out for a walk, as long as you come back in time. What you pay attention to is whether the previous number has been called, and when it is called, the next number will be your turn.

Chained storage structure: It stores data elements in any storage unit. This group of storage units can be continuous or discontinuous. Enter image description

Obviously, chained storage is much more flexible. It doesn't matter where the data exists, as long as there is a pointer that stores the corresponding address, it can be found.

A few years ago, there was a movie called "Infernal Affairs" in Hong Kong, and there was a TV series called "Infernal Affairs" in mainland China. They were very popular. I don't know if you have seen it. Intelligence gathering work. In order not to reveal the true identity of each lurking person, it is often a one-line contact, only the upline knows who the downline is, and it is communicated through a secret code. Under normal circumstances, information can be uploaded and distributed smoothly, but if a comrade at a node in a chain sacrifices, it will be troublesome, because other people do not know who is online or offline, and the consequences are very serious.

For example, in "Infernal Affairs", Liang Chaowei is the police's undercover agent in the underworld, and has always been in contact with the police officer played by Huang Qiusheng, but when Huang was killed, Liang could not prove that he was a policeman. So at the end of the film, when Tony Leung pointed a gun at Andy Lau's head and said, "I'm sorry, I'm a policeman." Andy Lau immediately asked, "Who knows?" Yeah, who knows who you are when no one can prove your identity? Seeing this in the film makes people feel a little sad. This is actually a real-world example of a chained relationship.

The logical structure is problem-oriented, while the physical structure is computer-oriented, and its basic goal is to store data and its logical relationship in the computer's memory.

1.6 Abstract Data Types

1.6.1 Data Types

Data type: refers to a set of values ​​of the same nature and a general term for some operations defined on this set.

Data types are divided by value.

Why did those who designed computer languages ​​think about data types?

For example, everyone needs a house, and they all hope that the bigger the house, the better. Obviously, without money, there is little point in thinking about a house. As a result, various types of commercial housing have appeared, including villas, split-level, and single rooms; more than 100 square meters, some tens of square meters, and even capsule apartments in Beijing - only two square meters. Room. . . . This meets the needs of different people.

Similarly, in a computer, the memory is not infinite. If you want to calculate the addition, subtraction, multiplication and division of an integer number such as 1+1=2, 3+5=8, it is obviously not necessary to open up a large number of suitable decimal settings. Memory space for string operations. Therefore, computer researchers considered that data should be classified and divided into various data types.

In the C language, data types can be divided into two categories according to the different values:

  1. Atomic types: basic types that cannot be decomposed, including integers, reals, characters, etc.
  2. Structural type: It is composed of several types and can be decomposed again. For example, an integer array is composed of several integer data.

For example, in the C language, variables declare int a, b, which means that the value range of in cannot be exceeded when assigning values ​​to variables a and b, and the operation between variables a and b can only be allowed by the int type operation.

Abstraction refers to extracting the universal essence of things.

1.6.2 Abstract data types

Abstract Data Type (ADT): refers to a mathematical model and a set of operations defined on the schema. Abstract data type decomposes real-life problems into multiple small-scale and easy-to-handle problems, and then establishes a data model that can be processed by a computer, and treats the implementation details of each functional module as an independent unit, so that the specific implementation can be realized. The process is hidden.

Some related concepts of data structure, as shown in 1-7-1.Enter image description

Data structure, discussed from different angles, will have different classifications, as shown in Figure 1-7-2. Enter image description]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326079237&siteId=291194637