How to solve T(n)=4T(n/4)+n^2 by recursion tree and master theorem? - recurrence

T(n) = 4T(n/4) + n^2 (if n=1, T(1)=c for some positive constant)
I asked MathStackExchange but no one answered.
What I want to ask is the answer to solving by master theorem and recursion tree about the same problem.
The conclusion is below sentences.
Master theorem = theta(n^2)
Recursion tree = theta(n^2 log_4 n)
How to solve and what is the answer?

In the first level we have O(n^2) time-complexity. For the second level we have 4 times O(n/4). For the next level 4*4 times O(n/(4*4)) and so on.
So we have
PS:
The last part is a geometric series with a=1 and q = 1/4 summed upto m which m is equal to log_4(n).
Depth of recursion tree can calculate from n/4^i = c formula. So h = log_4(n).

Related

arbitrarily weighted moving average (low- and high-pass filters)

Given input signal x (e.g. a voltage, sampled thousand times per second couple of minutes long), I'd like to calculate e.g.
/ this is not q
y[3] = -3*x[0] - x[1] + x[2] + 3*x[3]
y[4] = -3*x[1] - x[2] + x[3] + 3*x[4]
. . .
I'm aiming for variable window length and weight coefficients. How can I do it in q? I'm aware of mavg and signal processing in q and moving sum qidiom
In the DSP world it's called applying filter kernel by doing convolution. Weight coefficients define the kernel, which makes a high- or low-pass filter. The example above calculates the slope from last four points, placing the straight line via least squares method.
Something like this would work for parameterisable coefficients:
q)x:10+sums -1+1000?2f
q)f:{sum x*til[count x]xprev\:y}
q)f[3 1 -1 -3] x
0n 0n 0n -2.385585 1.423811 2.771659 2.065391 -0.951051 -1.323334 -0.8614857 ..
Specific cases can be made a bit faster (running 0 xprev is not the best thing)
q)g:{prev[deltas x]+3*x-3 xprev x}
q)g[x]~f[3 1 -1 -3]x
1b
q)\t:100000 f[3 1 1 -3] x
4612
q)\t:100000 g x
1791
There's a kx white paper of signal processing in q if this area interests you: https://code.kx.com/q/wp/signal-processing/
This may be a bit old but I thought I'd weigh in. There is a paper I wrote last year on signal processing that may be of some value. Working purely within KDB, dependent on the signal sizes you are using, you will see much better performance with a FFT based convolution between the kernel/window and the signal.
However, I've only written up a simple radix-2 FFT, although in my github repo I do have the untested work for a more flexible Bluestein algorithm which will allow for more variable signal length. https://github.com/callumjbiggs/q-signals/blob/master/signal.q
If you wish to go down the path of performing a full manual convolution by a moving sum, then the best method would be to break it up into blocks equal to the kernel/window size (which was based on some work Arthur W did many years ago)
q)vec:10000?100.0
q)weights:30?1.0
q)wsize:count weights
q)(weights$(((wsize-1)#0.0),vec)til[wsize]+) each til count v
32.5931 75.54583 100.4159 124.0514 105.3138 117.532 179.2236 200.5387 232.168.
If your input list not big then you could use the technique mentioned here:
https://code.kx.com/q/cookbook/programming-idioms/#how-do-i-apply-a-function-to-a-sequence-sliding-window
That uses 'scan' adverb. As that process creates multiple lists which might be inefficient for big lists.
Other solution using scan is:
q)f:{sum y*next\[z;x]} / x-input list, y-weights, z-window size-1
q)f[x;-3 -1 1 3;3]
This function also creates multiple lists so again might not be very efficient for big lists.
Other option is to use indices to fetch target items from the input list and perform the calculation. This will operate only on input list.
q) f:{[l;w;i]sum w*l i+til 4} / w- weight, l- input list, i-current index
q) f[x;-3 -1 1 3]#'til count x
This is a very basic function. You can add more variables to it as per your requirements.

Cannot solve this algebraic equation in Maxima?

