Time complexity of analysis algorithm--The theorem of the item

Source: Internet
Author: User
Tags comparison constant

In the analysis of the time complexity of the algorithm based on the recursive equation, the equation is common to the following forms,
T (n) = A * T (n/b) + f (n)
A³1,b > 1,f (n) is generally a simple function

There are 2 ways to calculate the complexity of time. One is to use recursive tree, layer by generation into the original, and eventually form a series,
And then use a function to express, get T (n).

The second is the Master Method, which applies the item theorem. In fact, the Master theorem is an induction of recursive tree method, which forms
Fixed calculation method, and in three kinds of situations to calculate.

These three cases are mainly compared to Nlogba and F (n), why compare these two functions.

Observing the primitive, it can be seen that the Nlogba is actually equivalent to the first of the right of the recursive equation solved by the recursive tree method,
and f (n) is the second item to the right of the recursive equation, so that the master theorem is actually a comparison of the two function items that comprise the result,
And this comparison is based on the magnitude (or amplitude) of the comparison, that is to say, such as 2n and 28n is
Magnitude (magnitude of change) equivalent.

There are three different scenarios:

F (n) < Nlogba

i.e. f (n) = O (nlogba-e), E > 0 is any small constant
Or, f (n) changes slower than Nlogba, slow NE
So, T (n) îq (Nlogba)

F (n) > Nlogba

i.e. f (n) = W (Nlogba +e), E > 0 is any small constant
Or, f (n) changes faster than Nlogba, NE
So, T (n) îq (f (n))

It can be simply said that the two items on the right side of the recursive equation, which change the block, T (n) belong to which order of magnitude

F (n) = Nlogba

That is, the order of magnitude of the two items is equal to the order of magnitude multiplied by the previous LG N

T (n) îq (Nlogba * LG N)

Examples (The following example is from the network):

T (n) = 5T (N/2) + Q (n2)

Case 1:if f (n) = O (nlogba-e) for some constant e > 0 then T (n) îq (Nlogba)

Determine:a, B, f (n) and Logba

A = 5

b = 2

F (n) = Q (n2)

LOGB A = log2 5≈2.32

is f (n) îo (NLG 5-e) for e > 0?

Yes. F (n) = Q (n2) Îo (NLG 5-e) = O (n2.32-e) for e≈0.32

T (n) îq (NLOG25)

2. T (n) = 2T (N/2) + N

Determine:a, B, f (n) and LOGB (a)

A = 2

b = 2

F (n) = n

LOGB A = log2 2 = LG 2 = 1

Case 3:if f (n) = Q (Nlogba) and then T (n) îq (NLOGBA LG N)

F (n) = Nîq (Nlog22) = Q (N1)

T (n) îq (nlog22 lg N) = Q (n lg N)

3. T (n) = 5T (N/2) + Q (n3)

Determine:a, B, f (n) and LOGB (a)

A = 5

b = 2

F (n) = Q (n3)

LOGB A = log2 5≈2.32

Case 2:if f (n) = W (nlogba+e) for some constant e > 0

F (n) = Q (n3) îw (nlog25+e) = W (n2.32+e) for e≈0.68

and AF (n/b) ≤CF (n) for some constant C < 1 and all sufficiently large n

5 (N/2) 3≤cn3

5n3/8≤cn3

c = 5/8 < 1

Then T (n) îq (n3)

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.