Question: Write working java methods from descriptions and estimate their Big-O notation. Algorithm 1: Fill the array 'a' from a[0] to a[n-1] as follows: To fill

Write working java methods from descriptions and estimate their Big-O notation.

Algorithm 1: Fill the array 'a' from a[0] to a[n-1] as follows: To fill a[i], generate random numbers until you get one that is not already in a[0] to a[i-1].

Algorithm 2: Same as algorithm 1, but keep an extra array called the 'used' array. When a random number, 'ran', is first put into the array 'a', set used[ran] = true. Now, when chosing a random number, no longer check ever position in 'a' before the one you are filling, just check the 'used' array.

Algorithm 3: Fill the array such that a[i] = i+1. Then, for(i = 1; i < n; i++) swapReferences(a[i], a[random(0,i)]); *Note: Write your own swapReferences method to switch two given positions

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!