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
15
votes
2 answers
Calculating work done by f x = (x,x)
Let's say I have this function: (Haskell syntax)
f x = (x,x)
What is the work (amount of calculation) performed by the function?
At first I thought it was obviously constant, but what if the type of x is not finite, meaning, x can take an arbitrary…

Guido
- 2,571
- 25
- 37
14
votes
7 answers
Accessing Elements - Really O(1)?
It is said that an example of a O(1) operation is that of accessing an element in an array. According to one source, O(1) can be defined in the following manner:
[Big-O of 1] means that the execution time of the algorithm does not depend on
the…

Mr Chasi
- 437
- 1
- 6
- 18
13
votes
2 answers
Solve: T(n) = T(n/2) + n/2 + 1
I struggle to define the running time for the following algorithm in O notation. My first guess was O(n), but the gap between the iterations and the number I apply isn't steady. How have I incorrectly defined this?
public int function (int n )
{
…

sra
- 157
- 7
13
votes
4 answers
Time complexity of the program using recurrence equation
I want to find out the time complexity of the program using recurrence equations.
That is ..
int f(int x)
{
if(x<1) return 1;
else return f(x-1)+g(x);
}
int g(int x)
{
if(x<2) return 1;
else return f(x-1)+g(x/2);
}
I write its recurrence…

siddstuff
- 1,215
- 4
- 16
- 37
13
votes
4 answers
If f(n)=O(g(n)), then shouldn't f(n)∗log2(f(n)^c)=O(g(n)∗log2(g(n))) depend on the value of C?
If f(n)=O(g(n)), then shouldn't f(n)∗log2(f(n)^c)=O(g(n)∗log2(g(n))) depend on the value of C?
Here C is a positive constant. According to me if C is large then the statement would become false and if c is small it'd be true. Hence the outcome is…

Charu
- 2,679
- 6
- 35
- 52
12
votes
2 answers
What is the resizing factor of lists in Python
For example, ArrayLists in Java have a resizing factor of 2. When the array that the ArrayList is wrapped around runs out of space, all the elements of that array are transferred to a new array that is 2 times the size of the original array.
Since…

TomLisankie
- 3,785
- 7
- 28
- 32
12
votes
3 answers
Is there any implementation to Remove by Key and get the Value at the same time?
I'm doing a performance critical program (little academic stuff) and I'm looking to optimize wherever possible (not like it proved "this is the" bottleneck).
I have a custom dictionary structure (a wrapper around .NET Dictionary<,>) and I would…

nawfal
- 70,104
- 56
- 326
- 368
12
votes
1 answer
Hash Collision Linear Probing Running Time
I am trying to do homework with a friend and one question asks the average running time of search, add, and delete for the linear probing method. I think it's O(n) because it has to check at certain number of nodes until it finds an open one to add.…

Richard
- 5,840
- 36
- 123
- 208
12
votes
2 answers
When do floors and ceilings matter while solving recurrences?
I came across places where floors and ceilings are neglected while solving recurrences.
Example from CLRS (chapter 4, pg.83) where floor is neglected:
Here (pg.2, exercise 4.1–1) is an example where ceiling is ignored:
(EDIT: I gather from public…

Tejas Patil
- 6,149
- 1
- 23
- 38
11
votes
2 answers
Can it be proved that call-by-need has the minimal asymptotic time complexity among all reduction strategies?
When I read the Church Rosser II Theorem here
Theorem (Church Rosser II)
If there is one terminating reduction, then outermost reduction will terminate, too.
I'm wondering: Is there some theorem which strengthens the Church Rosser II Theorem so…

luochen1990
- 3,689
- 1
- 22
- 37
11
votes
1 answer
Is there a programmatic way or eclipse plugin to calculate big O notation for java method
Is there a programmatic way or eclipse plugin to calculate big-O notation for java method ?

Amgad Hanafy
- 537
- 5
- 15
11
votes
1 answer
Find the next greater element in an array
Given an array , for every element I need to find the smallest element to the right of the given element which is greater than the current element.
Mathematically,
For every index i in array A, I need to find index j such that
A[j] > A[i]
j > i
A[j]…

Sam Radhakrishnan
- 681
- 1
- 5
- 19
11
votes
1 answer
Why is SortedDictionary.GetEnumerator O(log n) but SortedSet.GetEnumerator O(1)?
From the SortedSet.GetEnumerator documentation:
This method is an O(1) operation
From the SortedDictionary.GetEnumerator documentation:
This method is an O(log n) operation, where n is count.
Can both the statements be true,…

nawfal
- 70,104
- 56
- 326
- 368
11
votes
5 answers
Complexity of the recursion: T(n) = T(n-1) + T(n-2) + C
I want to understand how to arrive at the complexity of the below recurrence relation.
T(n) = T(n-1) + T(n-2) + C
Given T(1) = C and T(2) = 2C;
Generally for equations like T(n) = 2T(n/2) + C (Given T(1) = C), I use the following method.
T(n) =…

Gopal
- 1,292
- 3
- 19
- 41
11
votes
2 answers
The time complexity of counting sort
I am taking an algorithms course and there I saw that the time complexity of counting sort is O(n+k) where k is the range of numbers and n is the input size. My question is, when the difference between k and n is too much, such as when k=O(n2)or…
user2110714