My program of sorting values clocks at:
- 100000 8s
- 1000000 82s
- 10000000 811s
Is that O(n)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, that looks like O(n) to me – going from the 1st to 2nd case and the 2nd to 3rd case, you’ve made the input 10 times bigger, and it’s taken 10 times longer.
In particular, it looks like you can predict the rough time by using:
or
which gives a simplest explanation of O(n) for the data provided.
EDIT: However… As has been pointed out, there are various ways in which the data could be misleading you – I rather like Dennis Palmer’s idea that the IO cost is dwarfing everything else. For example, suppose you have an algorithm whose absolute number of operations is:
In that case the complexity is still O(n^2), but that won’t become apparent from observations until n is very large.
I think it would be accurate to say that these observations are suggestive of an O(n) algorithm but that doesn’t mean it definitely is.