Data structure (c)

Source: Internet
Author: User

Data structure (c)

In the past, it was difficult and abstract to get started with the data structure. In this review, we analyzed and reviewed the data structure in detail and split the data structure. After a few days of study, I began to have a preliminary understanding of the data structure.


What is the use of learning data structures?

After you have mastered the data structure, if you have designed a good data structure, you can bring higher operation and storage efficiency to your program, data Structures usually involve retrieval methods, indexing techniques, and some algorithms. Of course, small systems do not involve data structures, but if we design a large system, we need to design a good data structure for the system. Learning the data structure well is the basis of becoming a master.

Data is the representation of objective things. In a computer, it refers to a set of data that can be input to a computer and processed by the computer. data elements are the basic unit of exponential data, generally, it is considered and processed as a whole in a computer. A data item is the smallest unit of data that cannot be separated (the data element consists of multiple data items .). A Data Structure is a  elements that exist between each other.

The data structure is divided:

1. Data Logical Structure: that is, the relationship between data, divided into four categories: linear structure, tree structure, graph mechanism, set.

2. Data Storage Structure: it is also called the house structure. It has a sequential storage structure and a chain storage structure.

3. Data Operations

The logical structure of data is closely related to the storage constructor. The design of any algorithm depends on the selected data logical structure, and the implementation of the algorithm depends on the storage structure used.

1. linear structure: a linear table is the simplest and most commonly used data structure. It is a finite sequence consisting of n nodes of the same data type.

1. The most important property of a linear table is that the knot and relative position in a linear table are determined. Multiple storage methods are available to store linear tables in computers. The most common storage methods are sequential storage and chained storage.

(1) chain storage of linear tables

Chained Storage refers to the use of nodes to store data elements. The space of nodes can be continuous or discontinuous. Therefore, the logical relationship between elements must be stored while storing data elements, the Node space is requested only when necessary and does not need to be allocated in advance.

(2) sequential storage of linear tables

A group of continuous storage units are used to store data elements in a linear table at a time, so that two elements adjacent to the logical relationship are physically adjacent. In this storage mode, the logical relationship does not need to occupy additional storage space. Some elements in the table can be randomly accessed. The disadvantage is that the insert and delete operations need to move elements.

Comparison of sequence and chain storage:

(1) In terms of time, sequential storage has a great advantage in searching for data by location or in terms of the frontend and successor of searching elements. when inserting or deleting data, chain storage has a great advantage. This is because you only need to modify the pointer in the linked list to perform these operations. When you insert or delete a sequence table, you need to move the data in the table.

(2) From the Perspective of space, the storage space of the sequence table is statically allocated. In terms of program execution, the storage mode of the sequence table must be specified, dynamic table storage space is dynamically allocated, and will not overflow as long as the storage space is idle.

2. linear structures are stored in special linear tables, such as linear tables, stacks, queues, strings, and arrays,

(1) A linear table is the simplest and most commonly used data structure. In short, a linear table is a finite sequence of n elements, which is characteristic of being out of the first element, each element in the SET has a direct precursor. Except the last element, each element in the SET has only one direct successor.

(2). Stack: It is a linear table that can only be inserted and deleted at one end of the table.
 It stores data according to the principle of last-in, first-out. The first-entered data is pushed into the bottom of the stack. The last data is on the top of the stack. When the data needs to be read, the data is popped from the top of the stack (the last data is read first).
The stack is a special linear table that allows insert and delete operations on the same end. The end that allows insertion and deletion is called the top of the stack, and the other end is the bottom of the stack; the bottom of the stack is fixed, while the top of the stack is floating; when the number of elements in the stack is zero, it is called an empty stack.
Insertion is generally called PUSH, and deletion is called POP. The stack is also referred to as the last out table.
(3). The queue is a special linear table, which only allows delete operations at the front end of the table and insert operations at the rear end of the table. The end that performs the insert operation is called the tail of the queue, and the end that performs the delete operation is called the head of the queue. When there are no elements in the queue, it is called an empty queue. In a data structure such as a queue, the element that is inserted first will be the element that is deleted first; otherwise, the element that was inserted last will be the element that was deleted last, so the queue is also called "first in first out" (FIFO—first in first) out) linear table.

