Reputation: 2546
What is the time complexity to sort an array of 10 elements?
I'm familiar with sorting algorithms. However, when we have the size of array already defined as a constant value suppose n=10, can we say that it requires constant time to sort the elements?
Is the same true for some another array of size n=100 or 10000?
Upvotes: 0
Views: 572
Reputation: 41
Complexity is always expressed as some kind of growth in relation to one or more variable. When you only have constant values, there is no growth. Thus, you are only interested in the real run time of your algorithm.
If the question is if there are better sorting algorithms for small sample sizes: Yes there are.
For example, typical quick sort usually uses other sorting algorithms on small subsets because they perform better on say 10 or 3 elements (eg. insertion sort).
Upvotes: 2