recurrence

How to solve this recurrence relation: T(n) = 4*T(sqrt(n)) + n

血红的双手。 提交于 2019-11-28 12:30:36
问题 I know how to solve the recurrence relations using Master Method. Also I'm aware of how to solve the recurrences below: T(n) = sqrt(n)*T(sqrt(n)) + n T(n) = 2*T(sqrt(n)) + lg(n) In the above two recurrences there is same amount of work at each level of the recursion tree. And there are a total of log log n levels in the recursion tree. I'm having trouble in solving this one: T(n) = 4*T(sqrt(n)) + n EDIT: Here n is a power of 2 回答1: Suppose that n = 2^k. We have T(2^k) = 4*T(2^(k/2)) + 2^k.

Reccurrence T(n) = T(n^(1/2)) + 1

允我心安 提交于 2019-11-28 10:18:06
I've been looking at this reccurrence and wanted to check if I was taking the right approach. T(n) = T(n^(1/2)) + 1 = T(n^(1/4)) + 1 + 1 = T(n^(1/8)) + 1 + 1 + 1 ... = 1 + 1 + 1 + ... + 1 (a total of rad n times) = n^(1/2) So the answer would come to theta bound of n^(1/2) hint: assume n = 2 2 m or m = log 2 log 2 n, and you know 2 2 m-1 * 2 2 m-1 = 2 2 m so, if you define S(m)=T(n) your S will be: S(m) = S(m-1)+1 → S(m) = Θ(m) → S(m)=T(n) = Θ(log 2 log 2 n) extend it for the general case. In recursion like T(n) = T(n/2) + 1, in each iteration, we reduce the height of the tree to half. This

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

n log n is O(n)?

老子叫甜甜 提交于 2019-11-27 17:38:09
I am trying to solve this recurrence T(n) = 3 T(n/2) + n lg n .. I have come to the solution that it belongs to masters theorem case 2 since n lg n is O(n^2) but after referring to the solution manual i noticed this solution that they have The soluttion says that n lg n = O ( n ^(lg 3 - e)) for e between 0 and 0.58 so this means n lg n is O(n) .. is this right? Am i missing something here? Isn't nlgn O(n^2) ? This will explain things better n*log(n) is not O(n^2) . It's known as quasi-linear and it grows much slower than O(n^2) . In fact n*log(n) is less than polynomial. In other words: O(n

Should I store dates or recurrence rules in my database when building a calendar app?

萝らか妹 提交于 2019-11-27 16:56:06
I am building a calendar website ( ASP.NET MVC ) application (think simple version of outlook) and i want to start supporting calendar events that are recurring (monthly, yearly, etc) right now I am storing actual dates in my but I wanted to figure out if, with recurrence, does it make sense to continue to store dates (with some obvious cutoff), or should I store the recurrence options and generate the dates on the fly. It got me thinking how outlook, google mail, etc does this or any other service that supports recurring calendar items. Are there any suggestions on this? Separate your data

How to solve: T(n) = T(n - 1) + n

巧了我就是萌 提交于 2019-11-27 15:33:54
I have the following worked out: T(n) = T(n - 1) + n = O(n^2) Now when I work this out I find that the bound is very loose. Have I done something wrong or is it just that way? Think of it this way: In each "iteration" of the recursion you do O(n) work. Each iteration has n-1 work to do, until n = base case. (I'm assuming base case is O(n) work) Therefore, assuming the base case is a constant independant of n, there are O(n) iterations of the recursion. If you have n iterations of O(n) work each, O(n)*O(n) = O(n^2). Your analysis is correct. If you'd like more info on this way of solving

Understanding recursion in Python

有些话、适合烂在心里 提交于 2019-11-27 14:53:05
I'm really trying to wrap my brain around how recursion works and understand recursive algorithms. For example, the code below returns 120 when I enter 5, excuse my ignorance, and I'm just not seeing why? def fact(n): if n == 0: return 1 else: return n * fact(n-1) answer = int (raw_input('Enter some number: ')) print fact(answer) lets walk through the execution. fact(5): 5 is not 0, so fact(5) = 5 * fact(4) what is fact(4)? fact(4): 4 is not 0, so fact(4) = 4 * fact(3) what is fact(3)? fact(3): 3 is not 0, so fact(3) = 3 * fact(2) what is fact(2)? fact(2): 2 is not 0, so fact(2) = 2 * fact(1)

Number of 1s in the two's complement binary representations of integers in a range

北城余情 提交于 2019-11-27 04:19:35
问题 This problem is from the 2011 Codesprint (http://csfall11.interviewstreet.com/): One of the basics of Computer Science is knowing how numbers are represented in 2's complement. Imagine that you write down all numbers between A and B inclusive in 2's complement representation using 32 bits. How many 1's will you write down in all ? Input: The first line contains the number of test cases T (<1000). Each of the next T lines contains two integers A and B. Output: Output T lines, one corresponding

Reccurrence T(n) = T(n^(1/2)) + 1

拟墨画扇 提交于 2019-11-27 02:51:29
问题 I've been looking at this reccurrence and wanted to check if I was taking the right approach. T(n) = T(n^(1/2)) + 1 = T(n^(1/4)) + 1 + 1 = T(n^(1/8)) + 1 + 1 + 1 ... = 1 + 1 + 1 + ... + 1 (a total of rad n times) = n^(1/2) So the answer would come to theta bound of n^(1/2) 回答1: hint: assume n = 2 2 m or m = log 2 log 2 n, and you know 2 2 m-1 * 2 2 m-1 = 2 2 m so, if you define S(m)=T(n) your S will be: S(m) = S(m-1)+1 → S(m) = Θ(m) → S(m)=T(n) = Θ(log 2 log 2 n) extend it for the general

What's the best way to model recurring events in a calendar application?

て烟熏妆下的殇ゞ 提交于 2019-11-26 21:12:38
I'm building a group calendar application that needs to support recurring events, but all the solutions I've come up with to handle these events seem like a hack. I can limit how far ahead one can look, and then generate all the events at once. Or I can store the events as repeating and dynamically display them when one looks ahead on the calendar, but I'll have to convert them to a normal event if someone wants to change the details on a particular instance of the event. I'm sure there's a better way to do this, but I haven't found it yet. What's the best way to model recurring events, where