implement the algorithm for the question 4

Question 4 over!