A Algorithm implementation