How to find that array is a cyclic or not?

How to find whether the array is Cyclic or not ?

Example 1 A1=[‘a’,’b’,’c’,’d’]

A2 = [‘a:b’, ‘c:d’]

Output : not cyclic because ([‘b’,’a’,’d’,’c’] is the order for that)

Example 2

A1=[‘a’,’b’,’c’,’d’]

A2 = [‘a:b’, ‘b:a’]

Output : It is cyclic because it is looping a to b , b to a and again