Implement the algorithm in the Discrete Mathematics