basic algorithm