Figure 1: The flow of algorithm.