Overview of basic data structures and algorithms

data structure

I am a "stack"

  • The computer world to store and organize data
    to introduce the following four different data storage
  • Array
    Storage: stored sequentially in consecutive memory
    Access: only need to provide the location index
    Note: You can only save the same type of data
    features: easy to read, delete and insert difficulties.
  • List
    storage: discrete space containing a pointer to the node points and a data node.
    Access: From the first start looking, know where to find the data you need
    characteristics: difficulty addressing, easy to remove and insert
  • Stack
    principles: last out
  • Queue
    principle: First In First Out

Time complexity:
represented by O (n), is a function of, qualitatively describes the running time of an algorithm
from the execution times T (n) can know a time complexity of
the presence of a constant C, such that when N> = c when T (N) <= f ( N), is expressed as T (n) = O (f (n))
as the input of size n increases, the time required for execution of the algorithm can be growth rate f (n) represents
the T (n-) => O (n-)
T (n-) = constant, O (n) = 1,
selecting higher order terms

比如
T(n) = n^3 + n^2 + 29,此时时间复杂度为 O(n^3)。

Disregarding the highest order constant multiplied
by analyzing the algorithm and mathematical operations obtained from T (n-)
1. For a cycle time, assuming that the complexity of the loop body is O (n), the number of cycles is m, the time complexity of the cycle degree is O (n- m)
a plurality of cycle 2, the loop time complexity is O (n), each of the cycles a, B, C ..., O (n-) = O (n-
a B C .. .). When analyzed in the analysis outwardly from the
algorithm executed 3. sequence, the total time complexity equal to the maximum complexity
4. conditional statement, the total time complexity equal to the complexity of the time complexity of the maximum path
Quicksort time complexity
1 is preferably O (nlogn)
2. worst is O (n2)
the spatial complexity:
describes an algorithm memory required

Recursive algorithm: there is a procedure or function calls and notes in its direct or indirect calls itself one way, usually to a large, complex problem into a similar problem with the original smaller problem to solve . Recursion requires only a small number of programs can be described repeatedly calculate the required process of problem solving, greatly reducing the code size. Recursive infinite set of capabilities that with limited statement to define object.

Generally, recursive need to have the boundary conditions, recursive and recursive return of the advance period, when the boundary conditions are not met, recursive forward, when the boundary conditions are met, the recursive return.

Constitute conditions recursive need:

1. The sub-problem and the original problem is the same thing, and more simple;

2. Not unlimited calls, there is a need to export, simplify the situation for non-recursive processing.

Fibonacci number is a typical recursive case.

Recursive algorithm has some performance issues for the cycle with respect. If recursive particularly deep, and may cause a stack overflow.

Recursive algorithm design steps of:

1. Determine the recursive formula

2. determining the boundary (end) Condition

Typical example:

Fast sorting algorithms: take the first random number sequence value, then the value is put forward by comparing the value is smaller than the element value larger than the element into the rear of the value, and then again on the front half portion the number of columns and the second half of the above-described operations out of order.

The average complexity of quick sort algorithm is O (nlogn), the worst case complexity is O (n ^ 2)

Comparison of insertion, bubble, merge, fast sorting algorithms, such as different advantages and disadvantages. From the additional space consumption, the average time complexity and worst aspects of time complexity and so to compare their advantages and disadvantages.

Guess you like

Origin www.cnblogs.com/kehaoran/p/11101439.html