Cody

Problem 1482. Number of cyles and fixed points in a permutation

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]

Problem 6) Prev: 1481 Next: 1483

Solution Stats

61.11% Correct | 38.89% Incorrect
Last solution submitted on Nov 09, 2016

Problem Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more