math - method for substituting the variable in a recurrence relation -
or the Data Structures class we are learning how to solve recurrence in 1 variable. Unfortunately, some things come "out of blue" Example: Some exercises already show how to calculate the variable n:
for T (n) n = 2 ^ of
t (n) = for n = & Lt; 2
T (n) = 8T (n / 2) + bn ^ 2 (a and b >> 0)
But some exercises will only give you without T (n) Providing substitution for variable n:
T (n) = 1 n = & lt; 1
T (n) = 2 T (n / 4) + sqrt (n)
I used the repetition method and reached the correct answer: sqrt (n) + ( 1/2) * sqrt (n) * log (n) but when the professor explained, he started by saying: "Let's do it n = 4 ^" I mean, "using the fact" out of blue " The answer is simple to get.
T (n) = 1n = & lt; This is another example:
(n) = 2 t ((n -1) / 2) + n
Here I started again with the repetition method, but I can not reach a certain answer, it looks more complex in that way. After 3 iterative steps I reached:
(1) T (n) = 4 t ((n -2) / 4) + 2n - 1
(2 ) T (n) = 8 t ((3-n-3) / 8) + 3n-3
(3) t (n) = 16 t ((n4) / 16) + 4n-6
i t (i) = 2 ^ i * t ((r) / 2 ^ i) + i * n - ??? I'm interested to say this last part I do not understand, maybe I made a mistake.
Though he replied that he starts with another replacement again: let's say N = (2 ^ K) -1 WTF ??
What is the logic behind this? Thank you.
In all these cases, these replacements are appropriate because they write the repetition as a form again. These repetitions of S (K) = AS (K - 1) + F (K) are often easier to solve compared to other iterations because they clearly defined S (K) in terms of S (K) Are there.
Some examples do this to see how it works. Consider this recurrence:
T (n) = 1 (if n & le; 1)
T (n) = 2T (n / 4) + sqrt (N) (otherwise)
Here, the size of the problem decreases with one aspect of four on each walk. Therefore, if the input is the correct power of four, then input 4 k to 4 k-1 to 4 k-1 to 4 K-2 , etc. Until the recycling is not downwards If we make this replacement and do s (k) = t (4 k ), we get the cap
S (0) = 1
s (k) = 2s (k - 1) + 2 k
This is now a recurrence relation where reference to S (k) Is defined in S (K-1), which can make it easier to solve repetition.
Let's look at your original iteration:
T (n) = one (for N & A); 2)
T (n) = 8T (n / 2) + bn 2
Note that recursive phase divides by n Have two If n is the true power of two, then the recursive phase considers the power of two which comes right before n. S (k) = t (2 k )
s (k) = a (for & le; 1)
S (k) = 8 s (k-1) + b2 2k
Note how S (K) is defined in terms of S (K) It is very easy to solve which is the choice of the powers of two, the choice of the powers of the two was "natural" because of this it was clearly mentioned that the recurring step of the previous value of S. and some arbitrarily small The prices were not.
Now, look at the last occurrence: T (n) = 2 t (n -1) / 2) + n
T (n) = 1 ( N & P; 1)
/ blockquote>
We want to do some replacement k = f (n) that T (F) = 2 T (F) - 1) + The question is how this is done.
With some testing and error, we find that setting in F (N) = 2 n - 1 bill, because
(F (n) - 1) / 2 = ((2 n - 1) - 1) / 2 = (2 n - 2) / 2 = 2 N-1 - 1 = f (n) - 1
Therefore, k = 2 n - 1 and s (k) = On installing T (2 n - 1) we get
s (n) = 1 (if n & le; 1)
< P> S (n) = 2 s (n -1) + 2 n - 1
Hope it helps!
Comments
Post a Comment