Calculate mean and standard deviation from a vector of samples in C++ using Boost

I don’t know if Boost has more specific functions, but you can do it with the standard library. Given std::vector<double> v, this is the naive way: #include <numeric> double sum = std::accumulate(v.begin(), v.end(), 0.0); double mean = sum / v.size(); double sq_sum = std::inner_product(v.begin(), v.end(), v.begin(), 0.0); double stdev = std::sqrt(sq_sum / v.size() – mean … Read more

Algorithm to list all unique permutations of numbers contain duplicates

The simplest approach is as follows: Sort the list: O(n lg n) The sorted list is the first permutation Repeatedly generate the “next” permutation from the previous one: O(n! * <complexity of finding next permutaion>) Step 3 can be accomplished by defining the next permutation as the one that would appear directly after the current … Read more