Question: Design algorithms for the following two tasks and code them in Java: 1 . Write a Java method called fillArray that accepts a positive integer
Design algorithms for the following two tasks and code them in Java:
Write a Java method called fillArray that accepts a positive integer n as its only parameter. The method returns an array of length n This array is filled with unique integers in the range mathrmn In other words, the array contains all but one of the numbers in that range. The numbers are not sorted; they are in random order.
Write a second Java method called findMissingNumber that accepts as its only parameter an array of the type produced by fillArray. Find and return the number in the range mathrmn that is missing from the array.
For both methods:
The algorithm must be mathrmOmathrmn for time complexity; and
You are only allowed to use O additional space besides the array itself. In other words, you cannot use a second array.
Include in your class a main method that tests both methods.
Include the following clearly labeled information in your submission document for Question :
a The code for your complete Java class, including your main method, fillArray, and findMissingNumber.
b Output for multiple test cases for both mathrmn and mathrmn For each test case, display and clearly label:
the contents of the array produced by fillArray display all numbers on the same line; and
the missing number as returned by findMissingNumber.
c An explanation of why your fillArray method is mathrmOmathrmn for time complexity
d An explanation of why your fillArray method is mathrmO for space usage, other than the array itself
e An explanation of why your findMissingNumber method is mathrmOmathrmn for time complexity
f An explanation of why your findMissingNumber method is mathrmO for space usage, other than the array itself
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
