shivam agarwal
shivam agarwal

Reputation: 27

How to print all cycles in a linked list with extra pointers?

Given a data structure that resembles a linked list with a pointer pointing to next node and another pointer pointing to any random node, I have to print all the unique cycles that the structure has. Here is an example of this data structure:

enter image description here

Unique cycles here are (1,2,1), (2,3,4,5,2), (1,3,5,2,1), (3,4,3) etc. but (1,2,3,4,5,2,1), (1,2,3,4,3) is not a cycle. What should be the algorithm to print all of these unique cycles?

Upvotes: 1

Views: 125

Answers (0)

Related Questions