complexity of (n^2/2)+(n^2*logn) - algorithm

I'm trying to solve exercises about algorithms complexity and in a case like the one in the title I'm not sure on how to proceed.
I know that I would have to find the fastest growing term and remove the coefficient unless the coefficient includes another term:
for example: (n^2)*logn complexity is O((n^2)*logn) and (n^2)*2 complexity is O(n^2).
What I did was simplifying the function to n^2(1/2+logn), but after that I'm not sure if the complexity would just be O(n^2(1/2+logn)) or if the result is something else.

Like Damien suggested in the comment, the answer is:
O(1/2 + logn) = O(logn)

Related

what is the difference between nlogn and logn in the view of how the algorithm grows

I have a question reagarding to my lecture datastructures and algortihms.
I have to problem to understand how a algorithm grows. I dont unterstand the difference between the O Notations. And i dont understand the difference between them for example O(lgn)and O(nlgn).
I hope anyone can help me. thank you
To compare time complexities you should be able to make some mathematical proofs. In your example:
for every n>1 we have by multiplying with logn: nlogn>logn so nlogn is worse than logn. An easy way to understand this is by comparing the graphs of functions as suggested in comments or even try some big inputs to see the asymptotic behavior. For example for n=1000000 :
logn(1000000)=6 and 1000000log(1000000)=6000000 which is greater.
Also notice that you dount count constants in big O notation for example 4n is O(n) , n is O(n) and also cn+w is O(n) for c,w constants.

Big O notation Algorithm

I am learning Algorithm recently and know that there are usually some good algorithm existed already that we don't need to write our own. I think the problem I am facing in a question paper.
I have a question in my past paper that if a function is O(n) then can it be O(n^2) ?
can we say that if a function is O(n) then it's also O(n^2)???
Big O is an upper bound. So, yes, n is in O(n^2), but not vice-versa. Also, both n and n^2 are in O(n^3).

Time Complexity of Algorithms (Big Oh notation)

Hey just a quick question,
I've just started looking into algorithm analysis and I'm attempting to learn Big-Oh notation.
The algorithm I'm looking at contains a quicksort (of complexity O(nlog(n))) to sort a dataset, and then the algorithm that operates upon the set itself has a worst case run-time of n/10 and complexity O(n).
I believe that the overall complexity of the algorithm would just be O(n), because it's of the highest order, so it makes the complexity of the quicksort redundant. However, could someone confirm this or tell me if I'm doing something wrong?
Wrong.
Quicksort has worst case complexity O(n^2). But even if you have an O(nlogn) sort algorithm, this is still more than O(n).

What is the asymptotic complexity of log_2(n)-log_3(n)?

I'm trying to determine whether it is: O(1).
How can I prove it?
In complexity terms, log_b(n) is log(n). So is O(log_2(n)-log_3(n))=O(0)=O(1)? that doesn't seem like a strong proof.
Also, this doesn't converge asymptotically, so how can it be O(1)?
...your proof is wrong. O(log_2(n)-log_3(n))==O(log(n)/log(2)-log(n)/log(3))==O(log(n)*(1/log(2)-1/log(3))=O(Clog(n))=O(log(n)).
Also, you might have a look at Wolfram Alpha
It gives some nice plots for log_2(n)-log_3(n)
And, even more important for you, it describes O(log_2(n)-log_3(n))

Time Complexity Explanation with addition

If i have something with O(logN) and add it to something with O(1)
Is the overall complexity still logN?
thanks
Often big-O notation is an approximation. For example, you might say logN when the actual complexity is 4logN + 7. This is still considered to be logN time, because the major factor is the behaviour as N changes.
If you had some algorithm that is N^2 + logN, then the most significant term is N^2 and the logN quickly becomes unimportant as N increases... In that case, you might simply say it is O(N^2) because it describes the characteristic time complexity of the algorithm.
So it depends on your needs. If you simply need to describe the nature of the algorithm, then logN should suffice. If you need to completely categorize every part of it or compare with similar but optimized algorithms, then add in all the terms.

Resources