Menu

(Solved) : Import Javautil Import Javautilrandom Public Class Randomnumber Public Static Void Main St Q43950451 . . .

import java.util.*;
import java.util.Random;
public class RandomNumber {
  
  
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(“Enter a number: “);
int input = scan.nextInt();
Random ran = new Random(input);
int ran1 = ran.nextInt(input+1);
int ran2 = ran.nextInt(input+1);
System.out.println(“pick 1 is: ” + input);
System.out.println(“pick 2 is: ” + ran1);
System.out.println(“pick 3 is: ” + ran2);
}
  
/* ADD YOUR CODE HERE */
  
}

Examine your three-of-a-kind code from the previous question. Inthe text box below determine the time complexity of the code:

2. Randomly picks an integer between 1 and n. Save thisin a variable pick1
3. Randomly picks an integer between 1 and n. Save this ina variable pick2
4. Randomly picks an integer between 1 and n. Save this ina variable pick3
5. Go to step 3 until pick1 is equal to pick2 AND pick1 isequal to pick3

Hint: To answer this question you have to thinkabout “probabilities”. What is the probability that a specificnumber between 1 and n is chosen at random? Run your programmultiple times using n=5 and extrapolate a general f(n) from thisexample (more hint: if n=5 then the odds ofpicking some number is one in five so what are the odds of pickingthe same number twice?).

Answer the following questions:

1. Determine a worst-case time complexity formula f(n) for thealgorithm (highlighted in red above).

2. Determine worst case run-time Big-O i.e: O(f(n))

3. Determine best case run-time. i.e: Omega f(n)

4. Estimate Theta f(n) . ( average run-time ).

Expert Answer


Answer to import java.util.*; import java.util.Random; public class RandomNumber { public static void main(String[] args) { Scanne…

OR