recurrence

How would you store possibly recurring times?

南楼画角 提交于 2019-12-03 03:28:38
I need to store whether something happens once, daily, weekdays, weekly, some days of the week, some days of the month, which may be numerical or symbolic, like first Monday of each month, and so on. Any recommendations? Any code, data structure or schema to look at? There are complex solutions and easy solutions. The two easiest solutions are: Fan out recurring events up to some constant number of instances, or up to some fixed date range in the future. Store a FK recurrence_id with each instance that points to a description of the recurrence, and allows for mass editing and canceling. The

Determining the complexities given codes

旧城冷巷雨未停 提交于 2019-12-03 01:39:51
问题 Given a snipplet of code, how will you determine the complexities in general. I find myself getting very confused with Big O questions. For example, a very simple question: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.println("*"); } } The TA explained this with something like combinations. Like this is n choose 2 = (n(n-1))/2 = n^2 + 0.5, then remove the constant so it becomes n^2. I can put int test values and try but how does this combination thing come in? What

Non-Linear Recurrence Relation

青春壹個敷衍的年華 提交于 2019-12-03 00:51:37
How can I find Nth term for this recurrence relation F(n) = F(n-1) + F(n-2) + F(n-1)*F(n-2) I have to find Nth term for this recurrence relation modulo 10^9+7 . I know how to find Nth term for linear recurrence relations but unable to proceed for this. 1<=N<=10^9 F(0) and F(1) are provided as an input. There's a trick. Let G(n) = F(n) + 1 . The equation F(n) = F(n-1) + F(n-2) + F(n-1)*F(n-2) becomes G(n) - 1 = G(n-1) - 1 + G(n-2) - 1 + (G(n-1) - 1) * (G(n-2) - 1) = G(n-1) - 1 + G(n-2) - 1 + G(n-1)*G(n-2) - G(n-1) - G(n-2) + 1 = G(n-1)*G(n-2) - 1, so adding 1 to both sides, G(n) = G(n-1)*G(n-2)

Solving the recurrence relation T(n) = √n T(√n) + n [closed]

£可爱£侵袭症+ 提交于 2019-12-02 18:53:42
Is it possible to solve the recurrence relation T(n) = √n T(√n) + n Using the Master Theorem? It is not of the form T(n) = a ⋅ T(n / b) + f(n) but this problem is given in the exercise of CLRS chapter 4. This cannot be solved by the Master Theorem. However, it can be solved using the recursion tree method to resolve to O(n log log n). The intuition behind this is to notice that at each level of the tree, you're doing n work. The top level does n work explicitly. Each of the √n subproblems does √n work for a net total of n work, etc. So the question now is how deep the recursion tree is. Well,

Whats the best java date recurrence pattern calculator

巧了我就是萌 提交于 2019-12-01 05:16:05
Anyone know of a (reliable) date recurrence calculator, we're trying to implement something in our app which would allow a schedule to be created, similar to those for recurring meetings in Outlook. We have tried chronos but discovered some cases where it breaks down, I'd really appreciate knowing if anyone has successfully used any of the other options out there. Cheers, Robin This is a frequent question on the joda time mailing list and the usual answer is to try RFC 2445 . Disclaimer: I have not used it myself. Check out Lamma date (I wrote it recently), which is designed to generate dates

Complexity of the recursion: T(n) = T(n-1) + T(n-2) + C

非 Y 不嫁゛ 提交于 2019-12-01 04:32:58
I want to understand how to arrive at the complexity of the below recurrence relation. T(n) = T(n-1) + T(n-2) + C Given T(1) = C and T(2) = 2C; Generally for equations like T(n) = 2T(n/2) + C (Given T(1) = C), I use the following method. T(n) = 2T(n/2) + C => T(n) = 4T(n/4) + 3C => T(n) = 8T(n/8) + 7C => ... => T(n) = 2^k T (n/2^k) + (2^k - 1) c Now when n/2^k = 1 => K = log (n) (to the base 2) T(n) = n T(1) + (n-1)C = (2n -1) C = O(n) But, I'm not able to come up with similar approach for the problem I have in question. Please correct me if my approach is incorrect. The complexity is related

Complexity of the recursion: T(n) = T(n-1) + T(n-2) + C

假装没事ソ 提交于 2019-12-01 02:51:14
问题 I want to understand how to arrive at the complexity of the below recurrence relation. T(n) = T(n-1) + T(n-2) + C Given T(1) = C and T(2) = 2C; Generally for equations like T(n) = 2T(n/2) + C (Given T(1) = C), I use the following method. T(n) = 2T(n/2) + C => T(n) = 4T(n/4) + 3C => T(n) = 8T(n/8) + 7C => ... => T(n) = 2^k T (n/2^k) + (2^k - 1) c Now when n/2^k = 1 => K = log (n) (to the base 2) T(n) = n T(1) + (n-1)C = (2n -1) C = O(n) But, I'm not able to come up with similar approach for

Relational Schema for Fowler's Temporal Expressions

可紊 提交于 2019-11-30 10:19:23
问题 Martin Fowler defines an elegant object model for the scheduling of recurring tasks here, which maps to OO code very nicely. Mapping this to a relational database schema for persistence, however, is tricky. Can anyone suggest a schema + SQL combination that encapsulates all the functionality he describes, particularly in the image on page 11. Intersects and Unions are fairly obvious - the complexity lies in representing the 'Temporal Expressions', which take variable parameters and must be

How can I compute the number of characters required to turn a string into a palindrome?

偶尔善良 提交于 2019-11-30 07:06:10
问题 I recently found a contest problem that asks you to compute the minimum number of characters that must be inserted (anywhere) in a string to turn it into a palindrome. For example, given the string: "abcbd" we can turn it into a palindrome by inserting just two characters: one after "a" and another after "d": "a d bcbd a ". This seems to be a generalization of a similar problem that asks for the same thing, except characters can only be added at the end - this has a pretty simple solution in

How can I compute the number of characters required to turn a string into a palindrome?

六眼飞鱼酱① 提交于 2019-11-28 23:15:41
I recently found a contest problem that asks you to compute the minimum number of characters that must be inserted (anywhere) in a string to turn it into a palindrome. For example, given the string: "abcbd" we can turn it into a palindrome by inserting just two characters: one after "a" and another after "d": "a d bcbd a ". This seems to be a generalization of a similar problem that asks for the same thing, except characters can only be added at the end - this has a pretty simple solution in O(N) using hash tables. I have been trying to modify the Levenshtein distance algorithm to solve this