Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started