complexity-theory

Is there any practical application of Tango Trees?

大兔子大兔子 提交于 2019-12-05 03:50:51
Balanced binary search tree gives an O(log(n)) guaranteed search time. Tango trees achieves a search of O(log(log(n)) while compromising small amount of memory per node. While I understand that from theoretical point of view log(n) and log(log(n)) makes a huge difference, for majority of practical applications it provides almost no advantage. For example even for a huge number like n = 10^20 (which is like few thousand petabytes) the difference between log(n) = 64 and log(log(n)) = 6 is pretty negligible. So is there any practical usage of a Tango tree? tl;dr: no, use a splay tree instead.

McCabe Cyclomatic Complexity for switch in Java

五迷三道 提交于 2019-12-05 03:43:31
I am using a switch statement with 13 cases, each case only has an one line return value. McCabe paints this in red. Is there an easier way to write a big switch statement? It doesn't seem complex to read, but I don't like the default setting turning red. If other people use the same tool on my code and see red stuff they might think I'm stupid :-) Edit: I'm mapping different SQL-Types to my own more abstract types, therefore reducing the total amount of types. case Types.TIME: return AbstractDataType.TIME; case Types.TIMESTAMP: return AbstractDataType.TIME; case Types.DATE: return

I have a new algorithm to find factors or primes in linear time - need verification for this

旧城冷巷雨未停 提交于 2019-12-05 03:00:55
I have developed an algorithm to find factors of a given number. Thus it also helps in finding if the given number is a prime number. I feel this is the fastest algorithm for finding factors or prime numbers. This algorithm finds if a give number is prime in time frame of 5*N (where N is the input number). So I hope I can call this a linear time algorithm. How can I verify if this is the fastest algorithm available? Can anybody help in this matter? (faster than GNFS and others known) Algorithm is given below Input: A Number (whose factors is to be found) Output: The two factor of the Number.

How to measure complexity of a string?

拜拜、爱过 提交于 2019-12-05 02:37:41
I have a few long strings (~ 1.000.000 chars). Each string only contains symbols from the defined alphabet, for example A = {1,2,3} Sample strings string S1 = "1111111111 ..."; //[meta complexity] = 0 string S2 = "1111222333 ..."; //[meta complexity] = 10 string S3 = "1213323133 ..."; //[meta complexity] = 100 Q What kind of measures can I use to quantify the complexity of these strings? I can see that S1 is less complex than S3, but how can I do that programmatically from .NET? Any algorithm or point to the tool/literature would be greatly appreciated. Edit I tried Shannon entropy, but it

Random sequence iteration in O(1) memory?

夙愿已清 提交于 2019-12-05 01:19:59
Say you want to iterate over a sequence [0 to n] in a random order, visiting every element exactly once. Is there any way to do this in O (1) memory, i.e. without creating an [1..n] sequence with std::iota and running it through std::random_shuffle ? Some kind of iterator spitting out the sequence in a random order would be optimal. A requirement is that it should be possible to get another random order by picking another seed. In theory, if you built a random number generator whose period was exactly n , and covered all values in 0..n, then running through this once would give you what you

What is the complexity of matrix addition?

拟墨画扇 提交于 2019-12-05 00:43:37
I have found some mentions in another question of matrix addition being a quadratic operation . But I think it is linear. If I double the size of a matrix, I need to calculate double the additions, not quadruple. The main diverging point seems to be what is the size of the problem. To me, it's the number of elements in the matrix. Others think it is the number of columns or lines, hence the O(n^2) complexity. Another problem I have with seeing it as a quadratic operation is that that means adding 3-dimensional matrices is cubic, and adding 4-dimensional matrices is O(n^4) , etc, even though

what is the difference between running time ,complexity,compile time and execution time?

泪湿孤枕 提交于 2019-12-04 22:01:28
what is the difference between running time ,complexity,compile time and execution time? l have conflict between running time and time complexity and what is difference between them and execution time? Spektre What you are really asking is how to transform Big O Time complexity into runtime . That is not that easy as it seems at first. So take a closer look at complexities first, To make it more easy lets use this simple C++ example: int fact(int n) { if (n<=1) return 1; return n*fact(n-1); } Time vs. Space complexity (For starters I assume basic variables hence all complexities are the same

Are there any online algorithms for planarity testing?

眉间皱痕 提交于 2019-12-04 20:16:05
问题 I know that planarity testing can be done in O(v) (equivalently O(e), since planar graphs have O(v) edges) time. I wonder if it can be done online in O(1) amortized time as each edge is added (still O(e) time overall). In other words, in a database table representing edges of a graph and subject to a constraint that the represented graph is planar, how much time must the DBMS responsible for managing the constraint take to validate each proposed insertion? (For simplification, assume that

Searching strings with . wildcard

北城以北 提交于 2019-12-04 18:53:44
I have an array with so much strings and want to search for a pattern on it. This pattern can have some "." wildcard who matches (each) 1 character (any). For example: myset = {"bar", "foo", "cya", "test"} find(myset, "f.o") -> returns true (matches with "foo") find(myset, "foo.") -> returns false find(myset, ".e.t") -> returns true (matches with "test") find(myset, "cya") -> returns true (matches with "cya") I tried to find a way to implement this algorithm fast because myset actually is a very big array, but none of my ideas has satisfactory complexity (for example O(size_of(myset) * lenght

Can we solve N Queens without backtracking? and How to calculate and what will be the complexity of the backtracking solution?

流过昼夜 提交于 2019-12-04 18:11:58
I have tried solving this problem with backtracking and it prints all possible solutions. Two questions came up: 1. Can i implement n queen using other techniques? 2. Is it possible to make the code below print only the first solution and then terminate? My current code uses backtracking: n = 8 x = [-1 for x in range(n)] def safe(k,i): for j in xrange(k): if x[j] == i or abs(x[j] - i) == abs(k - j) : return False return True def nqueen(k): for i in xrange(n): if safe(k,i): x[k] = i if k == n-1: print "SOLUTION", x else: nqueen(k+1) nqueen(0) Note : I am interested in techniques that do not