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
3
votes
2 answers
Average Case Analysis of Sequential Search with Geometric Probability Distribution
I was kind of aware of getting the average running time in a uniform distribution. Say for example we have 6 array elements.
| 1/6 | 1/6 | 1/6 | 1/6 | 1/6 | 1/6 |
Above is the array with the uniform probability distribution of a search…

alyssaeliyah
- 2,214
- 6
- 33
- 80
3
votes
3 answers
Asymptotic analysis of a given code
I have been given the following pseudocode:
j = 1
while j < n:
k = 2
while k < n:
k = k*k
j++
In my thinking, this piece of pseudocode would have the following complexity:
O(n*log(n))
Since the outer loop is…

basil
- 690
- 2
- 11
- 30
3
votes
2 answers
Calulating time complexity of loops with in loops example
hi I was working with analysis of iterative solution, here is one problem that I am not able to calculate the worst-case running time
void function(int n)
{
int count = 0;
for (int i=0; i

Thinker
- 518
- 1
- 6
- 22
3
votes
2 answers
Bitonic Sort (Calculating complexity)
so basically I'm trying to understand how a time complexity of Bitonic Sort should be calculated and best and worse case scenarios decided using Cost and Time and then adding and multiplying values.
As an example: I tried first calculating…

Yahooo C9Wuxii
- 87
- 6
3
votes
3 answers
Big-O time complexity for this recursive Fibonacci?
I have a program that prints Fibonacci Series using Recursion. There are better methods for it, but I was asked to use recursion so i had to do it this way.
Here is the program:
#include
#define TERMS 10
long fibo(int);
int main(void){
…

coder3101
- 3,920
- 3
- 24
- 28
3
votes
1 answer
Worst scenario for shell sort: Θ(N^3/2) or O((NlogN)^2)?
I am looking for worst case of Shell sort.
According to this, the worst case is O(N^3/2)
but here, it is claimed that the worst case is O((N log N)^2)).
I think that worst case should be a a sequence containing largest vales in odd positions.…

David
- 1,343
- 3
- 12
- 13
3
votes
1 answer
Find the order of a function
What is the lowest order of the following function as n tends to infinity?
where a>1 and 0

Sus20200
- 337
- 3
- 13
3
votes
1 answer
Which f(x) minimizes the order of g(f(x)) as x goes to infinity
Assume f(x) goes to infinity as x tends to infinity and a,b>0. Find the f(x) that yields the lowest order for
as x tends to infinity.
By order I mean Big O and Little o notation.
I can only solve it roughly:
My solution: We can say ln(1+f(x)) is…

Sus20200
- 337
- 3
- 13
3
votes
2 answers
Time complexity of program
Consider the following C functions:
int f1(int n) {
if(n == 0 || n == 1)
return n;
else
return (2 * f1(n-1) + 3 * f1(n-2));
}
I have to find the running time of f1(n)
My Solution:-
The recurrence relation for running time…

abnvanand
- 203
- 2
- 6
3
votes
2 answers
Doing an O(1) operation, O(n) times still O(1)?
If you have an array and you add 5 to every element, what would you say this runs in? Obviously if it goes over all the elements in the array then it should by default be O(n). However, since adding an integer value is O(1), could we say the entire…

Michael
- 61
- 6
3
votes
2 answers
What is the Worst-Case Input for Stein's Algorithm?
I'm trying to come up with the recurrence relation for Stein's Algorithm (binary GCD algorithm), but my ability to trace through it is proving not up-to-scratch.
I'm completely stumped by the multiple paths and recursive calls, as well as the fact…

Pilkoid
- 33
- 4
3
votes
5 answers
How is the time complexity of the following function O(n³)?
I was going through the Algorithm lecture series of Stanford University on Coursera by Tim Roughgarden. There, he gave a multiple choice question to find the running time complexity of a function, which is given below in the image.
In this…

KhiladiBhaiyya
- 633
- 1
- 14
- 43
3
votes
1 answer
Big O analysis of an algorithm - Job Interview
Recently I had an interview question to write an algorithm which analyse an array and returns numbers which are duplicates;
My brute force solution was:
public static ArrayList getDuplicates (int[] input){
ArrayList duplicates = new…

zakb
- 91
- 1
- 5
3
votes
1 answer
Why the complexity of pop_heap is O(2 * log(N))?
I saw in a several places that in priority_queue, the complexity of pop_heap is O(2 * log(N)), is that true? If yes, where that 2 come from? After removing first element it just needs to reconstruct heap, which would take O(log(N)).

user1289
- 1,251
- 2
- 13
- 25
3
votes
1 answer
Longest Substring Without Repeating Characters corner cases
I was asked this question in a recent interview. I need to find the longest substring without repeating characters.
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given…

Wild Widow
- 2,359
- 3
- 22
- 34