A permutation can be constructed from one or more sets of elements in cyclic order. A permutation in a single row vector form indicates where elements indexed sequentially will be repositioned to. Ex. [ 2 4 1 3] means the first element goes to position 2, 2nd to 4, 3rd to 1 and 4rth to 3 and this happens to be one cycle 1 to 2 to 4 to 3 back to 1.
Given a permutation, determine the number of cycles. Consider fixed points as cycles of length 1.
http://en.wikipedia.org/wiki/Cyclic_permutation
http://en.wikipedia.org/wiki/Cycles_and_fixed_points
Ex. [2 3 1 5 6 4] has two cycles [2 3 1][5 6 4]
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers38
Suggested Problems
-
Get the area codes from a list of phone numbers
1072 Solvers
-
Numbers with prime factors 2, 3 and 5.
682 Solvers
-
Back to basics 21 - Matrix replicating
1795 Solvers
-
Convert from Base 10 to base 5
281 Solvers
-
Count letters occurence in text, specific to words with a given length.
196 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!