first approach of the algorithm