I have two questions regarding time complexities.
1) I still haven’t seem to have gotten a hold of the big-oh or the landau’s notation. I know it is used to represent time complexities, but why cant I just say the worst-case time complexity of, say, bubble sort is n^2 and not as O(n^2)?
2) Why does log come into the picture for some time complexities? for example, why and how exactly is the worst-case time complexity of shell sort O(nlogn)?
any good site, other than wikipedia, about these things will be appreciated.
Big-O notation is used to denote the fact that you’re talking about asymptotic behaviour. If you just write
n^2, it might be assumed that you’re talking about the actual runtime of your particular program (i.e. that you could get the runtime in seconds directly from that expression). But in practice, your runtime will be of the forma.n^2 + b.n + c.log(n) + d. Big-O notation allows you to ignore all the lower-order terms, because asnheads to infinity, it’s only then^2term that matters.I’m not sure the worst-case complexity of shell sort is
O(n log n). Butlogoften comes in when something is being successively divided in two (think about the height of a balanced binary tree, for instance).