Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions