Source: Internet
Author: User

01. Concept and algorithm basis of Data Structure, 01 Data Structure**Data Structure concepts and algorithm Basics****I. Data Structure Concept****1. Data**: A symbol used to describe objective transactions. It is an object that can be operated on by computers. It is a collection of symbols that can be recognized by computers and input to computers for processing. Data includes not only integer, real, and other numeric types, but also non-numeric types such as characters, sounds, images, and videos.**2. Data Elements**It is a basic unit that makes up data and has a certain significance. It is usually processed as a whole in a computer and also becomes a record. For example, in animals, cattle, horses, and sheep all belong to data elements.**3. Data items**: A data element can be composed of several data items, which are the smallest units that cannot be separated. Data elements such as people can have data items such as eyes, ears, and noses.**4. Data Objects**: A set of data elements with the same nature. It is a subset of data. The data element has the same quantity and type. For example, all people have the same data items such as name, birthday, and gender. In a sense, data objects are also called data (data objects are subsets of data ).**5. Data Structure**: Different data elements are not independent. Second, they have specific relationships, which can be called structures. The so-called data structure refers to a set of data elements with one or more specific relationships between each other-the data organization form.**6. logical and physical structures**(1) Logical Structure: it refers to the relationship between data elements in the data object. The logical structure is designed to solve a specific problem. Based on the understanding of the problem, a proper data structure is selected to represent the logical relationship between data elements. A. Set structure: Except for the same set, the data elements in the set structure have no other relationships. B. linear structure: the data elements in the linear structure have one-to-one relationships. C. Tree Structure: there is a one-to-many hierarchy between data elements in the tree structure. D. Graphic Structure: The data elements of the graphic structure are many-to-many relationships. Note: When we use a logical structure to represent data, we need to consider each data element as a node (represented by a circle ); the logical relationship between elements is expressed by the line between nodes. (2) Physical Structure: it refers to the storage form of the logic structure of exponential data in the computer, that is, how to store data elements in the memory of the computer, the data storage structure reflects the relationship between data elements. A. Ordered Storage Structure: stores data elements in address-contiguous storage units. The logical and physical relationships between the data are consistent. B. chained Storage Structure: stores data elements in any storage unit, which can be continuous or discontinuous. The storage relationship of data elements does not reflect the logical relationship. Therefore, you need to use a pointer to store the address of the data element. In this way, you can find the location of the associated data element through the address. Conclusion: The logical structure is problem-oriented. The physical structure is computer-oriented, and its basic goal is to store data and logical relationships in the computer's memory.**7. Data Types and abstract data types****(1) Data Type**: Refers to a set of values of the same nature and a general term for some operations on this set.**(2) abstract data type (ADT)**: Refers to a data model and a group of operations defined on the model. The meaning of "abstraction" lies in the mathematical abstraction of data types. An abstract data type is defined as a data object, the relationship between each data element in the data object, and the operations of data elements. In short, abstract data types reflect the problem decomposition, abstraction, and Information Hiding features in programming. ABSTRACT Data Types break down real-life problems into small and easy-to-handle problems, and then create a mathematical model that can be processed by a computer. The time details of each function module are used as an independent unit to hide the specific implementation process. Standard format for describing abstract data types:

Principle 1: replace all addition constants in the running time with constant 1 --------------- example: f (n) = 3, then according to the time complexity of the large order method is O (1) Principle 2: in the modified number of running functions, only the highest-order items are retained ------------ example: f (n) = 3n + 1 Principle 3: If the highest-order items exist and are not 1, then the constant multiplied by this is removed. ----- Example: --------- the time complexity of the Large O-order method is O (n) 0.

The number of program executions is (n + a), where a is a constant. According to Principle 2 and 3, the time complexity of the algorithm is O (n ). To determine the order of an algorithm, we often need to determine the number of times a specific statement or statement set runs. Therefore, the key to analyzing the complexity of algorithms is to analyze the running status of the loop structure. (3) source code of the logarithm level: int count = 1; while (count <n) {count = count * 2 ;.... /* program step sequence with a time complexity of O (1) */} since each count multiplied by 2, it is closer to n, that is to say, if the number of 2 is multiplied by greater than n, the loop will exit. From 2 ^ x <n x <log2 ^ n, the number of program executions is log2 ^ n = log (2*2*2*2*2 *... * n ). The time complexity of the algorithm based on principle 2 and 3 is O (logn ). (4) squared source code 1: int I, j; for (I = 0; I <m; I ++) {for (j = 0; j <n; j ++ );{.... /* program step sequence with a time complexity of O (1) */} program statement execution times: f (n) = m * n + 1 +, a is a constant. According to the large O-order method, the time complexity of the algorithm is O (m * n ). source code 2: int I, j; for (I = 0; I <n; I ++) {for (j = I; j <n; j ++) {/* program step sequence with time complexity of O (1) */} analysis: When I = 0, the internal cycle is executed n times; when I = 1, executes n-1 times ;.... when I = n-1, it is executed once. Therefore, the number of Program Statement executions is f (n) = n + (n-1) + (n-2) +... + 1 = n (n + 1)/2 = n ^ 2/2 + n/2 + a, where a is a constant. According to the large O-order method, the time complexity of the algorithm is O (n ^ 2 ).

The control complexity of an algorithm is implemented by the storage space required by the computing algorithm. The calculation formula of the control complexity is as follows: S (n) = O (f (n, n is the scale of the problem, and f (n) Is the function of the statement about the storage control occupied by n. "Time Complexity" refers to the running time requirement, and "space complexity" refers to the space requirement. In short, the advantages and disadvantages of algorithms directly determine the efficiency of program running.

Related Article