Question: Implement the algorithm of Randomize-In-Place. We will discuss the algorithm in the CSC317 class. You can follow the pseudocode in the CLRS book, Chapter

Implement the algorithm of Randomize-In-Place. We will discuss the algorithm in the

Implement the algorithm of Randomize-In-Place. We will discuss the algorithm in the CSC317 class. You can follow the pseudocode in the CLRS book, Chapter 5 (code written below). Choose the programming language you like to implement the algorithm. Some options are Java, Javascript, C, C++, Python, Matlab, etc. RANDOMIZE-IN-PLACE(A) 1. n=A.length 2. for i1 to n 3. swap A[i] with A[Random(i,n)] Input: An array of numbers. Output: Random permutation of the array. The auxiliary function in the pseudocode Random(i,n) returns a random integer between i and n. Print: We ask you to print out the program state at each loop iteration. The program state in this case should be the array of numbers and iterator i. Also, print out Random(i,n) so that it is clear what two elements were swapped at each step. Choose an example array of length 10 to illustrate your code. Animation: Alternatively, you can animate the program state or display a figure of the array for instance as a bar plot, indicating i and what elements were swapped.

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!