How to calc worst case complixity? [closed] - data-structures

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I calc. the worst case complexity for these code using big O notation.
int a=0, b=0;
for(i=0;i<N;i++){
a=a+1;
}
for(j=0;j<M;j++){
b=b+j;
}

The complexity is linear. The worst case is either N or M, which ever is bigger. The first loop will run N times, the second loop will run M times.

Related

Given problem to be solved in O(n) , but solution using sort() is accepted [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm a beginner and was confused as to why , if we are given to solve a problem in O(n) , and I'm using sort() (O(nlogn)) the platform is accepting the answer , isn't O(nlogn) > O(n)?
isn't O(nlogn) > O(n) ?
Yes. If you used std::sort with input of length n, then you didn't solve the problem in O(n).

I am not able to understand the working of bubble sort algorithm [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am really not able to understand how the bubble sort algorithm works. I am newbie to algorithms.
Bubble sort simply swaps two elements directly comparing them without any advanced programming technique.It works in O(n^2) time that is it will take n^2 amount of proportional time where n is number of elements.
You should have done a some amount of effort as this is available in great visualization here https://visualgo.net/bn/sorting?slide=1.
This will definitely clarify the concept.

How to implement an algorithm to solve this following homework in O(n) time by suffix tree? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a question in bioinformatics. You can solve it by suffix tree structure.
Given a string S=S[1…n] and a number k, we want to find the smallest sub-string of S that occurs in S exactly k times, if it exists. How to solve this problem in O(n) time?
Build the suffix tree of the string O(N).
Count for every node the number of leafs under it O(N).
Find a node where the count == k. The path from the root to that node is a substring that repeats exactly k times.

What is time-complexity of T(N)=4T(N/2)+(N^2)/logN [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
This question was given in MIT video on analysis of algorithms,
The following question can not be done using master method and can be solved using recurrence tree.
Can any please tell me the solution?
Why exactly do you claim that it can not be done with the masters theorem?. This theorem has only some constraints that a and b are constants and a >= 1 and b > 1. It will hold for any f(n) and therefore you can apply it here.
If you will apply it you would see that a=4, b=2 and therefore c = 2. n^c grows faster than your f(n) and therefore the complexity is O(n^2).

Method to solve the stated recurrence? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Need help finding a method for solving the following:
Given f(n) to be 9f(n/3)+(n2)*(log3n) for all n > 1.
And given f(1)=1.
Solve for f(n)
I tried the master theorem, but all the 3 cases did not fit here, my guess would be using the substitution method, but I am not sure how to apply it
Use the substitution f(n) = n2g(n).
This gives us g(n) = g(n/3) + log n.
And so g(n) = Θ(log2n) and f(n) = Θ(n2log2n)

Resources