Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

language being used is JAVA Write a program that: 1. Prompts you to enter a (integer) number n 2. Randomly picks an integer between 1

image text in transcribedlanguage being used is JAVA

Write a program that: 1. Prompts you to enter a (integer) number n 2. Randomly picks an integer between 1 and n. Save this in a variable pick1 3. Randomly picks an integer between 1 and n. Save this in a variable pick2 4. Randomly picks an integer between 1 and n. Save this in a variable pick3 5. Go to step 3 until pick1 is equal to pick2 AND pick1 is equal to pick3. NOTE: be sure you go to step 3 and not step 2. Examine your three-of-a-kind code from the previous question. In the text box below determine the time complexity of the code: 2. Randomly picks an integer between 1 and n. Save this in a variable pick1 3. Randomly picks an integer between 1 and n. Save this in a variable pick2 4. Randomly picks an integer between 1 and n. Save this in a variable pick3 5. Go to step 3 until pick1 is equal to pick2 AND pick1 is equal to pick3 Hint: To answer this question you have to think about "probabilities". What is the probability that a specific number between 1 and n is chosen at random? Run your program multiple times using n=5 and extrapolate a general f(n) from this example (more hint: if n=5 then the odds of picking some number is one in five so what are the odds of picking the same number twice?). Answer the following questions: 1. (4 marks]: Determine a worst-case time complexity formula fin) for the algorithm (highlighted in red above). 2. [2 marks]: Determine worst case run-time Big-O i.e: Off(n)) 3. [2 marks]: Determine best case run-time. I.e: Omega f(n) 4. [2 mark]: Estimate Theta f(n). (average run-time). Note: for full marks you must THOROUGHLY explain your reasoning for your answers for each question 1-4. Grading (10) marks. For full marks, your answer must include an explanation (your "work"). This can be in the form of a couple of equations, or a short derivation, or a brief verbal argument. Part marks will be assessed for incomplete or incorrect answers. . For full marks, you must use fn), o, omega, theta explanation to express your answer. A submission consisting only of the final answer with no explanation will receive no more than 1 mark

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions