big-o

Prove or disprove n^2 - n + 2 ∈ O(n)

For my algorithm analysis course, I've derived from an algorithm the function f(n) = n^2 - n + 2. Now I need to prove or disprove f(n) ∈ O(n). Obviously it's not, so I've been trying to disprove that for a few hours and can't figure out how to do it. To disprove it, I need to prove the negative: ∀M > 0, ∀N > 0, ∃n > N s.t. n^2 - n + 1 ...

Easiest way to determine time complexity from run times

Lets suppose I am trying to analyze an algorithm and all I can do is run it with different inputs. I can construct a set of points (x,y) as (sample size, run time). I would like to dynamically categorize the algorithm into a complexity class (linear, quadratic, exponential, logarithmic, etc..) Ideally I could give an equation that more...

Time complexity of Hash table

I am confused about the time complexity of hash table many articles state that they are "amortized O(1)" not true order O(1) what does this mean in real applications. What is the average time complexity of the operations in a hash table, in actual implementation not in theory, and why are the operations not true O(1)? ...

Example of O(n!)?

What is an example (in code) of a O(n!) function? It should take appropriate number of operations to run in reference to n; that is, I'm asking about time complexity. ...

Big O Notations

Possible Duplicate: Big O Notations Questions Hi, I need an example in codes with reference to O(N!) time complexity. ...

Big-O Notation Code Algorithm Analysis Homework

for(int i=N; i>0; i=i/2) irrelevant statement; I am asked to find the complexity class and I am unsure of whether I am supposed to use Big-Omega notation or Big-O? But I am assuming that it is O(N/2) and then O(N) if I drop the constants. for (int i=0; i<N; i++) for (int j = i+1; j<N; j++) irrelevant statement; ...

Big O of pre order traversal, in order traversal ,post order, level order for tree

Please let me know the Big Oh of the above. ...

Mapping from String to integer - performance of various approaches

Let's say that I need to make a mapping from String to an integer. The integers are unique and form a continuous range starting from 0. That is: Hello -> 0 World -> 1 Foo -> 2 Bar -> 3 Spam -> 4 Eggs -> 5 etc. There are at least two straightforward ways to do it. With a hashmap: HashMap<String, Integer> map = ... int integer = ...

What is the best way to get right most number in an integer with C?

I'm just mucking around with C as a learner, and wrote this little function... char *getPlaceSuffix(int number) { static char *suffixes[] = {"st", "nd", "rd", "th"}; if (number >= 11 && number <= 13) { return suffixes[3]; } else { while (number > 10) { number -= 10; } if (num...

Big Oh Algorithm Time Complexity

000000000000000000 ...

how do you prove that the big theta of a series is its leading term?

if f(x) = (An) x^n + (An-1) x^(n-1) +...+ (A1)x + (A0) how can you prove f(x) is big theta(x^n). I've thought about it and one could do it by proving that f(x) big O(x^n) and x^n big O(f(x)). I've figured out the proof for the former (using triangle inequality) but could not understand how to do the latter. Alternatively one could prov...

Help In Learning Algorithm Basics

Hi Guys, I am learning algorithms and need you guys to help me. I am a beginner so forgive me if my question is not clear. Whiles am learning i am seeing something like NlogN, N^2 etc.. and something like that. I don't really understand it clearly when it comes to checking the efficiency/performance of different algorithms using these...

complexity about going from beginning to end and back through a vector

Hi All I am trying to be familiar with the complexity evaluation of algorithms. In general I think that is a good/elegant practice, but in the specific I need it to express time complexity of my C++ code. I have a small doubt. Suppose I have an algorithm that just reads data from the beginning of a std::vector until the end; then it ...

Levenshtein Distance Algorithm better than O(n*m)?

I have been looking for an advanced levenshtein distance algorithm, and the best I have found so far is O(n*m) where n and m are the lengths of the two strings. The reason why the algorithm is at this scale is because of space, not time, with the creation of a matrix of the two strings such as this one: Is there a publicly-available l...

Determining BigO of a recurrence

T (1) = c T (n) = T (n/2) + dn How would I determine BigO of this quickly? ...

Mergesort running time BigO

Snape’s “Unfriendly Algorithms for Wizards” textbook claims the running time of merge sort is O(n^4). Is this claim correct? Solution: Yes. This claim is technically correct, because O(n^4) only gives an upper bound for how long the algorithm takes. However, it’s an obnoxiously unhelpful answer, since the tight bound is Θ(n log n). I'm...

BigO bound on some pseudocode

AllDistinct(a1 , . . . , an ) if (n = 1) return True for i := n down to 2 begin if (LinearSearch(a1 , . . . , ai−1 ; ai ) != 0) return False end return True Give a big-O bound on the running time of AllDistinct. For full credit, you must show work or briefly explain your answer. So the actual answer for this according to ...