asymptotic-complexity

How do I perform a deletion of the kth element on a min-max heap?

邮差的信 提交于 2019-12-04 19:06:39
A min-max heap can be useful to implement a double-ended priority queue because of its constant time find-min and find-max operations. We can also retrieve the minimum and maximum elements in the min-max heap in O(log 2 n) time. Sometimes, though, we may also want to delete any node in the min-max heap, and this can be done in O(log 2 n) , according to the paper which introduced min-max heaps : ... The structure can also be generalized to support the operation Find(k) (determine the kth smallest value in the structure) in constant time and the operation Delete(k) (delete the kth smallest value

Difference between O(m+n) and O(mn)?

隐身守侯 提交于 2019-12-04 17:08:35
I was trying to find the complexities of an algorithm via different approaches. Mathematically I came across one O(m+n) and another O(mn) approach. However I am unable to grasp or say visualize this. It's not like I look at them and get the "Ahh! That's what's going on" feeling! Can someone explain this using their own examples or any other tool? My recommendation for finding intuition is thought experiments as follows: First, realize that m and n are two different measurements of the input . They might be the lengths of two input streams, the lengths of sides of a matrix, or the counts of two

Merge sort worst case running time for lexicographic sorting?

旧巷老猫 提交于 2019-12-04 17:04:35
A list of n strings each of length n is sorted into lexicographic order using the merge sort algorithm. The worst case running time of this computation is? I got this question as a homework. I know merge sort sorts in O(nlogn) time. For lexicographic order for length in is it n times nlogn ? or n^2 ? amit Each comparison of the algorithm is O(n) [comparing two strings is O(n) worst case - you might detect which is "bigger" only on the last character], You have O(nlogn) comparisons in mergesort. Thus you get O(nlogn * n) = O(n^2 * logn) But according to the recurrence relation T(n) = 2T(n/2) +

why O(2n^2) and O(100 n^2) same as O(n^2) in algorithm complexity?

北战南征 提交于 2019-12-04 16:48:06
I am new in the algorithm analysis domain. I read here in the Stack Overflow question " What is a plain English explanation of "Big O" notation? " that O(2n^2) and O(100 n^2) are the same as O(n^2) . I don't understand this, because if we take n = 4, the number of operations will be: O(2 n^2) = 32 operations O(100 n^2) = 1600 operations O(n^2) = 16 operations Can any one can explain why we are supposed to treat these different operation counts as equivalent? Why this is true can be derived directly from the formal definition . More specifically, f(x) = O(g(n)) if and only if |f(x)| <= M|g(x)|

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

让人想犯罪 __ 提交于 2019-12-04 15:13:54
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? 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 or better expectations were cooled down by principal limitations these computing-device architectures still

Graph In-degree Calculation from Adjacency-list

独自空忆成欢 提交于 2019-12-04 08:33:57
I came across this question in which it was required to calculate in-degree of each node of a graph from its adjacency list representation. for each u for each Adj[i] where i!=u if (i,u) ∈ E in-degree[u]+=1 Now according to me its time complexity should be O(|V||E|+|V|^2) but the solution I referred instead described it to be equal to O(|V||E|) . Please help and tell me which one is correct. Corneliu Rather than O(|V||E|), the complexity of computing indegrees is O(|E|). Let us consider the following pseudocode for computing indegrees of each node: for each u indegree[u] = 0; for each u for

Are 2^n and 4^n in the same Big-Θ complexity class?

◇◆丶佛笑我妖孽 提交于 2019-12-04 06:37:50
Is 2^n = Θ(4^n)? I'm pretty sure that 2^n is not in Ω(4^n) thus not in Θ(4^n), but my university tutor says it is. This confused me a lot and I couldn't find a clear answer per Google. chiwangc 2^n is NOT big-theta (Θ) of 4^n , this is because 2^n is NOT big-omega (Ω) of 4^n . By definition, we have f(x) = Θ(g(x)) if and only if f(x) = O(g(x)) and f(x) = Ω(g(x)) . Claim 2^n is not Ω(4^n) Proof Suppose 2^n = Ω(4^n) , then by definition of big-omega there exists constants c > 0 and n0 such that: 2^n ≥ c * 4^n for all n ≥ n0 By rearranging the inequality, we have: (1/2)^n ≥ c for all n ≥ n0 But

Juggling Algorithm

自作多情 提交于 2019-12-04 06:28:51
问题 METHOD (A Juggling Algorithm) Divide the array in different sets where number of sets is equal to GCD of n and d and move the elements within sets. If GCD is 1 as is for the above example array (n = 7 and d =2), then elements will be moved within one set only, we just start with temp = arr[0] and keep moving arr[I+d] to arr[I] and finally store temp at the right place. Here is an example for n =12 and d = 3. GCD is 3 and Let arr[] be {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} a) Elements are

How the time complexity of the following code is O(n)?

痞子三分冷 提交于 2019-12-04 06:17:55
问题 I was solving a time-complexity question on Interview Bit, which is given below in the image. The correct answer to this question is O(N). But according to me, the answer should be O(NlogN). Since the complexity for the first "for loop" should be O(logN) because the variable i is divided by 2 in each iteration and I have studied that whenever the loop variables are either multiplied or divided by 2, then the time complexity is O(logN). Now, for the second "for loop", the complexity should be

Which pair of functions satisfy f (N) ~g(N)?

天大地大妈咪最大 提交于 2019-12-04 06:04:14
问题 I've just started working with algorithms and I am doing some tasks like this question: I think, the right answer is A. As the functions are the same, or do I miss something? Question: 回答1: The answer is A. Notice that in that case, f(N) = N + 2N + 3N = 6N = g(N) so f(N) ~ g(N). For the functions given in B, notice that f(N) = (N + 1) + (N + 2) + (N + 3) = 3N + 6 so the limit of f(N) / g(N) as N tends toward infinity is 3, and therefore f(N) is not tilde of g(N). For the functions in C,