big-o

[Java] Efficiently finding the intersection of a variable number of sets of strings.

I have a variable number of ArrayList's that I need to find the intersection of. A realistic cap on the number of sets of strings is probably around 35 but could be more. I don't want any code, just ideas on what could be efficient. I have an implementation that I'm about to start coding but want to hear some other ideas. Currently, jus...

Counting duplicates (not necessarily removing) in an array in O(n)

Hello :) This is for an assignment, and is in psuedo-code. I need to find how many integers in an array are unique, nothing else, but it has to be in O(n), preferably without hashing. Thanks! ...

Finding smallest angle between vectors in logarithmic time.

I have n=10000 10-dimensional vectors. For every vector v1 I want to know the vector v2 that minimizes the angle between v1 and v2. Is there a way to solve this problem faster than O(n^2)? ...

Questions on runtime analysis properties

Am I wondering if the follow are true. If f(n) is O(g(n)) and f(n) is also Ω(g(n)) that means f(n) is also big Θ(g(n)) right? Also if either of the 2 above are false, then f(n) is not big Θ(g(n))? ...

tight (Θ) bound

Can someone explain this to me? Such as this: Given a function: for k = 1 to lg(n) for j = 1 to n x=x+1 How would I analyze the tight (Θ) bound? ...

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; } } ...

Big O Complexity of a method

I have this method: public static int what(String str, char start, char end) { int count=0; for(int i=0;i<str.length(); i++) { if(str.charAt(i) == start) { for(int j=i+1;j<str.length(); j++) { if(str.charAt(j) == end) count++; } } ...

Quick Big-O question

int a = 3; while (a <= n) a = a*a; My version is that its complexity is: Is there such a thing? ...

Tricky Big-O complexity

public void foo (int n, int m) { int i = m; while (i > 100) i = i/3; for (int k=i ; k>=0; k--) { for (int j=1; j<n; j*=2) System.out.print(k + "\t" + j); System.out.println(); } } I figured the complexity would be O(logn). That is as a product of the inner loop, the outer loop -- ...

Find if there is an element repeating itself n/k times

You have an array size n and a constant k (whatever) You can assume the the array is of int type (although it could be of any type) Describe an algorithm that finds if there is an element(s) that repeats itself at least n/k times... if there is return one. Do so in linear time (O(n)) The catch: do this algorithm (or even pseudo-code) ...

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) ...

Big-oh time complexity for nested for loop

Hi, I have a question here the loop is: for (i=0; i < n; ++i) for (j = 3; j < n; ++j) { ... } I kind of understand how to calculate the big-oh but I am not entirely sure on how to do it. The outer loop executes n times and the inner loop executes i times for each value of i. The complexity is sup...

Are there any cases where LINQ's .Where() will be faster than O(N)?

Hi all.. Think the title describes my thoughts pretty well :) I've seen a lot of people lately that swear to LINQ, and while I also believe it's awesome, I also think you shouldn't be confused about the fact that on most (all?) IEnumerable types, it's performance is not that great. Am I wrong in thinking this? Especially queries where ...

What is big-O notation? How do you come up with figures like O(n)?

Possible Duplicate: Plain english explanation of Big O I'd imagine this is probably something taught in classes, but as I a self-taught programmer, I've only seen it rarely. I've gathered it is something to do with the time, and O(1) is the best, while stuff like O(n^n) is very bad, but could someone point me to a basic expla...

Big O notation for triangular numbers?

What's the correct big O notation for an algorithm that runs in triangular time? Here's an example: func(x): for i in 0..x for j in 0..i do_something(i, j) My first instinct is O(n²), but I'm not entirely sure. ...

Is the time complexity of the empty algorithm O(0)?

So given the following program: Is the time complexity of this program O(0)? In other words, is 0 O(0)? I thought answering this in a separate question would shed some light on this question. EDIT: Lots of good answers here! We all agree that 0 is O(1). The question is, is 0 O(0) as well? ...

Is there such a thing as "negative" big-O complexity?

Possible Duplicate: Are there any O(1/n) algorithms? This just popped in my head for no particular reason, and I suppose it's a strange question. Are there any known algorithms or problems which actually get easier or faster to solve with larger input? I'm guessing that if there are, it wouldn't be for things like mutations or...

Recurrence Relation: Solving Big O of T(n-1)

Hello, I'm solving some recurrence relation problems for Big O and so far up till this point have only encountered recurrence relations that involved this form: T(n) = a*T(n/b) + f(n) For the above, it's quite easy for me to find the Big O notation. But I was recently thrown a curve ball with the following equation: T(n) = T(n-1) + ...

The Big O of Distinct() method with a Custom IEqualityComparer

Anyone knows the Big O of the algorithm used in the Distinct() method, with a custom IEqualityComparer? ...

Does Big O Measure Memory Requirments Or Just Speed?

I often here people talk about Big O which measures algorithms against each other Does this measure clock cycles or space requirements. If people want to contrast algorithms based on memory usage what measure would they use ...