Question: (b) Write a function called void randperm (int n, int perm []) which fills the n-dimensional array perm with a random permutation. Follow this
![(b) Write a function called void randperm (int n, int perm [])](https://dsd5zvtm8ll6.cloudfront.net/questions/2024/03/6606840b49451_1711706557922.jpg)
(b) Write a function called void randperm (int n, int perm []) which fills the n-dimensional array perm with a random permutation. Follow this algorithm: 1. Initialize perm [] to the canonical permutation: 0, 1, 2, 2. Loop for i = 0, 1, 2, ..., n-1 (a) Generate a random index: k between 0 and n-1 (b) Swap the values of perm[i] and perm [k] n-1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
