Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is O(n log n) different then O(log n)? [closed]

Tags:

Researching big O notation, I understand the concept of O(log n) as a binary search and O(n log n) as a quick sort.

Can anyone put into layman's terms what the main difference in runtime is between these two? and why that is the case?

they seem intuitively to be similarly related

like image 812
Adam Weitzman Avatar asked Feb 14 '17 23:02

Adam Weitzman


People also ask

What is the difference between O n and log n?

O(logn) means that the algorithm's maximum running time is proportional to the logarithm of the input size. O(n) means that the algorithm's maximum running time is proportional to the input size. basically, O(something) is an upper bound on the algorithm's number of instructions (atomic ones).

Is O log N same as log n?

They are also both equal to O(log n). You can easily verify that by plugging the functions into the definition of O(g).

What is bigger O of N or O of log n?

Usually the base is less than 4. So for higher values n, n*log(n) becomes greater than n. And that is why O(nlogn) > O(n).

What does O'n log n mean?

O(log N) basically means time goes up linearly while the n goes up exponentially. So if it takes 1 second to compute 10 elements, it will take 2 seconds to compute 100 elements, 3 seconds to compute 1000 elements, and so on. ​It is O(log n) when we do divide and conquer type of algorithms e.g binary search.


2 Answers

Basically: a factor of N.
A binary search only touches a small number of elements. If there's a billion elements, the binary search only touches ~30 of them.
A quicksort touches every single element, a small number of times. If there's a billion elements, the quick sort touches all of them, about 30 times: about 30 billion touches total.

like image 99
Mooing Duck Avatar answered Oct 06 '22 02:10

Mooing Duck


enter image description here

See how Log(n) is flat (not literally but figuratively, in comparison to other functions), while nLog(n) has crossed 600 for a value of n = 100. That's how different they are.

like image 22
displayName Avatar answered Oct 06 '22 02:10

displayName