Why is Insertion sort better than Quick sort for small list of elements?

Big-O Notation describes the limiting behavior when n is large, also known as asymptotic behavior. This is an approximation. (See http://en.wikipedia.org/wiki/Big_O_notation) Insertion sort is faster for small n because Quick Sort has extra overhead from the recursive function calls. Insertion sort is also more stable than Quick sort and requires less memory. This question describes … Read more

how do you insert the value in a sorted vector?

The simple answer to the question: template< typename T > typename std::vector<T>::iterator insert_sorted( std::vector<T> & vec, T const& item ) { return vec.insert ( std::upper_bound( vec.begin(), vec.end(), item ), item ); } Version with a predicate. template< typename T, typename Pred > typename std::vector<T>::iterator insert_sorted( std::vector<T> & vec, T const& item, Pred pred ) { … Read more

Fastest way to sort 10 numbers? (numbers are 32 bit)

(Following up on the suggestion of @HelloWorld to look into sorting networks.) It seems that a 29-comparison/swap network is the fastest way to do a 10-input sort. I used the network discovered by Waksman in 1969 for this example in JavaScript, which should translate directly into C, as it’s just a list of if statements, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)