complexity-theory

Can OSGi help reduce complexity?

烈酒焚心 提交于 2019-12-03 04:49:59
问题 I saw lots of presentations on OSGi and i think it sounds promising for enforcing better modularization. Apparently "hotdeployment" and "running different versions of x in parallel" are mayor selling points too. I wonder whether what OSGi promises to solve is even an issue...? It reminded me of the early days of OO when similar claims were maid: When OO was new, the big argument was reusability. It was widely claimed that when using OO, one would only have to "write once" and could then "use

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

半城伤御伤魂 提交于 2019-12-03 04:36:39
问题 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 8 years ago . 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. 回答1: This cannot be solved by the Master Theorem. However, it can be solved using the recursion tree method

Way to store a large dictionary with low memory footprint + fast lookups (on Android)

此生再无相见时 提交于 2019-12-03 03:59:08
问题 I'm developing an android word game app that needs a large (~250,000 word dictionary) available. I need: reasonably fast look ups e.g. constant time preferable, need to do maybe 200 lookups a second on occasion to solve a word puzzle and maybe 20 lookups within 0.2 second more often to check words the user just spelled. EDIT: Lookups are typically asking "Is in the dictionary?". I'd like to support up to two wildcards in the word as well, but this is easy enough by just generating all

Is “house coloring with three colors” NP?

瘦欲@ 提交于 2019-12-03 03:41:10
Consider the problem described here (reproduced below.) Can some better known NP-complete problem be reduced to it? The problem: There are a row of houses. Each house can be painted with three colors: red, blue and green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color. You have to paint the houses with minimum cost. How would you do it? Note: The cost of painting house 1 red is different from that of painting house 2 red. Each combination of house and color has its own cost. Knoothe No, it

In-order traversal complexity in a binary search tree (using iterators)?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 03:25:58
Related question: Time Complexity of InOrder Tree Traversal of Binary Tree O(N)? , however it is based on a traversal via recursion (so in O(log N) space) while iterators allow a consumption of only O(1) space. In C++, there normally is a requirement that incrementing an iterator of a standard container be a O(1) operation. With most containers it's trivially proved, however with map and such, it seems a little more difficult. If a map were implemented as a skip-list, then the result would be obvious However they are often implemented as red-black trees (or at least as binary search trees) So,

The “pattern-filling with tiles” puzzle

不问归期 提交于 2019-12-03 03:17:27
问题 I've encountered an interesting problem while programming a random level generator for a tile-based game. I've implemented a brute-force solver for it but it is exponentially slow and definitely unfit for my use case. I'm not necessarily looking for a perfect solution, I'll be satisfied with a “good enough” solution that performs well. Problem Statement: Say you have all or a subset of the following tiles available (this is the combination of all possible 4-bit patterns mapped to the right,

Assigning people to buildings while respecting preferences?

允我心安 提交于 2019-12-03 02:55:18
A friend asked me a question today about an assignment problem. I found a quite straightforward solution, but I feel that it can be made simpler and faster. Your help would be appreciated. The problem: Assuming that I have N people, I need to assign them into M buildings, each building can house K people. Not all people are willing to live with each other, so i have a matrix of N*N cells and a 1 that marks the people that are willing to live with each other. If a cell contains 1 it means that I and J can live together. Obviously the matrix is symmetrical around the main diagonal. My solution

Are there any real O(n^n) algorithms?

筅森魡賤 提交于 2019-12-03 01:10:49
Is there any real Algorithm with a time complexity O(n^n), that isn't just a gimmick? I can create such an Algorithm, like computing n^n in O(n^n) / Θ(n^n): long n_to_the_power_of_m(int n, int m) { if(m == 0) return 1; long sum = 0; for(int i = 0; i < n; ++i) sum += n_to_the_power_of_m(n, m-1); return sum; } (needs more than 4 minutes to compute 10^10) Or other way around: Are there any Problems, which cannot be solved better than in O(n^n)? What you have coded in your example is very similar to a depth first search. So, that's one answer. A depth first search algorithm without any special

Understanding How Many Times Nested Loops Will Run

时光怂恿深爱的人放手 提交于 2019-12-03 00:32:10
I am trying to understand how many times the statement "x = x + 1" is executed in the code below, as a function of "n": for (i=1; i<=n; i++) for (j=1; j<=i; j++) for (k=1; k<=j; k++) x = x + 1 ; If I am not wrong the first loop is executed n times, and the second one n(n+1)/2 times, but on the third loop I get lost. That is, I can count to see how many times it will be executed, but I can't seem to find the formula or explain it in mathematical terms. Can you? By the way this is not homework or anything. I just found on a book and thought it was an interesting concept to explore. Consider the

Why is the complexity of A* exponential in memory?

北城余情 提交于 2019-12-03 00:25:37
Wikipedia says on A* complexity the following ( link here ): More problematic than its time complexity is A*’s memory usage. In the worst case, it must also remember an exponential number of nodes. I fail to see this is correct because: Say we explore node A, with successors B, C, and D. Then we add B, C, and D to the list of open nodes, each accompanied by a reference to A, and we move A from the open nodes to the closed nodes. If at some time we find another path to B (say, via Q), that is better than the path through A, then all that is needed is to change B's reference to A to point to Q