algorithm sample codes