asymptotic-complexity

Algorithm asymptotic-complexity

我是研究僧i 提交于 2019-12-11 03:03:49
问题 I would like to know what is the minimum and maximum value this procedure can return in the following algorithm using the big-theta notation. The algorithm is: procedure F(𝐴[1..n]) s = 0 for i = 1 to n j = min(max(i,A[i]),n³) s = s + j return s 回答1: EDIT: removed original answer as it was for the wrong question. The analysis hinges on the following line: min(max(i,A[i]),n³) If we figure out the cases for this then we can easily figure the cases for the result. We must answer whether i > A[i]

Asymptotic complexity of logarithmic functions

我们两清 提交于 2019-12-10 13:47:40
问题 I know that in terms of complexity, O(logn) is faster than O(n), which is faster than O(nlogn), which is faster than O(n2). But what about O(n2) and O(n2log), or O(n2.001) and O(n2log): T1(n)=n^2 + n^2logn What is the big Oh and omega of this function? Also, what's little oh? versus: T2(n)=n^2.001 + n^2logn Is there any difference in big Oh now? I'm having trouble understanding how to compare logn with powers of n. As in, is logn approximately n^0.000000...1 or n^1.000000...1? 回答1: O(n^k) is

the asymptotic growth of n choose floor(n/2)

百般思念 提交于 2019-12-10 11:13:26
问题 How can I find the asymptotic growth of n choose floor(n/2) ? I tried to use the expansion and got that it is equal to [n*(n-1)*........*(floor(n/2)+1)] / (n-floor(n/2))! Any idea how can i go from there? Any help is appreciated, prefer hints over answers 回答1: Using Stirling's approximation, you get n! = \sqrt{2n\pi}(n/e)^n If you substitute it into $\choose{n}{n/2}$, you should eventually end up with 2^{n+1/2}/\sqrt{n\pi} PS. you might want to check my math before you actually use the answer

How to solve for this recurrence T(n) = T(n − 1) + lg(1 + 1/n), T(1) = 1?

对着背影说爱祢 提交于 2019-12-10 09:20:31
问题 I got stuck in this recurrence: T(n) = T(n − 1) + lg(1 + 1/n), T(1) = 1? for a while and it seems the master method cannot be applied on this one. 回答1: We have: lg(1 + 1/n) = lg((n + 1) / n) = lg(n+1) - lg(n) Hence: T(n) - T(n - 1) = lg(n + 1) - lg(n) T(n-1) - T(n - 2) = lg(n) - lg(n - 1) ... T(3) - T(2) = lg(3) - lg(2) T(2) - T(1) = lg(2) - lg(1) Adding and eliminating, we get: T(n) - T(1) = lg(n + 1) - lg(1) = lg(n + 1) or T(n) = 1 + lg(n + 1) Hence T(n) = O(lg(n)) 回答2: Same answer as the

What is the difference between Work, Span and Time in parallel algorithm analysis?

做~自己de王妃 提交于 2019-12-09 19:57:12
问题 When analysing parallel algorithms, we tend to focus Work(T1), Span(T∞) or time. What I'm confused about is that if I was given an algorithm to analyse, what key hints would I need to look for, for Work, span and time? Suppose this algorithm: How do I analyse the above algorithm to find the Work, Time and span? 回答1: Origin: PRAM s have been introduced in early 70-ies last century, in a hope it may allow to jump ahead a performance in tackling computationally hard problems. Yet, the promises

Solving the recurrence T(n) = T(n/2) + T(n/4) + T(n/8)?

泪湿孤枕 提交于 2019-12-09 07:01:45
问题 I'm trying to solve a recurrence T(n) = T(n/8) + T(n/2) + T(n/4) . I thought it would be a good idea to first try a recurrence tree method, and then use that as my guess for substitution method. For the tree, since no work is being done at the non-leaves levels, I thought we could just ignore that, so I tried to come up with an upper bound on the # of leaves since that's the only thing that's relevant here. I considered the height of the tree taking the longest path through T(n/2) , which

Does a useful Haskell HashMap/HashTable/Dictionary library exist?

送分小仙女□ 提交于 2019-12-09 02:51:51
问题 I'm looking for a monad-free, constant access query O(1) associative array. Consider the hypothetical type: data HT k v = ??? I want to construct an immutable structure once: fromList :: Foldable t, Hashable k => t (k,v) -> HT k v I want to subsequently query it repeatedly with constant time access:: lookup :: Hashable k => HT k v -> k -> Maybe v There appears to be two candidate libraries which fall short: unordered-containers hashtables unordered-containers unordered-containers contains

Is there any implementation to Remove by Key and get the Value at the same time?

一世执手 提交于 2019-12-08 17:22:55
问题 I'm doing a performance critical program (little academic stuff) and I'm looking to optimize wherever possible (not like it proved "this is the" bottleneck). I have a custom dictionary structure (a wrapper around .NET Dictionary<,> ) and I would constantly Remove items at one stage (by the Key value). I need the Value of the removed items. Right now I have to do: T t; if !TryGet(key, out t) return false; Remove(key); That's two lookups. I would love this: public bool Remove(S key, out T value

Why is time complexity O(1) for pow(x,y) while it is O(n) for x**y?

拟墨画扇 提交于 2019-12-08 17:19:20
问题 Why is time complexity O(1) of pow(x,y) while it is O(n) for x ** y ? Check comment from agf here 回答1: The statement is wrong. pow is more or less identical to ** . pow and ** do integer exponentiation if their arguments are integers. (Python 3 has automatic bignum support, so, for example, a ** b always gives the exact integral result, even if a or b are very large.) This takes O(log(b)) multiplications with exponentiation by squaring, but bignum multiplication isn't constant time, so the

Asymptotic complexity of .NET collection classes

和自甴很熟 提交于 2019-12-08 14:56:35
问题 Are there any resources about the asymptotic complexity (big-O and the rest) of methods of .NET collection classes ( Dictionary<K,V> , List<T> etc...)? I know that the C5 library's documentation includes some information about it (example), but I'm interested in standard .NET collections too... (and PowerCollections' information would also be nice). 回答1: MSDN Lists these: Dictionary<,> List<> SortedList<,> (edit: wrong link; here's the generic version) SortedDictionary<,> etc. For example: