(1) The basic concept of data structures and algorithms

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/SDDDLLL/article/details/90760009

This is my first article in the series architect, also my mountains for it, so in a future article, I think it is easier to understand in simple words to explain the problem. Want a subsequent series of articles, I am concerned, I will continue to post (hope you're not the only person not to see the collection).

Ado, if we want to learn data structures and algorithms, first the mind must always remember two key words, time efficiency and space efficiency . The two architects throughout the entire vocabulary knowledge. What is the time efficiency and space efficiency it? Popular understanding is: We use two different programs to solve the same problem, high short time Description Time efficiency, high consumption of small space description space efficiency. Now back to the subject of our data structure.

We are studying data structures and algorithms, when, in fact, use different data structures and different algorithms to optimize time efficiency and space efficiency of the computer. So what data agencies as well as algorithms have such a good performance? The first sub-classes of these data structures.

A classification data structure

We can see from the chart, the entire data structure knowledge and research algorithms also so much. Remember the time efficiency and space efficiency just mentioned thing? Logical structure and storage structure for all services. The operation data is the manifestation of time efficiency and space efficiency.

Second, the analysis of the data structure

The relationship between the logical structure of the data referred to. For example a set of linear structures (one to one), a tree structure (one to many), the graph structure (many).

In the form stored in a computer data storage structure called.

    1, sequentially stores: data element he is using in the relative position memory to represent logical relationships between data elements

    2, the chain stores: increasing a storage address pointer in each data element, the element represents the logical relationship between the pointer.

Third, the time complexity and space complexity

In the beginning of the article describes the time efficiency and space efficiency, so the two of them how to use data to quantify it? Or how are we to measure time efficiency and space efficiency it? It uses the time complexity and space.

1, first of all look at the time complexity:

Want to know the time complexity, we need to understand the time frequency. Time spent with a number of algorithm execution algorithm is proportional to the statement, the statement is executed which algorithm more often, it takes time and more. A number of execution algorithms statement called the statement frequency or time frequency . Referred to as T (n).

Then it introduces the concept of time complexity. Look at the comparison of the official definition of it: In general, the number of basic arithmetic operations executed repeatedly n is a function of problem size, with T (n) said that if an auxiliary function f (n), such that when n approaches infinity, T (n) / f (n) is not equal to zero limit constant, called f (n) is T (n) is a function of the same order. Denoted by T (n) = O (f (n)), said O (f (n)) is a progressive time complexity of the algorithm, referred to as time complexity . Is not difficult to understand, it plainly is the time complexity of time scale described, for example, the frequency of time is T (n), the time complexity is O (n). Time frequency is time T (n + n), the time complexity is O (n). That is, his time is n this level of scale.

Common relationship between the time complexity of the algorithm is:

O(1)<O(logn)<O(n)<O(nlog n)<O(n2)<O(2n)<O(n!)<O(nn)

To give an example:

  a=0;                         //(1)
     for(i=1;i<=n;i++)          //(2)
        for(j=1;j<=n;j++)       //(3)
         a++;                  //(4)

Statement (1) is executed once,

Statement (2) n times

Statement (3) the implementation of n2 times

Statement (4) the implementation of n2 times

T (n) = n + 1 + 2n2 = O (n2)

2, space complexity

Space complexity is easier to understand, and space complexity of the algorithm is a measure of a temporary occupation of storage space during operation, the same reflects a spatial scale, we use S (n) is defined.

Space complexity are commonly used: O (1), O (n), O (n²),

Guess you like

Origin blog.csdn.net/SDDDLLL/article/details/90760009