Doubt in solving Question 8 of Pattern Practice questions

I am having doubt in solving question 8 of pattern practice questions can you please help in understanding the algorithm of this question.