Using Induction to design use inductive design algorithm [3/14]

Source: Internet
Author: User

Link: http://blog.csdn.net/jj12345jj198999/article/details/6602500

 

Improvement: The first improvement is that there are many redundant computations in the solution process: the X index is calculated from the beginning. When we calculate x ^ N, using the value of x ^ (n-1) can help us save a lot of multiplication operations. These are all implemented through the induction of x ^ N in the induction hypothesis:

Stronger inductive hypothesis: we already know how to calculate polynomial Pn-1 (X) and how to calculate the value of x ^ (n-1.

This induction assumption is stronger because it requires the calculation of x ^ (n-1), but it is easier to expand. When calculating x ^ N, we only need to perform one-step multiplication, and then perform one-step multiplication to obtain an x ^ N, and then perform one-step addition to complete the entire calculation. (In fact, this assumption is not too strong, because we still need to calculate the value of x ^ (n-1 ). All in all, 2n multiplication and N addition are required. Although this induction assumption requires more calculations, it reduces the workload in general. We will discuss this later. It seems that this algorithm is good at all levels. It is efficient, simple, and easy to implement. However, there is a better algorithm, which is implemented through induction in a different way.

We can simplify the problem by moving the last coefficient. (This is a straightforward practice) but we can also remove the first coefficient A0. This smaller scale problem becomes a polynomial that is computed by the coefficients an, An-1... A1, as shown below:
P 'N-1 (x) = An * x ^ (n-1) + an-1 * x ^ (n-2)... + A1
(Note that an is the n-1 coefficient, which is changed in turn later)

New inductive hypothesis (inverted): we know how to calculate the coefficient an, An-1... the X polynomial of A1 (P 'N'-1 (x) listed above ))

This assumption is easier to expand, so it is more in line with our purpose. Obviously, Pn (x) = x * P' n-1 (x) + a0. Therefore, only one multiplication and one addition can be used to calculate the Pn (x) through P 'N'-1 (x ). The complete algorithm can be described using the following expression:
An * x ^ N + an-1 * x ^ (n-1) +... + A1 * x + a0 = ((... (an * x + an-1) x + an-2 )...) X + A1) x + a0

This algorithm is called Horna induction and named after W. G. Horner. (This was proposed by Newton ). The algorithm for polynomial calculation is given below.

Calculation Expression Algorithm
(A0, A1, a2... an, X: Real); // enter A0 to an, X, all of which are real numbers.
Begin
P: =;
For I: = 1 to n do
P: = x * P + an-I;
End;

 

Complexity Analysis: This algorithm requires only N multiplication, n addition times, and an additional memory space. Although the original solution seems simple and efficient, it is worthwhile to pursue a better algorithm. This algorithm is not only faster, but also easier for the corresponding program.

Conclusion: The simple example above illustrates the flexibility of induction. The trick of the Horna rule is to consider that the input is from left to right, rather than from right to left.

Of course, there are many other potentials using induction. We will see this in more examples.

 

Find the one-to-one ing [Q2]

F is a function that maps Finite Set A to itself. (For example, every element in a is mapped to another element in A.) For simplicity, we represent the element in a as a number from 1 to n. Assume that function f appears in the form of an array f [1. N], so that f [I] stores the value of f (I. (This value is an integer between 1 and N.) When every element in a has only one element corresponding to it, function f is called a one-to-one ing. Function f can be displayed in the graph shown in Figure 1. in the graph, the data at both ends correspond to the same set, and the edges in the graph represent the ing relationship. (This ing is from left to right)

 

Problem: Find a subset S (SCA) that contains the most elements, so that function f can map any element in S to other elements in S. (That is, F maps s to itself). At the same time, each element in S maps only the unique element in S to itself. (That is, limit s to make f a one-to-one ing)

If F is a one-to-one ing, then the complete set a meets the problem conditions. Obviously, it is also the largest set. In another aspect, if f (I) = f (j) exists and I =j, then the set S cannot contain both I and J. For example, in Figure 1, s cannot contain 2 and 3 at the same time. It is impossible to select a collection from either of them. For example, if we decide to delete 3, because 1 is mapped to 3, we must also delete 1. (Because any ing must be mapped to S, and 3 is no longer in S ).

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.