Algorithm Notes (2) Data Structure

1.1 Data structure:

A data structure is a way of storing and organizing data in a computer, and it also generally refers to a collection of data that has one or more specific relationships with each other.

1.1.1 What is a data structure

Until now, there is no unified definition of data structure in the field of computer technology. Here is a partial explanation of the quote:

noun definition

  • A data structure refers to a collection of data elements . Record as:
Data_Structure=(D,R)
where D is the set and R is the finite set . [2]  

Other definitions

In his book Data Structures, Algorithms and Applications, Sartaj Sahni states: "A data structure is a data object and the various connections that exist between instances and the data elements that make up the instance . These connections can be defined by related functions ." He defines a data object as "a data object is a collection of instances or values".
The definition of Clifford A. Shaffer in the book " Data Structure and Algorithm Analysis " is: "A data structure is the physical realization of ADT ( Abstract Data Type)."
In the book "Data Structure and Programming", Robert L. Kruse divides the design process of a data structure into abstraction layer, data structure layer and implementation layer. Among them, the abstraction layer refers to the abstract data type layer, which discusses the logical structure of data and its operation , and the data structure layer and the implementation layer discuss the representation of a data structure, the storage details in the computer, and the realization of the operation.
The data structure specifically refers to the relationship , including three components , the logical structure of the data , the storage structure of the data and the data operation structure.
 

Although there is no single definition, these definitions all have similar meanings.

Data structures are the foundation of all algorithms.

Data structures are the foundation of programming languages.

2.1.1 Basic Concepts of Data Structures

  Data: Data is the carrier of information and the raw material processed by computer programs. Integers, characters, strings, entity classes, images, sounds, etc. can all be thought of as data structures.

  Data Element: Data element is the basic unit of data, also known as element, node, vertex, record, etc.

  Data structure: Data structure refers to the relationship between data, that is, the organization of data.

2.1.2 Contents of the data structure

Generally speaking, the data structure includes the logical structure of the data, the storage structure of the data and the operation of the data.

The logical structure of the data:

The logical relationship between data elements. The logical structure of data is to describe the data from the logical relationship, which has nothing to do with how the data is stored in the computer. It is an abstract concept independent of the computer. From the perspective of mathematical analysis, the logical structure of data can be regarded as a mathematical model abstracted from specific problems.

Data storage structure:

The representation of data elements and their logical relationships in computer memory. The storage structure of the data depends on the computer language, and is the realization of the logic mechanism in the computer language. Generally, the storage structure is only discussed at the level of high-level language, and the storage structure of low-level machine language is specific.

Data manipulation:

Ability to operate on data that is false. The basis of data operations is the logical structure of data. Each logical structure can be summarized as a set of operations. Common AND operations include retrieval, insertion, deletion, update, and sorting.

The data structure is an organic whole. The same logical structure can have different storage structures, and the same logical structure can also have different sets of data operations.

Any change in the logical structure of the data, the storage structure of the data and the operation of the data will lead to a new data structure.

2.1.3 Classification of data structures

According to the logical structure of data, it can be simply divided into linear structure and nonlinear structure.

Linear structure:

Linear structure means that each node in the table has a linear relationship. Such as linear lists, stacks, queues and strings. Described in the language of data structures, a linear structure should include:

A linear structure is a nonempty set;

A linear structure has one and only one start node and one end node;

In a linear structure, there is only one immediate predecessor node and one immediate successor node on the left and right of all nodes.

Nonlinear structure:

Each node in the table has multiple correspondences, such as arrays, generalized tables, tree structures, and graph structures. Nonlinear structures should include:

A nonlinear structure is a non-empty set;

A node of a nonlinear structure may have multiple immediate predecessors and immediate successors.

How the data structure is stored:

Sequential storage method:

The sequential storage method is to store data one by one in a continuous storage area. The sequential storage method stores logically adjacent nodes in physically adjacent storage units, and the logical relationship of nodes is reflected by the adjacency relationship of the storage units. The sequential storage method is also called the sequential storage structure, which is generally described by an array or an array of structures.

The current storage method is mainly used for data storage of the current logical structure, and is not suitable for nonlinear structures such as graph composite numbers.

Link storage method:

The link storage method does not require logically adjacent nodes to be physically adjacent. The logical relationship between nodes is identified by an additional reference field. The reference field of one node often points to the storage location of the next node.

The linked storage method also becomes a linked storage structure. Generally, a reference type is added to the original data item to indicate the positional relationship between nodes.

Index storage method:

It is a storage method that uses an additional index table to store node information. The index table consists of several index entries.

The index storage method can also be divided into dense index and sparse index.

Hash storage method:

The hash storage method is a storage method in which the storage address of the node is directly calculated according to the key of the node. Which storage method to use is often determined according to the specific data structure.

2.1.4 Data Types

According to whether the value of the data type can be decomposed, data types can be divided into basic data types and aggregate data types.

Basic data types: generally some data types defined by the programming language itself.

Aggregate data type: Its value can be further decomposed into several components, which are generally user-defined data types.

Abstract Data Type (ADT):

Refers to the organization of data and its associated operations. ADT can be seen as the logical structure of data and the operations defined on the logical structure.

Abstract data types generally have two important characteristics:

Data abstraction: When using abstract data types, it emphasizes the essential characteristics of the entity, the functions that can be completed, and the interface with external users.

Data encapsulation: It is used to separate the external features of the corpse from its internal implementation details, and hide its internal implementation details from external users.

2.1.4 Commonly used data structures

array:

An array is an aggregate data type, a collection that organizes several variables of the same type in an orderly manner.

stack:

A stack is a special linear table that can only perform insertion and deletion of data nodes at a fixed end of a table. The stack stores data on a last-in, first-out basis. The stack with no data is called an empty stack.

queue:

A queue is similar to a stack, and it is also a special kind of linear list. But the queue only allows inserts on one side of the table and deletes on the other. The end that performs the insertion operation is called the tail of the queue, and the end that performs the deletion operation is called the head of the queue.

Linked list:

A linked list is a tree structure in which data elements are stored according to a chained storage structure. This data structure is physically discontinuous. The linked list is composed of a series of data nodes, each data node includes two parts: the data field and the reference field.

Tree:

A tree is a typical nonlinear structure, which is a finite set K including n nodes. There is only one root node in the tree, this node has no predecessor node, other nodes have and only one predecessor node, and there can be m successor nodes.

picture:

A graph is a nonlinear structure. Data nodes are generally called vertices, and edges are ordered pairs of nodes.

heap:

The heap is a special tree-shaped data structure, and the pairs generally discussed are binary heaps. The characteristic of the heap is that the value of the root node is the smallest or largest among all nodes, and the two subtrees of the root node are also a heap structure.

Hash table:

The hash table is derived from the hash function. The idea is that if there is a record with the same key and T in the structure, then the record must be found in the storage location of F(T), so that it can be obtained directly without comparison. Checked records.

2.2 Linear table

A linear table is a finite sequence of n elements.

The number of data elements is n, the data length is n, and n=0 is called an empty table.

For a non-empty linear table, its logical structure characteristics are as follows,

There is only one start node a1, no direct predecessor node, and there is only one direct successor node a2;

There is one and only one terminal node an, no direct successor node, and one and only one direct predecessor node a(n-1);

All other internal nodes have one and only one immediate predecessor node and one immediate successor node.

For the same linear table, each data element ai must have the same data type, that is, uniform == each data element in the same linear table has the same type, and each data element has the same length.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326855474&siteId=291194637