Asymptotic complexity is an approximation of the edge case performance of an algorithm used to determine best and worst case scenarios.
Questions tagged [asymptotic-complexity]
796 questions
7
votes
1 answer
What is asymptotic complexity of List.Add?
I've found that there is a lot of controversy about asymptotic complexity of List.Add(). The source of it I suspect is the worst case scenario that causes underlying array to resize and would logically be O(n) operation. However, the array grows…

Eugene D. Gubenkov
- 5,127
- 6
- 39
- 71
7
votes
2 answers
Would this algorithm run in O(n)?
Note: This is problem 4.3 from Cracking the Coding Interview 5th Edition
Problem:Given a sorted(increasing order) array, write an algorithm to create a binary search tree with minimal height
Here is my algorithm, written in Java to do this problem
…

committedandroider
- 8,711
- 14
- 71
- 126
7
votes
2 answers
the asymptotic growth of n choose floor(n/2)
How can I find the asymptotic growth of n choose floor(n/2) ? I tried
to use the expansion and got that it is equal to
[n*(n-1)*........*(floor(n/2)+1)] / (n-floor(n/2))!
Any idea how can i go from there?
Any help is appreciated, prefer hints…

hussein hammoud
- 385
- 1
- 7
- 20
7
votes
2 answers
Complexity of inserting n numbers into a binary search tree
I have got a question, and it says "calculate the tight time complexity for the process of inserting n numbers into a binary search tree". It does not denote whether this is a balanced tree or not. So, what answer can be given to such a question? If…

yrazlik
- 10,411
- 33
- 99
- 165
7
votes
3 answers
Complexity of a double for loop
I am trying to figure out the complexity of a for loop using Big O notation. I have done this before in my other classes, but this one is more rigorous than the others because it is on the actual algorithm. The code is as follows:
for(cnt = 0,…

Michael Guantonio
- 409
- 1
- 6
- 14
6
votes
4 answers
understanding algorithmic complexity
I'm looking at some online algorithm solutions for coding interviews, and I don't understand why this algorithm is claimed to be O(n^3).
Caveat: I understand that big-Oh notation is abused in industry, and when I refer to O(n), I'm using that…

John Doe
- 63
- 3
6
votes
1 answer
When can the Master Theorem actually be applied?
I am quite frustrated over this.
In CLRS 3rd edition, page 95 (chapter 4.5), it mentions that recurrences like
T(n) = 2T(n/2) + n lg n
cannot be solved with the Master Theorem because the difference
f(n)/n^(log_b(a)) = (n lg n)/n^1 = lg n
is not…

AJJ
- 2,004
- 4
- 28
- 42
6
votes
3 answers
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);
}
…

George Kagan
- 5,913
- 8
- 46
- 50
6
votes
1 answer
Python converting a list to set, big O
and thanks for help
words = [....#Big list of words]
words_set = set(words)
I have hard time determine what is the complexity of set(words) when n=len(words).
Is it O(n) since it moves on all the items of the list, or O(l(n-l)) when l is a single…

nadir
- 175
- 1
- 2
- 8
6
votes
4 answers
Are 2^n and 4^n in the same Big-Θ complexity class?
Is 2^n = Θ(4^n)?
I'm pretty sure that 2^n is not in Ω(4^n) thus not in Θ(4^n), but my university tutor says it is. This confused me a lot and I couldn't find a clear answer per Google.

Nibble
- 75
- 1
- 1
- 3
6
votes
2 answers
Threaded Binary Search Trees Advantage
An explanation about Threaded Binary Search Trees (skip it if you know them):
We know that in a binary search tree with n nodes, there are n+1 left and right pointers that contain null. In order to use that memory that contain null, we change the…

Programmer
- 750
- 2
- 9
- 17
6
votes
6 answers
Big O Notation of an expression
If I have an algorithm that takes 4n^2 + 7n moves to accomplish, what is its O?
O(4n^2)?
O(n^2)?
I know that 7n is cut off, but I don't know if I should keep the n^2 coefficient or not.
Thanks

devoured elysium
- 101,373
- 131
- 340
- 557
6
votes
1 answer
Complexity of equals() in HashMap and SortedMap
I am trying to figure out the computational complexity of equals() in both HashMap and TreeMap in Java. Now, you might say it should be same in both cases as both HashMap and TreeMap inherit the same implementation from AbstractMap. However, I am in…

Waqas
- 311
- 1
- 3
- 10
6
votes
1 answer
Asymptotic complexity of printf
Assuming that I'm printing a string, as follows:
printf("%s", s);
What can we assume the asymptotic complexity of this function is?
Is it O(n) where n is strlen(s) - it's length? Or is it somehow O(1), constant time. Or something different? I…

Migwell
- 18,631
- 21
- 91
- 160
6
votes
2 answers
Asymptotic analysis of three nested for loops
I want to calculate the theta complexity of this nested for loop:
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
for (int k = 0; k < j; k++) {
// statement
I'd say it's n^3, but I don't think…

Aaron
- 826
- 10
- 22