Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18.3, Problem 18.24CP
Program Plan Intro
“HashSet” class:
- The “HashSet” class implements the “Set” interface.
- It uses hash codes to store the elements in a way that makes searching faster.
- The “HashSet” class gives constant time performance for the basic operations like add, delete, and size assuming the hash function separates the elements properly among the buckets.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Apex Assignment :
You have to create the method named myfirstmethod to set the vlaue in the
collection type i.e. set , map , and list. And also atttach the screenshot of the
debug log.
Question1- Add to the Test class a method called
isSubSet(LinearProbingHashTable h1, LinearProbingHashTable h2)
that is receives 2 hash tables h1 and h2, and returns true if h1 is sub set of h2,
otherwise the method returns false.
Don't forget to test the method in the main of Test class
Write a method void removeShortStrings(HashSet<String> set). The method should remove from the set any string that is shorter than 100.
Chapter 18 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 18.1 - Prob. 18.1CPCh. 18.1 - What are the three general types of collections?Ch. 18.1 - Prob. 18.3CPCh. 18.1 - Prob. 18.4CPCh. 18.1 - Prob. 18.5CPCh. 18.1 - Prob. 18.6CPCh. 18.1 - Prob. 18.7CPCh. 18.2 - Prob. 18.8CPCh. 18.2 - Prob. 18.9CPCh. 18.2 - Prob. 18.10CP
Ch. 18.2 - Prob. 18.11CPCh. 18.2 - Prob. 18.12CPCh. 18.2 - Prob. 18.13CPCh. 18.2 - Prob. 18.14CPCh. 18.2 - Prob. 18.16CPCh. 18.2 - Prob. 18.17CPCh. 18.2 - Prob. 18.18CPCh. 18.2 - Prob. 18.20CPCh. 18.3 - Prob. 18.21CPCh. 18.3 - Prob. 18.22CPCh. 18.3 - Prob. 18.23CPCh. 18.3 - Prob. 18.24CPCh. 18.3 - Any time you override the Object classs equals...Ch. 18.3 - Prob. 18.26CPCh. 18.3 - Prob. 18.27CPCh. 18.3 - Prob. 18.28CPCh. 18.4 - Prob. 18.29CPCh. 18.4 - Prob. 18.31CPCh. 18.4 - Prob. 18.32CPCh. 18.6 - How do you define a stream of elements?Ch. 18.6 - How does a stream intermediate operation differ...Ch. 18.6 - Prob. 18.35CPCh. 18.6 - Prob. 18.36CPCh. 18.6 - Prob. 18.37CPCh. 18.6 - Prob. 18.38CPCh. 18.6 - Prob. 18.39CPCh. 18 - Prob. 1MCCh. 18 - Prob. 2MCCh. 18 - This type of collection is optimized for...Ch. 18 - Prob. 4MCCh. 18 - A terminal operation in a stream pipeline is also...Ch. 18 - Prob. 6MCCh. 18 - Prob. 7MCCh. 18 - This List Iterator method replaces an existing...Ch. 18 - Prob. 9MCCh. 18 - Prob. 10MCCh. 18 - This is an object that can compare two other...Ch. 18 - This class provides numerous static methods that...Ch. 18 - Prob. 13MCCh. 18 - Prob. 14MCCh. 18 - Prob. 15TFCh. 18 - Prob. 16TFCh. 18 - Prob. 17TFCh. 18 - Prob. 18TFCh. 18 - Prob. 19TFCh. 18 - Prob. 20TFCh. 18 - Prob. 21TFCh. 18 - Prob. 22TFCh. 18 - Prob. 1FTECh. 18 - Prob. 2FTECh. 18 - Prob. 3FTECh. 18 - Prob. 4FTECh. 18 - Write a statement that declares a List reference...Ch. 18 - Prob. 2AWCh. 18 - Assume that it references a newly created iterator...Ch. 18 - Prob. 4AWCh. 18 - Prob. 2SACh. 18 - Prob. 4SACh. 18 - Prob. 5SACh. 18 - Prob. 6SACh. 18 - How does the Java compiler process an enhanced for...Ch. 18 - Prob. 8SACh. 18 - Prob. 9SACh. 18 - Prob. 10SACh. 18 - Prob. 11SACh. 18 - Prob. 12SACh. 18 - Prob. 13SACh. 18 - Prob. 14SACh. 18 - Word Set Write an application that reads a line of...Ch. 18 - Prob. 3PCCh. 18 - Prob. 5PCCh. 18 - Prob. 8PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Which of the following statements are true about a HashSet ? Select all that apply. Hint: you should be able to answer this question based only on the material presented in class. If E inherits Object.hashCode(), then there will be no collisions. A HashSet iterator should iterate through the Hashset elements in the order in which they were added to the Hashset. Two HashSets are equal (according to the equals() method) if they have the same size and their elements can be paired such that the pairs are equal according to the E.equals() method. OA HashSet could be implemented using a HashMap namely the key is the same as the value.arrow_forwardX595: removeOdd This method takes an ArrayList of integers as a parameter and does not return anything. The method will remove all of the odd elements in the given list. If there is no element in the given list, the list does not change. You must modify the given list. Your Answer: 1 public void removeOdd (ArrayList list) 2{ 3 4} 5 Feedback Your answer could not be processed because it contains errors: line 3: error: size has private access in java.util.ArrayListarrow_forwardWhat happens if you attempt to search up a value and the key in the map does not exist?arrow_forward
- addCourse: accepts an object of type Course as the first parameter and the idNum of the Student as the second parameter. The Course can be added only if the Student object with the specified idNum exists in the studentsList, Course does not exist in the coursesRegistered list for the Student, After adding the course, the number of credits, do not exceed 18. If the course is added successfully, return true, else return false.arrow_forwardIt is python language Write the code that creates a new Node class. It will store data and next attributes. You only need to create the __init__ method. data and next variables will have default values, both set to None. Assume you are using the Node class from the previous connection to create a LinkedList. You have the code below, create a method that removes the first node from the LinkedList. class LinkedList: def __init__(self): self.head = None Based on the code from the last two questions, create a new LinkedList. Add 2 values to the LinkedList (there is an add method that accepts data as an argument, called add). Then call the removeFront method created in the previous question. Based on the previous questions, create a Queue class that uses the LinkedList for its data storage. Create the __init__, isEmpty, insert, remove, and size methods. Assume that LinkedList class has the add, removeFront and size methods defined. Based on the LinkedList code already…arrow_forwardIf a collection stores 10 objects, what value would be returned from a call to its size method?arrow_forward
- Complete the method “readdata”. In this method you are to read in at least 10 sets of student data into a linked list. The data to read in is: student id number, name, major (CIS or Math) and student GPA. You will enter data of your choice. You will need a loop to continue entering data until the user wishes to stop. Complete the method “printdata”. In this method, you are to print all of the data that was entered into the linked list in the method readdata. Complete the method “printstats”. In this method, you are to search the linked list and print the following: List of student’s id and names who are CIS majors List of student’s id and names who are Math majors List of student’s names along with their gpa who are honor students (gpa 3.5 or greater) All information for the CIS student with the highest gpa (you may assume that different gpa values have been entered for all students) CODE (student_list.java) You MUST use this code: package student_list;import…arrow_forward' make a hashmap ' import hashlib import sys def insert (hashmap, key, value): ' insert a key value pair into the hashmap ' hashmap[key] = value def remove (hashmap, key): ' remove a key value pair from the hashmap ' del hashmap[key] def search (hashmap, key): ' search for a key in the hashmap ' if key in hashmap: return hashmap[key] else: return None def print (hashmap): ' print the hashmap ' for key in hashmap: print (key, ":", hashmap[key]) 'end of print' def main (): 'make a menu that lets the user call the functions' hashmap = {} while True: print (""" Menu: 1. Insert 2. Remove 3. Search 4. Print 5. Quit """) choice = input ("Enter your choice: ") if choice == "1": key = input ("Enter the key: ") value = input ("Enter the value: ") insert (hashmap, key, value) elif choice == "2":…arrow_forwardThe compareTo method. First you compare this.ticker which is a String, then if they are the same then you compare by the this.purchasePrice which is a double hashCode public int hashCode() The hashCode method using the Code-> Generate equals and hashCode with no changes Overrides: hashCode in class Object Returns: int Representing the hashCode compareTo public int compareTo(Stock another) The compareTo method not auto generated Compares first by ticker and if the tickers are the same secondarily compares by price Specified by: compareTo" in interface Comparable<stock> Parameters: another - the object to be compared. Returns: int Representing order Throws: IllegalArgumentException"- if another is null.arrow_forward
- getListRowIndices Method public static java.util.ArrayList<java.lang.Integer> getListRowIndices(int[][] array, int rowLength) This method returns an ArrayList with the indices of rows of the two-dimensional having a length that corresponds to rowLength. You may only use one auxiliary method. The method should create an ArrayList that is passed to the auxiliary in order to place the indices (if any). If no indices are found, an empty (size of 0) ArrayList will be returned. You can assume the array parameter will not be null and every row of the two-dimensional array has an array with a size of at least 0. Your implementation must be recursive and you may not use any loop construct. Do not use ++ or -- in any recursive call argument. It may lead to an infinite recursion. For example, use index + 1, instead of index++. Parameters: array - rowLength - Returns: ArrayList<Integer>arrow_forward@return index of the point that is closest to the origin, which is (0, 0) * In case of a tie, return the lowest index */ public int closestToOriginIndex() { return 0; }arrow_forwardCode to start with: public void addStudents(String[] ids){ }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education