big-theta

Order Of Growth complicated for loops

折月煮酒 提交于 2019-12-01 11:53:20
For the following code fragment, what is the order of growth in terms of N? int sum = 0; for (int i = 1; i <= N; i = i*2) for (int j = 1; j <= N; j = j*2) for (int k = 1; k <= i; k++) sum++; I have figured that there is lgN term, but I am stuck on evaluating this part : lgN(1 + 4 + 8 + 16 + ....). What will the last term of the sequence be? I need the last term to calculate the sum. You have a geometric progression in your outer loops, so there is a closed form for the sum of which you want to take the log: 1 + 2 + 4 + ... + 2^N = 2^(N+1) - 1 To be precise, your sum is 1 + ... + 2^(floor(ld(N)

Asymptotic analysis

孤者浪人 提交于 2019-11-29 11:03:27
I'm having trouble understanding how to make this into a formula. for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j += i) { I realize what happens, for every i++ you have 1 level of multiplication less of j. i = 1, you get j = 1, 2, 3, ..., 100 i = 2, you get j = 1, 3, 5, ..., 100 I'm not sure how to think this in terms of Big-theta. The total of j is N, N/2, N/3, N/4..., N/N (My conclusion) How would be best to try and think this as a function of N? So your question can be actually reduced to "What is the tight bound for the harmonic series 1/1 + 1/2 + 1/3 + ... + 1/N?" For which the

The complexity of n choose 2 is in Theta (n^2)?

醉酒当歌 提交于 2019-11-29 06:14:52
问题 I'm reading Introduction to Algorithms 3rd Edition (Cormen and Rivest) and on page 69 in the "A brute-force solution" they state that n choose 2 = Theta (n^2). I would think it would be in Theta (n!) instead. Why is n choose 2 tightly bound to n squared? Thanks! 回答1: n choose 2 is n(n - 1) / 2 This is n 2 / 2 - n/2 We can see that n(n-1)/2 = Θ(n 2 ) by taking the limit of their ratios as n goes to infinity: lim n → ∞ (n 2 / 2 - n / 2) / n 2 = 1/2 Since this comes out to a finite, nonzero

Asymptotic analysis

强颜欢笑 提交于 2019-11-28 04:25:55
问题 I'm having trouble understanding how to make this into a formula. for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j += i) { I realize what happens, for every i++ you have 1 level of multiplication less of j. i = 1, you get j = 1, 2, 3, ..., 100 i = 2, you get j = 1, 3, 5, ..., 100 I'm not sure how to think this in terms of Big-theta. The total of j is N, N/2, N/3, N/4..., N/N (My conclusion) How would be best to try and think this as a function of N? 回答1: So your question can be

Solve recurrence: T(n) = T(n^(1/2)) + Θ(lg lg n) [closed]

馋奶兔 提交于 2019-11-27 20:57:08
Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like T(n) = Tf(n) + g(n) . But I am lost with this recurrence: problem 1-2e : T(n) = T(√n) + Θ(lg lg n) How do I choose the method to find theta? And what, uh, this recurrence is? I just do not quite understand notation-inside-a-recurrence thing. One trick that might useful would be to transform n into something else, like, say, 2 k . If we do this, you can rewrite the above as T(2 k ) = T(2 k/2 ) + Θ(log log 2 k ) = T(2 k ) = T(2 k/2 ) + Θ(log k) Now this looks like a recurrence that we might

Difference between Big-Theta and Big O notation in simple language

喜夏-厌秋 提交于 2019-11-27 20:00:13
问题 While trying to understand the difference between Theta and O notation I came across the following statement : The Theta-notation asymptotically bounds a function from above and below. When we have only an asymptotic upper bound, we use O-notation. But I do not understand this. The book explains it mathematically, but it's too complex and gets really boring to read when I am really not understanding. Can anyone explain the difference between the two using simple, yet powerful examples . 回答1:

Solve recurrence: T(n) = T(n^(1/2)) + Θ(lg lg n) [closed]

非 Y 不嫁゛ 提交于 2019-11-26 20:29:54
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like T(n) = Tf(n) + g(n) . But I am lost with this recurrence: problem 1-2e: T(n) = T(√n) + Θ(lg lg n) How do I choose the method to find theta? And what, uh, this recurrence is? I just do not quite understand notation

What exactly does big Ө notation represent?

寵の児 提交于 2019-11-26 00:18:44
问题 I\'m really confused about the differences between big O, big Omega, and big Theta notation. I understand that big O is the upper bound and big Omega is the lower bound, but what exactly does big Ө (theta) represent? I have read that it means tight bound , but what does that mean? 回答1: It means that the algorithm is both big-O and big-Omega in the given function. For example, if it is Ө(n) , then there is some constant k , such that your function (run-time, whatever), is larger than n*k for

What is the difference between Θ(n) and O(n)?

不打扰是莪最后的温柔 提交于 2019-11-25 22:36:11
问题 Sometimes I see Θ(n) with the strange Θ symbol with something in the middle of it, and sometimes just O(n). Is it just laziness of typing because nobody knows how to type this symbol, or does it mean something different? 回答1: Short explanation: If an algorithm is of Θ(g(n)), it means that the running time of the algorithm as n (input size) gets larger is proportional to g(n). If an algorithm is of O(g(n)), it means that the running time of the algorithm as n gets larger is at most