# How long will selection sort and merge sort take to sort a certain number of items?

I am dealing with a sample exam question that I cannot understand which is as follows:

Selection sort takes one millisecond to sort 1000 items (worst-case time) on a particular computer. Estimate the amount of time it would take to sort 100,000 items. If Mergesort took 1 second for 100 items and 15 seconds for 1000 items, how long would you expect it to take for 1,000,000?

Now, I know that selection sort has worst-case upper bound of $O(n^2)$. So as size of input $n$ increases, $f(n)$ increases in a quadratic manner. So I understand the concept of it but I don't understand how to use it to solve for how much time it would take for 100,000 items (100 times the original input). How would I solve it?

• They want you to apply rule of three under ridiculous assumptions. (There are unknown lower-order terms and constant factors hidden in that $O(n^2)$. ) The question is senseless. – Raphael Oct 18 '16 at 0:08
• I'm sorry but I haven't heard of the rule of three before. Could you show me how I can use it to solve this question? – learnerX Oct 18 '16 at 0:10
• I'm sure you have. But no, it can't be used to really answer this question. And no, I won't be accomplice in teaching you wrong things. What your teacher wants you to calculate has nothing to do with how algorithm analysis or even Landau notation works. – Raphael Oct 18 '16 at 0:11
• Oh, right. I just know it as cross-multiplication. So I know how to use that rule for a linear decrease in time with input. But how do I use that when there's a quadratic decrease in time with input? – learnerX Oct 18 '16 at 0:16
• Please listen carefully: no. No, that's nothing you can do. You can do the numbers, but that doesn't make sense. It's not even wrong. See also here. – Raphael Oct 18 '16 at 0:22

They want you to apply rule of three under ridiculous assumptions.

If an O(n²) algorithm takes 1ms for 1000 elements, then from 1ms = c * 1000² and the ansatz Xms = c * 100000² we get that X = 10000.

In essence, they want you to assume that the running time function equals $cn^2$, in which case you could compute the constant $c$ from the given information.

The problem is that

• $O(\_)$ is only an upper bound and does not tell you anything about the true behaviour of the described function,
• there are unknown lower-order terms hidden in that $O(\_)$ (and also $\Theta(n^2)$, if you had that) and
• asymptotics tell us nothing for any finite $n$.
• They also ignore that the algorithms take different amounts of time for different inputs of the same size and
• that "time" is a famously fickly cost measure as it depends a lot on effects like caching and process scheduling.

Therefore, the problem is senseless.

• Thank you. I do understand that this solution is based on some big assumptions and would fail in the real-world miserably. I guess they just want to test if we understand the general concept of bit omega. – learnerX Oct 18 '16 at 0:34
• @learnerX This problem does not test that at all! The only thing it achieves is you gaining misconceptions about Landau notation. As my first three bullets show, understanding "big oh" means understanding that the problem is ill-posed. Please, please point your teacher here. – Raphael Oct 18 '16 at 0:36