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 [])

 

(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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!