Sunday 15 May 2011

math - Analyzing an algorithm with recurrence T(n) = T(n - 1) + T(n - 2) + T(n -3)? -


Therefore, someone has posted this before, but essentially no attempt was made in it, it was poorly tagged It was closed and then closed. However, I think it could be a good question I was posting because according to OP, my answer (posted in a comment) did not agree with the solution. So, I'm trying to understand what I'm doing wrong (assuming that it's actually true):

We:

  TN ) = T (N-1) + T (N-2) + T (N3)   

Where N & gt; 3. The base case was not listed with them, but later N & gt; 3, I have assumed that there are probably 3 basis cases for T (3) , T (2) and T (1) . To calculate T (K) , we do the following:

  T (k) = t (k -1) + t (k-2) ) + T (K-3)   

Then we should calculate it:

  t (k -1) = t ((1 -1 - 1) + T ((K-1) -2) + T ((K -1) -3) T (K2) = T ((K -2) -1) + T ((K -2) - 2) + T ((K-2) -3) T (K3) = T ((K3) -1) + T ((K3) -2) + T ((K3) - 3)   

And so on ... Here is a tree representation:

  LT (K) / | L1T (K) -1) T (K2) T (K-3) / | / | | / | (L-1T) -1 (T1 (T1) T ((K -1) -2)T (K-1) -3) T ((K2) -1) T ((K2) - 2) T ((K2) -3) T ((K3) -1) T ((K3) -2) T ((K-3) -3 ... ... .. .. So we have 3 children, 9 children, then There are 27 children ..., unless we kill our base cases. Therefore, the algorithm  O (3 ^ (N-3)), account for three basis cases, i.e. T ( 4) After, we can only make sockets case, there is no branch now  

The real solution was never provided, but as I said, I Zhe has said that it is wrong would appreciate any help.

The recurrence that you have established is:

T (n) = T (N-1) + T (N-2) + T (N-3)

I think the cases of the base probably T (1) = 1

  • T (2) = 1
  • T (0) = 1
  • T (4) = 5
  • T (5) = 9
  • T (6) = 17
  • T (7) = 31
  • ...

    Here does not seem to be a clear pattern. Luckily, we have 1, 1, 1 According to 3, 5, 9, 17, you can go to the online encyclopedia and punch of integer sequences and you think this is the same as the first three conditions are 1.

    If you see information about Tribonacci numbers, you will see the following:

    A (N) / A (N-1) Tribonacci constant, at 1.839286755 goes. ..

    (Here, there is an (N) site that uses for my T (n)). Since the continuous terms of the sequence of the sequence of the sequence are approximately 1.839286755, we know that the sequence of the trion should be growing intensely, and it grows rapidly at a rate which is approximately Θ (1.839286755 n ) . (Compare this to Fibonacci sequence, which is known to grow on Θ (φ n ), where φ is a golden ratio). On reading this further, Troyanki gives this formula for continuous:

    Enter the image details here

    and confirming the exponential growth rate.

    As a result, we can conclude that the runtime is Θ (1.839286755 n ).

    So ... how do you calculate it yourself? The easiest way to do this (and I think that these values ​​have been known) is to use. You can try to get a creative work for iterations written here, then try to rewrite the generating function in a closed-form to get the exact value. This is a way to get closed form for Fibonacci numbers, and it should be normalized (though it can be too much through unpleasant maths.) Alternatively, as @TMKeloba explains, you can write this matrix Are:

      | 0 1 0 M = | 0 0 1 | | 1 1 1 |   

    And calculate your eigenvalues, the largest of which will be coming out to the Tribonacci constant (note that this matrix has the property

      | 0 1 0 | | | | | b | 0 | | x | b | = | c | | 1 | 1 | | c As a result, if you repeat the three values ​​continuously with a single column vector and calculate MV If you do, then you return a new column vector back to the second value from the repetition, as well as the next value in the repetition. By computing M  k  v and the first part of the vector, calculate the Keith value of the repetition.)  

    Hope it helps!

  • No comments:

    Post a Comment