# Big O notation question for set insertion with sequential scan?

A friend and I are asking some questions on Big O Notation.

1. We have an operation that requires a sequential scan on insertion of an element O(n).
2. The insertion itself of an element is O(1).
3. We are inserting a whole set of n items.

We both agree the time for insertion is O(n+1) or simply O(n) reduced. But, we have two questions..

1. Does Big O Notation ever refer to the time for a set operation such as insertion of a whole set, or only to an individual elements operation on the set?
2. Can we ever say the time for an "insertion of a whole set of n size is O(n**2)" per the above?
• Please make up your mind: do you have a question about landau notation or algorithm analysis? The two are not the same! – Raphael Sep 27 '16 at 18:51
• He doesn't realize that they're not the same thing @Raphael. That's why the bulk of my question is clarifying (I hope!) the two concepts, and only secondarily addressing OP's original question. – gardenhead Sep 27 '16 at 20:19

First of all, let's get some things straight. Big-Oh notation is just a notation for describing the asymptotic behavior of any mathematical function (well, at least those defined on the real numbers). It is not tied to algorithm analysis.

Performing algorithmic analysis on a program $p$ that takes input $x$, you want to find a function $f(n)$ so that, for every input $x$ of size $n$, one has $T(p(x)) \leq f(n)$, where $T(p(x))$ denotes the run-time of a program. That is, we are finding the worst-case bound on the run-time of $p$.

Now, it may very well be the case that

$$T(p(x)) \leq e\times n^{3/2} + 2.73 \log_{\pi} \sqrt n \times + .23432342$$

However, this is not very useful. It's difficult to conceptualize the growth of this function. That is one reason we use asymptotic bounds (the other being it is often easier to determine the asymptotic behavior than the exact behavior). It is much more approachable to write

$$T(p(x)) = O(n^{3/2})$$

Anyway, to answer your question: you'll note here that $p$ is an arbitrary program. You can take that program to be whatever you like, including "insert $n$ elements into the set". No one can tell you what to analyze.

• "However, this is not very useful." -- quite the opposite; it's way more useful than the $O$-term! "It's difficult to conceptualize the growth of this function" -- it's incredibly easy to spot the leading term, if that's what you're interested in. – Raphael Sep 27 '16 at 18:52
• Well, I guess it depends on what your intended use is! Also, in this function is happens to be easy to spot the leading term, but there are others where the big-O is not nearly so obvious. – gardenhead Sep 27 '16 at 19:16
• Those rarely occur. And in these cases, nothing prevents you from additionally reporting asymptotics. – Raphael Sep 28 '16 at 6:07