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
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