Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the copy-and-paste method to give an average-case analysis for the permute function. Assume that the random number generator used in the algorithm produces truly

Use the copy-and-paste method to give an average-case analysis for the permute function. Assume that the random number generator used in the algorithm produces truly random numbers in the range [0, RAND_MAX). Please show all work/steps. Thank you.

// Generate a random permutation of the integers from // 0 .. n-1, storing the results in array a. // void permute (int a[], int n)

{

for (int i = 0; i < n; i++)

{

// Guess at a value to put into a[i]

int guess = rnd(n);

while (find(a, a+i, guess) != a+i)

{

// If it's one that we've already used, guess again.

guess = rnd(n);

}

a[i] = guess;

}

}

UPDATE: what is needed for this question is how to break down the function to give an average-case analysis using big O notation line by line and what the final result is in big O for example "O(n^3)". Also the find fucntion is part of the algorithm library.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions