complexity

Where does optical character recognition (OCR) fall on the scale of problem difficulty?

How hard is Optical Character Recognition (OCR), formally? Let's assume an error tolerance comparable to a human (which is, I believe, around 98%). In other words, where would it fit in the P/NP scale of problem complexity and intractability? Or would it fit on that scale? Just what kind of problem is it? I'm not terribly familiar wit...

How to know if your Unit Test is "right-sized"?

One thing that I've always noticed with my unit tests is that they get to be kind of verbose; seeing as they could also be not verbose enough, how do you get a sense of when your unit tests are the right size? I know of a good quote for this and it's: "Perfection is achieved, not when there is nothing left to add, but when there...

How to know if your Unit Test Fixture is “right-sized”?

How do you know if you "Test Fixture" is right-sized. And by "Test Fixture" I mean a class with a bunch of tests in it. One thing that I've always noticed with my test fixtures is that they get to be kind of verbose; seeing as they could also be not verbose enough, how do you get a sense of when your unit tests are the right size? My ...

Nested loop with dependent bounds trip count

hello. just out of curiosity I tried to do the following, which turned out to be not so obvious to me; Suppose I have nested loops with runtime bounds, for example: t = 0 // trip count for l in 0:N for k in 0:N for j in max(l,k):N for i in k:j+1 t += 1 t is loop trip count is there a general algorithm/...

What order of time does the .NET System.String.Length property take?

I had someone advise me to avoid repeatedly calling String.Length, because it was recalculated each time I called it. I had assumed that String.Length ran in O(1) time. Is String.Length more complex than that? ...

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"? what i call a sequence-generating-function is simply a function which returns a value out of a specific interval (i.e. printable ascii-charecters (32-126)). the point now is, that this generated sequence should be the programs ...

What is the difference between these two nloglog(n) sorting algorithms? (Andersson et al., 1995 vs. Han, 2004)

Swanepoel's comment here lead me to this paper. Then, searching for an implementation in C, I came across this, which referenced another paper on an algorithm described here. Both papers describe integer sorting algorithms that run in O(nloglog(n)) time. What is the difference between the two? Have there been any more recent findings ...

How to get it working in O(n)?

Possible Duplicate: Interview Q: given an array of numbers, return array of products of all other numbers (no division) I came across an interview task/question that really got me thinking ... so here it goes: You have an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to mul...

What is the complexity of this specialized sort

I would like to know the complexity (as in O(...) ) of the following sorting algorithm: There are B barrels that contain a total of N elements, spread unevenly across the barrels. The elements in each barrel are already sorted. The sort combines all the elements from each barrel in a single sorted list: using an array of size B to ...

What is the complexity of the following method?

Hello, I'm still learning about complexity measurement using the Big O Notation, was wondering if I'm correct to say that following method's complexity is O(n*log4n), where the "4" is a subscript. public static void f(int n) { for (int i=n; i>0; i--) { int j = n; while (j>0) j = j/4; } } ...

What is the minimal licensable source code?

Let's suppose I want to "protect" this code about being used without attribution, patenting it, or through any open source licence... #include<stdio.h> int main (void) { int version=2; printf("\r\n.Hello world, ver:(%d).", version); return 0; } It's a little obvious or just a language definition example.. When a source ...

How is the implementation of LinkedHashMap different from HashMap?

If LinkedHashMap's time complexity is same as HashMap's complexity why do we need HashMap? What are all the extra overhead LinkedHashMap has when compared to HashMap in Java? ...

How do you visualize difference between O(log n) and O(n log n)?

Binary search has a average case performance as O(log n) and Quick Sort with O(n log n) is O(n log n) is same as O(n) + O(log n) ...

Calculating the square of BigInteger

Hi, I'm using .NET 4's System.Numerics.BigInteger structure. I need to calculate the square (x2) of very large numbers - millions of decimal digits. If x is a BigInteger, What is the time complexity of: x*x; or BigInteger.Pow(x,2); ? How can multiply such big numbers in the fastest way using .NET 4 BigInteger? Is there an imple...

Naming of an algorithmic antipattern

Hi, I'm having problems to recall the name of doing something with quadratic complexity when it can be solved linearly. For example, using a get-by-index function to iterate over a linked list instead of just using a next-element is the typical case of this antipattern. I think it was the "something painter", as a metaphor of a guy tha...

Big-oh complexity for logarithmic algorithms

Hi again, Few more problems I ran into calculating the Big-oh complexity. There are 2 problems which I cannot solve due to log base operations. Here are the two problems: n = # of data items being manipulated 1) n^3 + n^2 log (base 2) n + n^3 log (base 2) n 2) 2n^3 + 1000n^2 + log (base 4) n + 300000n I am confused when the logs ha...

Remove Blank spaces in a string in O(n).

How to remove blank spaces in a string with a complexity of O(n). My approach is using two indexes. One will traverse till length on string. Other will be incremented only when a non-blank character is encountered. But i am not sure of this approach. TIA, Praveen ...

Conquering Complexity, Eckel on Java and Python and Chunk Theory

In the introduction to Bruce Eckel's Thinking In Java, he says, in 1998: Programming is about managing complexity: the complexity of the problem you want to solve, laid upon the complexity of the machine in which it is solved. Because of this complexity, most of our programming projects fail. And yet, of all the program...

Generate all subset sums within a range faster than O((k+N) * 2^(N/2))?

Is there a way to generate all of the subset sums s1, s2, ..., sk that fall in a range [A,B] faster than O((k+N)*2N/2), where k is the number of sums there are in [A,B]? Note that k is only known after we have enumerated all subset sums within [A,B]. I'm currently using a modified Horowitz-Sahni algorithm. For example, I first call it t...

Flash: runtime complexity of the 'Sprite.contains'?

As the title suggests, what is the runtime complexity (eg, big-O) of the Sprite.contains method? ...