Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I am doing a data structures and algorithms paper in which recurrence relations are being taught.
The question is as follows:
From what I understand from this question, n will keep on being halved over and over again. So what you are left with is 1/32n^2 + 1/16n^2 + 1/8n^2 + 1/4n^2 + 1/2n^2 + n^2. All the fractions sum to 1. So you're left with n^2 +n^2 = 2n^2.
However this is not a possible solution.
Can somebody please help me understand how to calculate these recurrence relations correctly, or point me in the right direction because I am having a lot of trouble with this topic and any help with be greatly appreciated.
Thank you for your time.
You might want to look at the Master Theorem
In the wiki, a = 1, b = 2, c = 2, where T(n) = aT(n/b) + n^c
Case 3 applies, since 2 > 0 = log_2(1)
Thus, by the master theorem, T = Big-Theta(n^c) = Big_Theta(n^2).
Choice B has a n^2 term, so that should be your answer.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to write macro to pick up slices which I would like to include in my MIP. So far it looks like this:
LowerStack = getNumber("prompt", 10);
UpperStack = getNumber("prompt", 10);
run("Z Project...", "start=" + LowerStack) ("stop=" + UpperStack) ("projection=[Max Intensity]");
It recognizes the Lower slice which I want to pick up, but not the upper one.
Any suggestions on what do I do wrong?
The syntax of the third line is incorrect. This works:
LowerStack = getNumber("Lower", 10);
UpperStack = getNumber("Upper", 10);
run("Z Project...", "start=" + LowerStack + " stop=" + UpperStack + " projection=[Max Intensity]");
Note that I also changed the string in the two prompts because you would likely get an error by them not being unique.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm practicing F# for the first time and I thought I'd try to make a program that would calculate the areas of different kinds of shapes. However, the portion that finds the area of a circle is giving me a lot of trouble.enter code here
elif stringInput = "2" then
let PI = 3.14156
printfn "What is the circle's radius: "
let radiusString = System.Console.ReadLine()
let radiusInt = radiusString |> float
let cirlceArea = (radiusInt * radiusInt) * PI
printfn "The area of the circle is : %d" cirlceArea
I'm sure it has something to do with the radiusString |> float part of the code, but nothing I've tried works and I've had no luck in finding any examples that can help. What can I do?
Ok I just found out the problem was that I was using %d instead of %f
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
In Python, create a function finding all integers between 1 and 1.000.000.000, which are equal to the sum of k'th power of its digits for some k.
Example: 4150 = 4^5 + 1^5 + 5^5 + 0^5.
Here is my code working perfect until 1.000.000. However, it becomes so slow for large numbers. I try Numpy but it does not work. Any improvement would be welcome. ^^ (Any library or python function you may use)
def powers(n):
s = []
for number in range(1, 10 ** n):
number_list = [int(x) for x in str(number)]
if max(number_list) > 1:
total = 0
power = 1
while total < number:
total = sum([y ** power for y in number_list])
if total == number:
s.append((number, power))
power += 1
return s
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
T(n) = n + T(n/2)
= n + n/2 + T(n/4)
= n + n/2 + n/4 + T(n/8)
= n + n/2 + n/4 + ... + n/(2^(k-1)) + T(n/2^k)
->>>
and I don't know how to go on to get big Oh formula.
please help me
I'm assuming there's some kind of initial condition like T(1) = 0 that you are not telling us.
If so, the answer is O(log n).
Think about how you would work out T(2), T(4), T(8), T(16) etc. Each one requires just one extra step.
T(1) = T(2^0) calls the method recursively 0 times.
T(2) = T(2^1) calls the method recursively 1 time
T(4) = T(2^2) calls the method recursively 2 times
T(8) = T(2^3) calls the method recursively 3 times
In other words, the number of steps is the power. This means that you have to take logarithms to get the answer.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've been using the simple_statistics gem, but im looking to calculate the EMA on the last x records. For example (when calculating WMA)
#stockticker.ema10 = s.stocktickers.last(10).map(&:current_price).map{|f| f.to_f}.wma
I was wondering if anyone can provide advise on how I got about calculating the EMA in rails?
It looks like the Moving Averages gem might be what you're looking for. Here is a copy of their exponential_moving_average method for reference as well.
class Array
def exponential_moving_average(idx=nil, tail=nil)
idx, tail = idx_and_tail_or_defaults(idx, tail)
valid_for_ma(idx, tail)
alpha = 2.0 / (tail + 1)
n = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1) * self[idx - tidx + 1]}.sum
d = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1)}.sum
n / d
end
alias_method :ema, :exponential_moving_average
end
I am the developer of Statsample-timeseries gem which is an extension of Statsample, an advance statistical suite in Ruby. It has quite many statistical methods (including EMA) which you can perform on your data.
If you need any assistance, I will be very happy to help out. :)