changes for cycles concept in algorithm