big-o

Is System.currentTimeMillis() the best measure of time performance in Java?

Is System.currentTimeMillis() the best measure of time performance in Java? Are there any gotcha's when using this to compare the time before action is taken to the time after the action is taken? Is there a better alternative? ...

Big O question

If I have the following code: IterateArray(object[] array) { for(int i=0; i<array.length; i++) { Dosomething(array[i]); } } and the Dosomething(object) method's time performance is O(log n), is the overall performance of IterateArray O(n) or O(n log n)? Thanks. ...

Is there a O(nlog(n)) algorithm for inverting a simply linked list?

In comments to this answer an idea is brought up that inverting a simply linked list could only be done in O(nlog(n)), not O(n) time. This is definitely wrong – an O(n) inversion is not a problem - just traverse the list and change pointers as you go. Three temporary pointers are required - that's constant extra memory. I understand co...

how to find the time complexity using step count

sum(array,n) { tsum=0; for(i=0;i<n;i++) tsum=tsum+array[i]; return tsum; } ...

Regex implementation that can handle machine-generated regex's: *non-backtracking*, O(n)?

Edit: This question has considerably evolved since I first asked it. See below for two fast+compatible, but not completely fully featured implementations. If you know of more or better implementations, please mention them, there still isn't an ideal implementation here yet! Where can I find reliably fast Regex implementation? Does ...

Some Questions on Complexity

1) Reorder the following efficiency from smallest to largest: 2^n, n!, n^5, 10000, nlog2(n) My Ans-> 10000 < nlog2(n) < n^5 < 2^n < n! Correct ? 2) Efficiency of an algo. is n^3, if a step in this algo. takes 1 nanosec. (10^-9 sec.). How long does it take the algo. to process an input of size 1000? I don't know ... Is it (...

Do you use Big-O complexity evaluation in the 'real world'?

Recently in an interview I was asked several questions related to the Big-O of various algorithms that came up in the course of the technical questions. I don't think I did very well on this... In the ten years since I took programming courses where we were asked to calculate the Big-O of algorithms I have not have one discussion about ...

Big O Notation for an Algorithm

I can't solve a problem; can someone help me? What is the Big O notation for the below statement:- for (int i=2;i<=n;i=i*4) sum++; ...

Is this code O(N) or O(1)

vector<int>::iterator it; vector<int> p; p.push_back(4); p.push_back(5); p.push_back(6); p.push_back(7); it = p.begin() + 2; cout << it << endl; Is this O(N) or O(1)? And why? ...

Is it ever possible to have Big O less than O(1)?

Possible Duplicate: are there any O(1/n) algorithms? Is it ever possible for your code to be Big O less than O(1)? ...

What is O value for naive random selection from finite set?

This question on getting random values from a finite set got me thinking... It's fairly common for people to want to retrieve X unique values from a set of Y values. For example, I may want to deal a hand from a deck of cards. I want 5 cards, and I want them to all be unique. Now, I can do this naively, by picking a random card 5 t...

Time Complexity O() of isPalindrome()

I have this method isPalindrome() and am trying to find the time complexity of it, and also rewrite the code more efficiently. boolean isPalindrome(String s) { boolean bP = true; for(int i=0; i<s.length(); i++) { if(s.charAt(i) != s.charAt(s.length()-i-1)) { bP = false; } } return bP; } Now I know this code...

What is the Big-O for SQL select ?

What is the Big-O for SQL select, for a table with n rows and for which I want to return m result? And What is the Big-O for an Update, or delete, or Create operation? I am talking about mysql and sqlite in general. ...

Can someone please explain the difference between Big-O and Little-O Notation?

I'm having trouble distinguishing between these these two. Can someone please explain the differences to me? I'm a little slow, so examples would probably help. Thanks ...

What is an easy way for finding C and N when proving the Big-Oh of an Algorithm?

I'm starting to learn about Big-Oh notation. What is an easy way for finding C and N0 for a given function? Say, for example: (n+1)5, or n5+5n4+10n2+5n+1 I know the formal definition for Big-Oh is: Let f(n) and g(n) be functions mapping nonnegative integers to real numbers. We say that f(n) is O(g(n)) if there is a real c...

Can someone explain how Big-Oh works with Summations?

I know this isn't strictly a programming question, but it is a computer science question so I'm hoping someone can help me. I've been working on my Algorithms homework and figuring out the Big-Oh, Big-Omega, Theta, etc, of several algorithms. I'm proving them by finding their C and N0 values and all is going well. However, I've come a...

Relative asymptotic behavior of these functions

I have 3 functions: f(n)=2n, g(n)=n! and h(n)=nlog(n) (log(n) is base 2). Comparing f(n) and g(n): The factorial function, g(n) can be approximated as O(nn) (poor upper bound). Considering this, Is g(n)=Ω(f(n)) ? How would I compare g(n) and h(n), and f(n) and h(n)? ...

What is the proper method to go about finding the order of growth for this function?

2^n + 6n^2 + 3n I guess it's just O(2^n), using the highest order term, but what is the formal approach to go about proving this? ...

Efficiency of Sort Algorithms

I am studying up for a pretty important interview tomorrow and there is one thing that I have a great deal of trouble with: Sorting algorithms and BigO efficiencies. What number is important to know? The best, worst, or average efficiency? ...

Calculating a Theta (Tight Bound) Estimation

Hi, I was just wondering if someone could explain this a little to me. I want to know how to calculate an estimate for a Theta function using the integrals or the truncate-and-bound method. For Example how would you calculate: n ∑ i√i+1 i=1 ...