start to implement the third algorithm