Design and Analysis of Algorithms: Introduction

● algorithms and procedures

Algorithm means to solve the problem one method or a process .
Algorithm is a finite sequence of several instructions satisfy properties:
(1) Input : YES amount supplied externally as input to the algorithm.
(2) Output : at least one algorithm produces as an output quantity.
(3) Uncertainty : each instruction is composed of the algorithm clear , unambiguous 's.
(4) Limitation : algorithm each instruction execution frequency is limited to, each instruction execution time is limited to.

Program is the algorithm using a programming language specific implementation . Program can not satisfied with the nature of the algorithm, such as the operating system .

● Step design algorithm

Understand the problem : Before designing an algorithm, we need to do first thing is to fully understand the issues presented. At the same time, need to be addressed strictly defined algorithm instance range is very important. A proper algorithm should not only be able to handle most of the cases, and should be able to correctly handle all legal input.
Understanding of computer equipment performance : most algorithms used today still runs on the von Neumann computer. Its primary random access machine vision is: running command one by one, each time the operation step, called sequential algorithm . Some newer computers can perform multiple operations at the same time, i.e., parallel computing .
Between the exact and approximate to choose : Solution called precise exact algorithm , called the approximate solution approximation algorithm . You can not get the exact solution or due to some problems inherent complexity , using known exact algorithm to solve this problem may be unacceptably slow.
Determining appropriate data structures : algorithms and data structures, computer programming of important foundation . Algorithms + Data Structures = Programs

● index analysis algorithm

For any algorithm or a solution, there are the following two questions:
(1) the problem can be resolved?
(2) to solve the problem, okay?

Efficiency is not the analysis of algorithms for the sole purpose of. Although the algorithm goal is speed , but the algorithm must first correct meaningful existence. Design algorithms , or when multiple algorithms compare the time, it is necessary to analyze their correctness and time efficiency . This kind of algorithm dissected to obtain their accuracy and time efficiency of the operation is the algorithm analysis . If the two algorithms time efficiency , we must implement the algorithm used space by comparing space using less is better.
Thus, the analysis algorithm can be divided into the following three aspects:
(1) correctness of
temporal efficiency analysis (2)
(3) Analysis of the temporal characteristics

= Algorithmic complexity algorithm computer resources required
time complexity of T (n-) ; space complexity of S (n-) .
Where n is the problem size (input size).

Time complexity of the algorithm has the following analysis:
(1) the worst case time complexity at
Tmax of (n-) = max {T (the I) | size (the I) = n-}
(2) the best-case time complexity of the resistance
of Tmin (n) = min {T (I) | size (I) = n}
(. 3) average case time complexity at
Tavg (n) =Here Insert Picture Description
where I is the problem size n of example , p (I) example I is appearing probability .

If for T (n) → ∞, as n → ∞;
have (T (n) - t ( n)) / T (n) → 0, as n → ∞;
called t (n) is T (n) the asymptotic behavior , the algorithm of the asymptotic complexity .
Mathematically, t (n) is T (n) is the asymptotic expression is T (n) primary item left lower order terms are omitted . It (n) simpler than T.

Asymptotic analysis of the symbol : In the following discussion, for all n, f (n) ≥ 0 , g (n) ≥ 0.
(1) bound the symbol O asymptotically
O (g (n)) = {f (n) | , and the presence of normal number c for all n ≥ n0 n0 such that there is: 0 ≤ F (n-) ≤ CG (n-)}
( 2) the asymptotic lower bound notation [Omega]
[Omega] (G (n-)) = {F (n-) |, and the presence of normal number c for all n ≥ n0 n0 such that there are: 0 ≤ CG (n-) ≤ F (n-)}
(. 3) non-bound tightening mark O
O (G (n-)) = {F (n-) | for any normal number c> 0, and a positive number n0> 0 such that for all n≥ n0 has: 0 ≤ f (n) < cg (n)}
is equivalent to f (n) / g (n ) → 0, as n → ∞.
(4) Non-tight lower bound notation [omega]
[omega] (G (n-)) = {F (n-) | for any normal number c> 0, there is a positive number and the n0> 0 such that ≥ n0 have all n: 0 ≤ cg (n ) <f (n)}
is equivalent to f (n) / g (n ) → ∞, as n → ∞.
f (n) ∈ ω (g (n)) is equivalent to G (n-) ∈ O (F (n-))
(. 5) immediately asymptotically bounded symbol [Theta]
[Theta] (G (n-)) = {F (n-) | presence of normal number c1, c2, and n0 n0 ≥ have all such n: c1g (n) ≤ f (n) ≤ c2g (n)}

For the algorithm a function of time f (n) , if f (n) and g (n) is the same magnitude (the same order), available f (n) = O (g (n)) expressed in the form. He said formula is the time complexity of the algorithm , also known as the time complexity of the algorithm is O (G (n-)) .
Commonly used time complexity have the following relationship:
O (. 1) ≤ O (log2n) ≤ O (n-) ≤ O (n-* log2n) ≤ O (n- 2 ) ≤ O (n- . 3 ) ≤ ... ≤ O (n- K ) ≤ O (2 n- ) <O (n-!)

● classification algorithm

Algorithm roughly divided into three categories:
(1) limited, deterministic algorithms
such algorithms for a limited period of time terminates . They may take a long time to perform assigned tasks, but will terminate within a certain period of time. Such algorithms often the result depends on the input values .
(2) a limited, non-deterministic algorithm
such algorithms in a limited time terminates . However, for a (or some) of the given numerical value, and the result of the algorithm is not unique or determined .
(3) infinite algorithm
refers to those because there is no termination condition is defined , or defined conditions not satisfied by the input data algorithm without terminating the operation. Typically, an infinite algorithm is due to the failure to determine the termination condition is defined.

Classical algorithm :
1. Exhaustive search
2. Iterative algorithm
3. Recursive algorithm
4. Recursive algorithm
5. Divide and conquer algorithm
6. Greedy algorithm
7. Dynamic programming algorithm
8. Backtracking
9. Branch and bound algorithm

Published 39 original articles · won praise 4 · Views 2052

Guess you like

Origin blog.csdn.net/weixin_44712386/article/details/105008543