Second, the tree structure: the tree structure is an important type of nonlinear data structure. Intuitively, the tree is a hierarchical structure defined by the branch relationship, and the tree is a finite set of n nodes, n is 0 Time is empty tree. The characteristics of the tree structure are: each node can have more than one direct successor, and all nodes except the root node have only one direct precursor. The following specifically gives the definition of the tree and the data structure of the tree.

1. Binary tree, a binary tree is a connected acyclic graph, and the degree of each vertex is not greater than 2. A rooted binary tree must satisfy the degree of the root node is not greater than 2. With the root node, each vertex defines a unique parent node, and a maximum of 2 child nodes

(1) Complete binary tree-If the height of the binary tree is h, the number of nodes in each layer (1 ~ h-1) reaches the maximum number except the h layer, and there are leaf nodes in the h layer, which is Completely binary tree.

(2), full binary tree-every node except the leaf node has left and right cotyledons and the leaf node is at the bottom of the binary tree.

Binary tree traversal: Traversal is a basic operation of the tree. The so-called traversal of the binary tree is to walk through all the nodes of the binary tree according to certain rules and order, so that each node is visited once, and only once . Because the binary tree is a non-linear structure, the tree traversal essentially converts each node of the binary tree into a linear sequence to represent. It is divided into pre-order traversal, middle-order traversal and subsequent traversal.

2. Huffman tree (optimal binary tree): given n weights as n leaf nodes, construct a binary tree. If the length of the weighted path reaches the minimum, this binary tree is called the optimal binary tree, also known as Ha Huffman tree (Huffman tree).

3. Clue binary tree: n node binary list contains n + 1 null pointer fields. The null pointer field in the binary linked list is used to store pointers to the predecessor and successor nodes of the node in a certain traversal order (such additional pointers are called "clues"). This kind of binary list with clues is called a thread list, and the corresponding binary tree is called a threaded binary tree (ThreadedBinaryTree). According to the different nature of clues, the clue binary tree can be divided into three types: pre-order clue binary tree, mid-order clue binary tree and post-order clue binary tree.

Note: The clue linked list solves the problem of finding the left and right children of the binary linked list, and the problem that the predecessor and successor of the node cannot be directly found in a certain traversal sequence.

