miscellaneous algorithms