Question: The following code prepares a random permutation of an array of integers in `O(n)` time: void permute (int a[], int n) { // Swap each

The following code prepares a random permutation of an array of integers in `O(n)` time:

void permute (int a[], int n) { // Swap each element with a randomly chosen one. for (int j = 1; j < n; j++) { int r = rand() % (j+1); int temp = a[j]; a[j] = a[r]; a[r] = temp; } } 

Suppose we wanted to develop a generic version of this algorithm to work, still in O(n) time, with std containers. We would have to replace all the uses of [ ] by appropriate iterator operations. Assuming that we do so, which of the following containers would be acceptable candidates?

-vector

-string

-list

-deque Select all that apply

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 Databases Questions!