Now you have a brief idea of which sorting algorithm might best meet your needs. But the story
doesn’t end here. The standard guarantees complexity but not how it is implemented. This is an
advantage in that an implementation could benefit from algorithm innovations and use a better way
of sorting without breaking the standard. For example, the sort() algorithm in the SGI implementation
of the STL is implemented by using introsort. Introsort is a new algorithm that, by default,
operates like quicksort but switches to heapsort when it is going to have quadratic complexity. The
disadvantage of the fact that the standard does not guarantee exact complexity is that an implementation
could use a standard-conforming, but very bad, algorithm. For example, using heapsort to
implement sort() would be standard conforming. Of course, you simply could test which algorithm
fits best, but be aware that measurements might not be portable
Now you have a brief idea of which sorting algorithm might best meet your needs. But the story
doesn’t end here. The standard guarantees complexity but not how it is implemented. This is an
advantage in that an implementation could benefit from algorithm innovations and use a better way
of sorting without breaking the standard. For example, the sort() algorithm in the SGI implementation
of the STL is implemented by using introsort. Introsort is a new algorithm that, by default,
operates like quicksort but switches to heapsort when it is going to have quadratic complexity. The
disadvantage of the fact that the standard does not guarantee exact complexity is that an implementation
could use a standard-conforming, but very bad, algorithm. For example, using heapsort to
implement sort() would be standard conforming. Of course, you simply could test which algorithm
fits best, but be aware that measurements might not be portable
การแปล กรุณารอสักครู่..