This is my first course in data structures and every lecture / TA lecture , we talk about O(log(n)) . This is probably a dumb question but I’d appreciate if someone can explain to me exactly what does it mean !?
This is my first course in data structures and every lecture / TA lecture
Share
It means that the thing in question (usually running time) scales in a manner that is consistent with the logarithm of its input size.
Big-O notation doesn’t mean an exact equation, but rather a bound. For instance, the output of the following functions is all O(n):
Because as you increase x, their outputs all increase linearly – if there’s a 6:1 ratio between
f(n)andg(n), there will also be approximately a 6:1 ratio betweenf(10*n)andg(10*n)and so on.As for whether
O(n)orO(log n)is better, consider: ifn = 1000, thenlog n = 3(for log-base-10). Which would you rather have your algorithm take to run: 1000 seconds, or 3 seconds?