Hello i am trying to solve a algebric equation in maxima, the equation has alpha, delta and psi as variable. I want the alpha in equation to be solved in terms of psi and delta. I tried using the solve command but i am getting alpha in terms of alpha.
Here is the equation to solve Equation to solve
And this is the output from maxima
.
This is the code i am trying -->
solve([(sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta)=0],alpha);
Thank you
The problem with that algebraic equation is that involves square roots,or radicals and normal polynomial, and that that type of equation is not easy to solve, take a look at this equation:
(%i30) solve(x=sqrt(x+6),x);
(%o30) x = sqrt{x+6}
So Maxima doesn't return any value, but for example other software Mathematica does.
Let's square both sides of equation and try to solve it
(%i31) solve(x^2=x+6,x);
(%o31) x=3 , x=-2
we get two solutions, let's try with first equation:
3 = sqrt(3+6) => 3 = sqrt(9) => 3 = 3
-2 = sqrt(-2+6) => -2 = sqrt(4) => -2 = 2 ??????
So the second solution is not valid,
maxima solve program in Macsyma/Maxima generally avoids methods that
produce false solutions, like "square both sides". It may still
make errors based on dividing by expressions that appear to be
non-zero, but actually ARE zero, and maybe some other similar
situations.
from this mailing list
In your case I will factor the equation to get a simplified version but with those free variable this will be difficult so, try to assume some values for psi and delta:
(%i26) solve(factor((sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta))=0,alpha);
(\%o26) \left[ \alpha=\ifrac{\left(3\,\delta+2\right)\,\isqrt{\left(-4\,\alpha-4\right)\,\delta\,\psi+\alpha^2\,\delta^2}+\left(-2\,\delta-2\right)\,\isqrt{\left(4\,\alpha^2+6\,\alpha+3\right)\,\delta^2+\left(2\,\alpha^2+4\,\alpha+2\right)\,\delta}}{\delta^2} \right]
Expand your Equation and try to remove square roots or some assumptions:
Equation : (sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta);

optimal separating hyperplane objective function confusion

Chapter 4.5.2 of Elements of Statistical Learning
I don't understand what does it mean:
"Since for any β and β0 satisfying these inequalities, any positively scaled
multiple satisfies them too, we can arbitrarily set ||β|| = 1/M." 
Also, how does maximize M becomes minimize 1/2(||β||^2) ?
"Since for any β and β0 satisfying these inequalities, any positively scaled multiple satisfies them too, we can arbitrarily set ||β|| = 1/M." 
y_i(x_i' b + b0) >= M ||b||
thus for any c>0
y_i(x_i' [bc] + [b0c]) >= M ||bc||
thus you can always find such c that ||bc|| = 1/M, so we can focus only on b such that they have such norm (we simply limit the space of possible solutions because we know that scaling does not change much)
Also, how does maximize M becomes minimize 1/2(||β||^2) ?
We put ||b|| = 1/M, thus M=1/||b||
max_b M = max_b 1 / ||b||
now maximization of positive f(b) is equivalent of minimization of 1/f(b), so
min ||b||
and since ||b|| is positive, its minimization is equivalent to minimization of the square, as well as multiplied by 1/2 (this does not change the optimal b)
min 1/2 ||b||^2

How to solve this recursion equation T (n) = √2T(n/2) + log n using master theorem?

I know it can be solved with master method but how ? please help ?
i am not sure if this is correct:
a = sqrt(2)
b = 2
f(n) = log n
log(b) a = log (2) sqrt(2) = 1/2
log n in O[n^(1/2)]
so the runtime of finding the logarithm of a number n is in O{n^(1/2)} (however the Master Theorem can not be applied here)
The solution is in following threads:Solving master theorem with log n: T(n) = 2T(n/4) + log n
Overall, we see that your recurrence is O(n1/2) and Ω(n1/2) by upper- and lower-bounding your recurrence by larger and smaller recurrences. Therefore, even though the Master Theorem doesn't apply here, you can still use the Master Theorem to claim that the runtime will be Θ(n1/2).
Master's theorem with f(n)=log n
Usually, f(n) must be polynomial for the master theorem to apply - it doesn't apply for all functions. However, there is a limited "fourth case" for the master theorem, which allows it to apply to polylogarithmic functions.
https://en.wikipedia.org/wiki/Master_theorem
https://en.wikipedia.org/wiki/Big_O_notation
Ralf is not correct by telling you that you can't apply masters theorem.
The only constrains here is that a >=1 and b >= 1, a, b can be irrational and f(n) can be anything.
Log2(sqrt(2)) is 1/2, which puts you in the first case and your solution is O(n^0.5).

Heuristic path algorithm (Pohl) completeness

This is a homework question, exactly as follows:
The heuristic path algorithm (Pohl, 1977) is a best-first search in which the evaluation function is f(n) = (2-w)g(n) + wh(n).
For what values of w is this complete?
Here's what I know:
w = 0: f(n)=2g(n) --> Uniform Cost Search, which is complete.
w = 1: f(n)=g(n) + h(n) --> A*, which is complete.
w = 2: f(n)=2h(n) --> greedy Best First Search, which is not complete.
What about all other values of w?
Please don't just give the answer, help me get to the solution.
Interesting thing about "all other values of w" for w>2: They all have the form f(n) = h(n) - g(n) with some constants in front of h and g. What impact, if any, does subtracting the cost have on completeness? Seems you should be able to generalize from there.

Resources