C++ implementation of algorithms