4. Balanced Binary Tree (Balanced Binary Tree) is also called AVL tree (different from AVL algorithm, and has the following properties: it is an empty tree or the absolute value of the height difference between its left and right subtrees does not exceed 1, and Both left and right subtrees are a balanced binary tree. Construction and adjustment methods

       5. Complete binary tree: Definition of a complete binary tree: a binary tree with a depth of k and n nodes if and only if each of its nodes corresponds to a node numbered from 1 to n in a full binary tree with a depth of k Is called a complete binary tree.
Characteristics: The leaf node can only appear on the two layers with the highest level; for any node, if the maximum level of the descendants of the right branch is l, then the maximum level of the descendants of the left branch must be l or l + 1

       6. Full binary tree: Full binary tree: A binary tree with a depth of k and a power of 2 (k)-1 node
Features: The number of nodes on each layer is the maximum number of nodes, and the full binary tree is definitely a complete binary tree
Complete binary tree is not necessarily full binary tree

Third, the graph is composed of a finite set V of nodes and a set E of edges. Among them, in order to distinguish it from the tree structure, nodes are often called vertices in the graph structure, and edges are ordered pairs of vertices. If there is an edge between two vertices, it means that the two vertices are adjacent relationship.

1. The most commonly used graph structures are adjacency matrix and adjacency list.

2. The traversal of the graph includes: depth-first traversal and breadth-first traversal.

Depth-first is similar to the preorder traversal of the tree. For undirected graphs, if it is connected, then traverse all vertices by depth-first traversal, and get a traversal sequence of all vertices. The graph is disconnected.

Breadth-first traversal: refers to the first vertex v, and then visit all the unvisited vertices adjacent to the vertex v, and so on, until all vertices of the graph have been visited once.

3. Minimum spanning tree: a spanning tree with a connected graph of n vertices has n vertices and n-1 edges. For a weighted graph in a spanning tree, the sum of the weights of the edges is called The cost of this tree, the spanning tree with the lowest cost, is the minimum cost tree, referred to as the minimum spanning tree.

4. Shortest path: The shortest path problem with weighted graph is to find the shortest path between two vertices, where the path length is not the sum of the number of edges on the value path but the sum of the weights on the path The specific meaning depends on the meaning represented by the weight on the edge.

5. Topological sorting: Topological sorting of a directed acyclic graph (DAG for short) is to arrange all vertices in G into a linear sequence so that any pair of vertices u and v in the graph, if <u , V> ∈ E (G), then u appears before v in the linear sequence.

(1) Select a vertex without a precursor (incoming degree is zero) in the directed graph and output it.

(2), delete the vertex and the arc it emits (so you can get other vertices with a degree of 0)

For example: in real life, there will be many application examples, such as school curriculum layout, you must complete some basic courses before you can continue to take professional courses. Or in some large-scale projects, some projects have a sequential order, so that topological sorting will be used.

6. Critical path: Critical path is a term for schedule control in project management. In project management, critical path refers to the sequence of elements of network terminal elements, which has the longest total duration and determines the shortest completion of the entire project time.

 (1) The critical path is the longest path in the project network diagram, which determines the total time of the project;
      (2) The project manager must focus on those tasks with higher priority to ensure that they are completed on time. Any delay in activities on the critical path will cause the entire project to be delayed;
      (3) Give time to critical paths and resources to non-critical paths;
      (4) Adjust progress and balance resources.

What is the data structure
What is data structure
?
Data structure is a term widely used in the entire field of computer science and technology. It is used to reflect the internal composition of a data, that is, a data is composed of those component data, in what way, in what structure. The data structure is divided into logical data structure and physical data structure. The logical data structure reflects the logical relationship between the component data, while the physical data structure reflects the storage arrangement of the component data within the computer. Data structure is the form of data. Data structure is a way of organizing information. Its purpose is to improve the efficiency of algorithms. It usually corresponds to a set of algorithms. Through this set of algorithms, you can perform certain operations on the data in the data structure.
?
What is the main research of data structure?
?
As a subject, data structure mainly studies various logical structures and storage structures of data, as well as various operations on data. Therefore, there are mainly three aspects: the logical structure of the data; the physical storage structure of the data; and the operations (or algorithms) on the data. Usually, the algorithmic
?
The design depends on the logical structure of the data, and the implementation of the algorithm depends on the physical storage structure of the data.
?
What is a data structure? What is the logical structure and physical structure?
?
Data refers to a collection of elements composed of limited symbols (for example, "0" and "1", which have their own structure, operations, and corresponding semantics). Structure is a collection of relationships between elements. Generally speaking, a data structure DS can be expressed as a two-tuple:
?
DS = (D, S), // ie, data-structure = (data-part, logic-structure-part) where D is a  elements (or "nodes", which may also contain "data items" or "Data field"), S is a set of relationships defined on D (or other sets), S = {R | R: D × D × ...}, which is called the logical structure of elements. There are four basic types of logical structure: collection structure, linear structure, tree structure and network structure. Tables and trees are the two most commonly used efficient data structures, and many efficient algorithms can be designed and implemented with these two data structures. Tables are linear structures (total order relations), trees (partial order or hierarchical relations) and graphs (weak / local orders) are non-linear structures.
?
The physical structure of the data structure refers to the storage image of the logical structure. The physical structure P of the data structure DS corresponds to a mapping from the data elements of DS to the storage area M (maintaining the logical structure S):
?
(PD, S)-> M Memory model: A memory M is a series of fixed-size storage units, and each unit U has a unique address A (U), which is continuously encoded. Each unit U has a unique successor unit U '= succ (U). The four basic mapping models of P: sequential (sequential), linked (linked), indexed (indexed), and hashed (hashing) mapping.
?
Therefore, we can get at least 4 × 4 possible physical data structures:
?
sequential (sets)
linked lists
indexed trees
hash graphs
?
(Not all possible combinations are reasonable)
?
??? Operations on the data structure DS: All operations defined on the DS must maintain the logical and physical structure of the DS when changing data elements (nodes) or domains of nodes.
?
Basic operations on DS: Any other advanced operations on DS can be implemented with these basic operations. It is best to consider DS and all its basic operations as a whole-called modules. We can further abstract the module as a data type (where the storage structure of DS is represented as a private member and the basic operations are represented as public methods), called ADT. As an ADT, stacks and queues are special tables, and they have a subset of the operations of the table. Advanced operations for DATs can be designed as (unencapsulated) algorithms that use basic operations to process DS.
?
Good and bad DS: if a DS can pass a certain ... full text remaining >>
 
What is the data structure

What is data structure
?
Data structure is a term widely used in the entire field of computer science and technology. It is used to reflect the internal composition of a data, that is, a data is composed of those component data, in what way, in what structure. The data structure is divided into logical data structure and physical data structure. The logical data structure reflects the logical relationship between the component data, while the physical data structure reflects the storage arrangement of the component data within the computer. Data structure is the form of data. Data structure is a way of organizing information. Its purpose is to improve the efficiency of algorithms. It usually corresponds to a set of algorithms. Through this set of algorithms, you can perform certain operations on the data in the data structure.
?
What is the main research of data structure?
?
As a subject, data structure mainly studies various logical structures and storage structures of data, as well as various operations on data. Therefore, there are mainly three aspects: the logical structure of the data; the physical storage structure of the data; and the operations (or algorithms) on the data. Usually, the algorithmic
?
The design depends on the logical structure of the data, and the implementation of the algorithm depends on the physical storage structure of the data.
?
What is a data structure? What is the logical structure and physical structure?
?
Data refers to a collection of elements composed of limited symbols (for example, "0" and "1", which have their own structure, operations, and corresponding semantics). Structure is a collection of relationships between elements. Generally speaking, a data structure DS can be expressed as a two-tuple:
?
DS = (D, S), // ie, data-structure = (data-part, logic-structure-part) where D is a  elements (or "nodes", which may also contain "data items" or "Data field"), S is a set of relationships defined on D (or other sets), S = {R | R: D × D × ...}, which is called the logical structure of elements. There are four basic types of logical structure: collection structure, linear structure, tree structure and network structure. Tables and trees are the two most commonly used efficient data structures, and many efficient algorithms can be designed and implemented with these two data structures. Tables are linear structures (total order relations), trees (partial order or hierarchical relations) and graphs (weak / local orders) are nonlinear structures.
?
The physical structure of the data structure refers to the storage image of the logical structure. The physical structure P of the data structure DS corresponds to a mapping from the data elements of DS to the storage area M (maintaining the logical structure S):
?
(PD, S)-> M Memory model: A memory M is a series of fixed-size storage units, and each unit U has a unique address A (U), which is continuously encoded. Each unit U has a unique successor unit U'= succ (U). The four basic mapping models of P: sequential (sequential), linked (linked), indexed (indexed), and hashed (hashing) mapping.
?
Therefore, we can get at least 4 × 4 possible physical data structures:
?
sequential (sets)
linked lists
indexed trees
hash graphs
?
(Not all possible combinations are reasonable)
?
??? Operations on the data structure DS: All operations defined on the DS must maintain the logical and physical structure of the DS when changing data elements (nodes) or domains of nodes.
?
Basic operations on DS: Any other advanced operations on DS can be implemented with these basic operations. It is best to consider DS and all its basic operations as a whole-called modules. We can further abstract the module as a data type (where the storage structure of DS is represented as a private member and the basic operations are represented as public methods), called ADT. As an ADT, stacks and queues are special tables, and they have a subset of the operations of the table. Advanced operations for DATs can be designed as (unencapsulated) algorithms that use basic operations to process DS.
?
Good and bad DS: if a DS can pass a certain ... full text remaining >>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.