Data Structures and Algorithms (a) - Getting the basic concepts

     data structure

      Data Structure

A. Basic concepts

  • introduction

       1.1 data element (Data Element): is the basic unit of data, and the process considered as a whole in the program

              A plurality of data elements by a data item (Data Item) composed of the data item is the smallest unit of data, the data item is a data description of the characteristics of one aspect of the objective things.

1.2 Data Objects (Data Object): is a collection of data elements of the same nature, is a subset of the data.

Data structure defines a tuple (D, S) D is a finite set of data elements, S is D finite set of data on the relationship

The basic concept of a data structure of 1.3: there is one or more relationships between each data set element and the set of data elements in the relationship between the composition.

1.3.1 Data logical structure : that reflects the data elements of the logical relationship between a data structure , wherein the logical relationship is the relationship between the longitudinal member elements of data, regardless of their location stored in a computer. Logical structure comprising:

  1. set

Between the data structure elements in addition to " belong to a set of " outside the relationship, no other relations;

2. The   linear structure

To-one correlation between the data structure elements;

  1. Tree structure

There is a correlation in many of the data structure elements;

  1. Graph structure

Many to many relationship exists in the data structure elements.

       Computer software = program + data + documentation

1.3.2 Physical structure of data : storage means in the form of logical structure data in a computer memory space.  [1] 

The physical structure of the data is represented by a data structure (known as an image) in the computer, which machine comprises a data-element represents the relationship between the machine and FIG. Because of various orders, links, indexing, hashing and other concrete implementation, therefore, may be represented as a data structure stored in one or more structures.

The relationship between the elements there are two different representations in a computer: sequential storage structure and chain storage structure.

Sequential structure: data indicating the relative position of the data in the memory element the logical structure between the elements.

Chain structure: increasing a storage address pointer to another element of each data element, the logical structure represented by the data elements between the pointer.

Comparison of two different storage structure:

      Sequence Structure - address data element is stored in contiguous;

      Chain structure - data elements stored in the address does not have to be contiguous.

In the C language, a sequence with a one-dimensional array memory structure; Storage Structure represents a structural body.

     

1.4 three components of the data structure:

             Logical Structure: logical relationships between data elements        D_S = (D, S)

             Storage structure: data storage element in the performance of computer logic and memory or physical structure called data.

             Operation of the data: data manipulation.

And logical structure of the storage structure employed:

      1.5 abstract data types (Abstract Data Type): A mathematical model and a set of operations defined in the model.

      ADT : the achievement of specific issues.

             ADT is defined as a set of logical characterization

             ADT formal definition triples: ADT = (D, S, P) D : data objects, S is D relationship set on, P is D a basic set of operations.

       1.6 Data structure of the operation:

              The Create : to create a data structure

              Destory : the elimination of a data structure

              The Delete : delete data elements from a data structure

              INSERT : inserting a data element to a data structure

              Access : access to the data structure

              The Modify : the elements of the data structure to be modified         

              Sort : sort the data structure

              Search : Find the data structure

1.7 algorithm

              Refers to the exact problem-solving solutions and complete description, is a series of clear instructions to solve the problem, the algorithm represents a policy mechanism to solve the problem described in a systematic way.

              The nature of the algorithm:

              Finite: the algorithm has poor refers to the termination of the algorithm must be executed after a finite number of steps;

              Uncertainty: each step of the algorithm must have a precise definition;

              Feasibility: 0 can have inputs, at least one output, each computation by the finite times to complete

       1.7.1 Time complexity of the algorithm

           Algorithm efficiency metrics :

            Execution time of the algorithm based programming time required by the algorithm running on a computer metrics

            T = n ( the number of instructions) * CPI * 1 / clock cycle is determined by the number of instructions

            = Running time of each statement of the algorithm execution time.

                Each statement set the execution time required for a unit of the running time of the algorithm is a frequency change of all statements and algorithms.

            There are about two kinds of methods:

                Prior Statistics: statistics and actual space inside the computer to perform the (large-scale project is not desirable)

                Prior analysis: obtaining a function of time limit of the algorithm, the basic analysis of the order of n

              The number of basic arithmetic operations are performed repeatedly problem size n of a function, which is recorded as a measure of time:

T (n) = O (f (n)), a progressive time complexity of the algorithm referred to, for short time complexity.

              Execution frequency operation of the original common deepest inner loop statement represented

              Represents the time complexity of order are:

                     O (1): Constant time order         O (N): Linear Time Order

                     O (logN): logarithmic time order    O (NlogN): linear logarithmic time order

                     O (N ^ k): K > = 2, k th order time

Demo1:

for(i=1;i<=n;i++)
    for(j=1;j<=n;j++) {     
        c[i][j] = 0;  //已经执行了n*n次
        for(k=0;k<=n;k++){     
        c[i][j]+=a[i][j]*b[i][j];       //执行了n*n*n次
    }      //总和:n^3+n^2
}     

Three repeat cycles, from 1 to n- , then the total number of times: n-* = n-n-n-* ^. 3, the time complexity of T (n) = O (n ^ 3);

       Six commonly used to calculate polynomial time

       O(1)<O(logN)<O(n)<O(NlogN)<O(n^2)<O(n^3)

       Index of the time :

       O(2^n)<O(n!)<O(n^n)

       Is a prime number is determined whether: O (n-^. 1/2) , and as long as 1 ~ n primes comparison between the number is n / 2 cycles .

       Quick calculation:

              Case 1 The basic statement of n independent O (1)

              Case 2 split Principle n / 2 O (log2n) // log to 2 as a substrate

              Case 3 single principle , rely n O (n)

              Case 4 double loop , split principle   O (nlog2n)

              Case 5 two-cycle                    O (n ^ 2)

       1.7.2 space complexity of the algorithm

              Complexity Space : a measure of the size of the programming required to run in a computer algorithm storage space. Denoted as: S (n-) = O (F (n-))

       Instruction memory occupied by variables constant;

       Input data storage space occupied;

       It refers to a constant work-place algorithm auxiliary space required algorithm , i.e., O (1)

       Secondary ( storage ) space.

              Space complexity of the algorithm refers to the auxiliary space.

              One-dimensional array A [n-] : space complexity  O (n)

              Two-dimensional array [n-] A [m] : space complexity of   O (n * m)

Published 58 original articles · won praise 31 · views 40000 +

Guess you like

Origin blog.csdn.net/qq_37504771/article/details/104261276