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
5
votes
2 answers
Is O(n) greater than O(2^log n)
I read in a data structures book complexity hierarchy diagram that n is greater than 2log n. But cannot understand how and why. On using simple examples in power of 2 as n, I get values equal to n.
It is not mentioned in book , but I am assuming it…

HimanshuR
- 1,390
- 5
- 16
- 35
5
votes
1 answer
How can I implement a collection with O(1) indexing and mutability in Haskell?
If I'm counting the occurences of characters in a string, I could easily implement this using an array in an imperative language, such as the following:
char values[256]; char c;
while (c = readChar()) {
values[c] += 1;
}
I can see how to do…

Jakub Arnold
- 85,596
- 89
- 230
- 327
5
votes
1 answer
What is the difference between O(N) + O(M) and O(N + M). Is there any?
I'm solving problems for interview practice and I can't seem to figure out the answer to the time and space complexity of the following problem:
Given two sorted Linked Lists, merge them into a third list in sorted order. Let's assume we are using…

nem035
- 34,790
- 6
- 87
- 99
5
votes
3 answers
Graph In-degree Calculation from Adjacency-list
I came across this question in which it was required to calculate in-degree of each node of a graph from its adjacency list representation.
for each u
for each Adj[i] where i!=u
if (i,u) ∈ E
in-degree[u]+=1
Now according to me its…

silentseeker
- 416
- 5
- 14
5
votes
3 answers
Can I say that a Θ(n^3/2)-time algorithm is asymptotically slower than an Θ(n log n)-time algorithm?
I analyzed an algorithm and for running time I got Θ(n3/2). Now I want to compare it with Θ(n log n) to see if it is asymptotically faster or slower, for that I did this:
Θ(n3/2) = Θ(n · n1/2)
If we compare them we will see that we need to compare…

HMdeveloper
- 2,772
- 9
- 45
- 74
5
votes
2 answers
Asymptotic analysis
I'm having trouble understanding how to make this into a formula.
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j += i) {
I realize what happens, for every i++ you have 1 level of multiplication less of j.
i = 1, you get j = 1,…

Mappan
- 2,537
- 2
- 22
- 27
5
votes
4 answers
Sum of order of O(1)+O(2)+ .... +O(n)
What does the sum O(1)+O(2)+ .... +O(n) evaluate to?
I have seen its solution somewhere it was written:
O(n(n+1) / 2) = O(n^2)
but I am not satisfied with it because O(1) = O(2) = constant, so according to me it must evaluate to O(n) only. I have…

Madhudeep Petwal
- 83
- 2
- 7
5
votes
2 answers
Computational complexity of a piece of code
I have got a program, and trying to compute its complexity. I want to be sure i am not mistaken
for(int i=4; i<=n; i=i*4)
{
cout<<"counter for first loop: "<<++count1<=0;j=j-4)
{
cout<<"counter for second…
user2110714
5
votes
1 answer
How can the lower bound for matrix sorting be found?
Consider the problem of sorting an n x n matrix (i.e. the rows and columns are in ascending order). I want to find the lower and upper bound of this problem.
I found that it is O(n^2 log n) by just sorting the elements and then outputting the first…

user2038833
- 87
- 1
- 6
5
votes
3 answers
Is there a library for programmatic manipulation of Big-O complexities?
I'm interested in programming languages that can reason about their own time complexity. To this end, it would be quite useful to have some way of representing time complexity programmatically, which would allow me to do things like:
f_time =…

perimosocordiae
- 17,287
- 14
- 60
- 76
5
votes
2 answers
How to add Big O and Big omega
If an algorithm has two sub algorithm, when it is best case for sub algorithm A1 to the given input, it is the worst case for sub algorithm A2. How could I find the overall algorithm complexity?
Simply I mean Ω(N) + O(N)=?
I know if the algorithms…

Mobi
- 645
- 3
- 6
- 14
4
votes
3 answers
Multiplying and adding different asymptotioc notations
does anyone knows how to perform such calculations
Example:
O(n^2) + THETA(n) + OMEGA(n^3) = ?
or
O(n^2) * THETA(n) * OMEGA(n^3) = ?
In general, how to add and multiply different asymptotic notations?

Sławosz
- 11,187
- 15
- 73
- 106
4
votes
4 answers
Big-O Notation, Find the Smallest
Give the smallest O() estimate you can for the following functions:
4n2 + 5n – 8 = O(...)
log(n)2 + n = O(...)
If you guys can, explain the answer rather than giving it to me. A question like this will be on my mid-term and I want to understand…

Steven Polluk
- 41
- 1
- 2
4
votes
2 answers
Whats the Time and Space Complexity for below Recursive code snippet?
Below is a recursive function to calculate the value of Binomial Cofecient 'C' i.e. Combination ! I wish to understand this code's Time and Space complexity in terms of N and K (Assuming that We are calculating NCK).
public class…

Aditya Goel
- 201
- 1
- 15
4
votes
3 answers
In algorithm analysis, what does "for some constant c" actually mean? (E.g., QuickSort)
Consider the following recursion tree for quick sort, which constantly divides subproblems into a 3-to-1 ratio (source: Khan Academy).
I understand that the partition subroutine in quicksort iterates through each subproblem and thus is O(n).…

A is for Ambition
- 557
- 7
- 18