basic algorithm implemented by C C++ Java Python Perl R