Determine the number of distinct items

Assignment Help JAVA Programming
Reference no: EM133389638

Use the Random class to create a list (System.Collections.Generic.List) with 10,000 random integers in the range [0, 20,000] (give or take a few hundred in that range is fine). Then determine how many distinct integers are in the list with 3 different approaches. Also, have them run in the order listed below. Do not change the order.

To be clear: You are not allowed to use ready implementations of Distinct. A note on what you're doing: you're taking an array of numbers and conceptually just removing duplicates and counting
how many are left. If the input array was {1,1,3,5,6,6,7,7,7,9} then the distinct number set is {1,3,5,6,7,9}, implying 6 distinct numbers.

Question 1. Do not alter the list in any way and use a hash set to determine the number of distinct integers in the list. The result will be included in the output, which is discussed more below. Also, include in the output information about the time complexity of this method. Be careful with this and describe how you determined it.

Question 2. Do not alter the list in any way and determine the number of distinct items it contains while keeping the storage complexity (auxiliary) at O(1). This means that you cannot dynamically allocate any memory. If you have an algorithm that would require more storage if the list had more items, then it is not O(1) storage complexity. Moreover, you cannot allocate additional lists, arrays, or containers of any sort.

Question 3. Sort the list (use built-in sorting functionality) and then use a new algorithm to determine the number of distinct items with O(1) storage, no dynamic memory allocation, and O(n) time complexity. Do not alter the list further after sorting it. Determine the number of distinct items in O(n) time (not including the sorting time, which you can ignore), where n is the number of items in the list.

Reference no: EM133389638

Questions Cloud

Retrieve the current values of the input elements : Create a file called hwork-1.js and add it to the bottom of the html as a script. Add an event listener to the button so that it calls a makeSentence function
How did george washington come to be involved : How did George Washington come to be involved? Were they important to the eventual outcome? How does George Washington's life connect to the major themes
Compute bmi and max-heart rate : Compute BMI and max-heart rate. Following the ntnu.edu/cerg/hrmax Maximum Heart Rate Calculator and develop something similar
How did george washington come to be involved in american : How did George Washington come to be involved in the American revolution? Were they important to the eventual outcome? How does George Washington's life connect
Determine the number of distinct items : Determine the number of distinct items in O(n) time (not including the sorting time, which you can ignore), where n is the number of items in the list
How did the southern colonies operate before the revolution : How did the Southern colonies operate before the Revolution? Who was in charge? How did they govern themselves? How was the economy run?
Special education progress mark datasets : What type of auditing would you do on special education progress mark datasets in an elementary school
What modern social movements do you see parallels : What modern social movements do you see parallels with in protests which took place before and during the American Revolution? What are the limitations of those
What steps did woodrow wilson take to avoid american : What steps did Woodrow Wilson take to avoid American involvement in the First World War? How did minorities in America participate in the First World War?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a recursive program

Write a recursive program to compute the number of ways in which an integer k can be written as sum

  Disposing of cans of theme mango cheesecake

Consider the Oakshire Brewing Company beer recall notice (posted on Kodiak). In particular, consider the instructions to consumers who have the product:

  The commission employee inherits

The Commission Employee inherits from the Employee class. A Commission Employee contains a commission rate and a sales amount variable which are used as part of the pay calculation. An explicit value constructor should be provided to set all 3 val..

  Create a gui with a text field and a button

The java program needs to create a GUI with a text field and a button, with an actionlistener. When the button is clicked, whatever text typed into the text field is stored in a variable and written to a text file

  Describe the semantics of the for-in statement

How is a new property of an object created? Describe the semantics of the for-in statement. Describe the two ways an Array object can be created.

  Describe solution to each problem

If we ask the wolf to calculate its path twice it works, but not if we ask it to do so only once - If your solution does already work for a larger game

  The class constructor should accept an array

Write a class named TestScores. The class constructor should accept an array of test scores as its arguments. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 10..

  Write a program that displays a string welcome to java

Write a program that displays a string Welcome to Java around the circle, as shown in Figure

  Explain principles of encapsulation and information hiding

Explain the principles of encapsulation and information hiding; Describe and relate the terms: public interface, information hiding;

  Create a linked list that is a palindrome

Create a linked list that is a Palindrome, and call the isPalindrome method, passing it a linkedList. Test to ensure it returns True.

  Write a java declaration for one real number quantity

Write a single Java statement to declare two integer quantities called orderOne and orderTwo, each initialized to 0.

  Write a program that asks for number of ticket to purchase

Write a program that asks for the number of ticket to purchase. Then calculate and display the amount of the discount (if any) and the total purchase price.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd